console.log("script.js is running"); const br = document.createElement("br"); const bar = document.getElementById("barContainer"); const circle = document.getElementById("circleContainer"); const redLabel = document.querySelector('.red-label'); const blueLabel = document.querySelector('.blue-label'); // N lines NL message if (document.getElementById("messageNL")) { const NL_message = document.getElementById("messageNL"); const messageBoxNL = document.getElementById("messageBoxNL"); const length_NL_message = NL_message.textContent.length; const n_lines = Math.ceil(length_NL_message/65); messageBoxNL.style.height = n_lines*40+"px"; } else { console.log("here"); } // assistance for contribution high gamma (draft) if (document.getElementById("id_contribution_gammahigh")) { const contributionGammaHigh = document.getElementById("id_contribution_gammahigh"); const validationInputHigh = document.getElementById("validation-input"); contributionGammaHigh.addEventListener("input", function() { if (contributionGammaHigh.value=="" ) { validationInputHigh.textContent = "" validationInputHigh.appendChild(br) bar.style.background = "#eee"; } else if (contributionGammaHigh.value<= 10 && contributionGammaHigh.value>= 0) { validationInputHigh.textContent = `You decided to contribute ${Number(contributionGammaHigh.value).toFixed(2).replace(/\.?0+$/, "")} token(s) to the shared account. You will keep ${(10 - Number(contributionGammaHigh.value)).toFixed(2).replace(/\.?0+$/, "")} token(s) in your private account.`; const value = parseFloat(contributionGammaHigh.value); // Convert 0–10 → 0–100% const percentage = value * 10; bar.style.background = `linear-gradient(to right, red ${percentage}%, blue ${percentage}%)`; } else if (contributionGammaHigh.value > 10) { validationInputHigh.textContent = "You cannot contribute more than the 10 tokens you own in the shared account"; bar.style.background = "#eee"; } else if (contributionGammaHigh.value < 0) { validationInputHigh.textContent = "You cannot contribute a negative number of tokens in the shared account"; bar.style.background = "#eee"; } }); } else { } // assistance for contribution low gamma (draft) if (document.getElementById("id_contribution_gammalow")) { const contributionGammaLow = document.getElementById("id_contribution_gammalow"); const validationInputLow = document.getElementById("validation-input"); contributionGammaLow.addEventListener("input", function() { if (contributionGammaLow.value=="" ) { validationInputLow.textContent = "" validationInputLow.appendChild(br) bar.style.background = "#eee"; } else if (contributionGammaLow.value<= 10 && contributionGammaLow.value>= 0) { validationInputLow.textContent = `You decided to contribute ${Number(contributionGammaLow.value).toFixed(2).replace(/\.?0+$/, "")} token(s) to the shared account. You will keep ${(10 - Number(contributionGammaLow.value)).toFixed(2).replace(/\.?0+$/, "")} token(s) in your private account.`; const value = parseFloat(contributionGammaLow.value); // Convert 0–10 → 0–100% const percentage = value * 10; bar.style.background = `linear-gradient(to right, red ${percentage}%, blue ${percentage}%)`; } else if (contributionGammaLow.value > 10) { validationInputLow.textContent = "You cannot contribute more than the 10 tokens you own in the shared account"; bar.style.background = "#eee"; } else if (contributionGammaLow.value < 0) { validationInputLow.textContent = "You cannot contribute a negative number of tokens in the shared account"; bar.style.background = "#eee"; } }); } else { } // assistance for contribution other participant high gamma (draft) if (document.getElementById("id_expected_other_player_contribution_gammahigh")) { const contributionGammaHigh = document.getElementById("id_expected_other_player_contribution_gammahigh"); const validationInputHigh = document.getElementById("validation-input"); contributionGammaHigh.addEventListener("input", function() { if (contributionGammaHigh.value=="" ) { validationInputHigh.textContent = "" validationInputHigh.appendChild(br) bar.style.background = "#eee"; } else if (contributionGammaHigh.value<= 10 && contributionGammaHigh.value>= 0) { validationInputHigh.textContent = `You think the other participant will contribute ${Number(contributionGammaHigh.value).toFixed(2).replace(/\.?0+$/, "")} token(s) to the shared account. This means they will keep ${(10 - Number(contributionGammaHigh.value)).toFixed(2).replace(/\.?0+$/, "")} token(s) in their private account.`; const value = parseFloat(contributionGammaHigh.value); // Convert 0–10 → 0–100% const percentage = value * 10; bar.style.background = `linear-gradient(to right, red ${percentage}%, blue ${percentage}%)`; } else if (contributionGammaHigh.value > 10) { validationInputHigh.textContent = "The other participant cannot contribute more than the 10 tokens in the shared account"; bar.style.background = "#eee"; } else if (contributionGammaHigh.value < 0) { validationInputHigh.textContent = "The other participant cannot contribute a negative number of tokens in the shared account"; bar.style.background = "#eee"; } }); } else {} // assistance for contribution other participant low gamma (draft) if (document.getElementById("id_expected_other_player_contribution_gammalow")) { const contributionGammaLow = document.getElementById("id_expected_other_player_contribution_gammalow"); const validationInputLow = document.getElementById("validation-input"); contributionGammaLow.addEventListener("input", function() { if (contributionGammaLow.value=="" ) { validationInputLow.textContent = "" validationInputLow.appendChild(br) bar.style.background = "#eee"; } else if (contributionGammaLow.value<= 10 && contributionGammaLow.value>= 0) { validationInputLow.textContent = `You think the other participant will contribute ${Number(contributionGammaLow.value).toFixed(2).replace(/\.?0+$/, "")} token(s) to the shared account. This means they will keep ${(10 - Number(contributionGammaLow.value)).toFixed(2).replace(/\.?0+$/, "")} token(s) in their private account.`; const value = parseFloat(contributionGammaLow.value); // Convert 0–10 → 0–100% const percentage = value * 10; bar.style.background = `linear-gradient(to right, red ${percentage}%, blue ${percentage}%)`; } else if (contributionGammaLow.value > 10) { validationInputLow.textContent = "The other participant cannot contribute more than the 10 tokens in the shared account"; bar.style.background = "#eee"; } else if (contributionGammaLow.value < 0) { validationInputLow.textContent = "The other participant cannot contribute a negative number of tokens in the shared account"; bar.style.background = "#eee"; } }); } else {} // assistance for contribution unknown gamma (draft) if (document.getElementById("id_contribution_message")) { const contributionGammaHigh = document.getElementById("id_contribution_message"); const validationInputHigh = document.getElementById("validation-input"); contributionGammaHigh.addEventListener("input", function() { if (contributionGammaHigh.value=="" ) { validationInputHigh.textContent = "" validationInputHigh.appendChild(br) bar.style.background = "#eee"; } else if (contributionGammaHigh.value<= 10 && contributionGammaHigh.value>= 0) { validationInputHigh.textContent = `You decided to contribute ${Number(contributionGammaHigh.value).toFixed(2).replace(/\.?0+$/, "")} token(s) to the shared account. You will keep ${(10 - Number(contributionGammaHigh.value)).toFixed(2).replace(/\.?0+$/, "")} token(s) in your private account.`; const value = parseFloat(contributionGammaHigh.value); // Convert 0–10 → 0–100% const percentage = value * 10; bar.style.background = `linear-gradient(to right, red ${percentage}%, blue ${percentage}%)`; } else if (contributionGammaHigh.value > 10) { validationInputHigh.textContent = "You cannot contribute more than the 10 tokens you own in the shared account"; bar.style.background = "#eee"; } else if (contributionGammaHigh.value < 0) { validationInputHigh.textContent = "You cannot contribute a negative number of tokens in the shared account"; bar.style.background = "#eee"; } }); } else { } // assistance for other player's contribution unknown gamma (draft) if (document.getElementById("id_expected_other_player_contribution_message")) { const contributionGammaLow = document.getElementById("id_expected_other_player_contribution_message"); const validationInputLow = document.getElementById("validation-input"); contributionGammaLow.addEventListener("input", function() { if (contributionGammaLow.value=="" ) { validationInputLow.textContent = "" validationInputLow.appendChild(br) bar.style.background = "#eee"; } else if (contributionGammaLow.value<= 10 && contributionGammaLow.value>= 0) { validationInputLow.textContent = `You think the other participant will contribute ${Number(contributionGammaLow.value).toFixed(2).replace(/\.?0+$/, "")} token(s) to the shared account. This means they will keep ${(10 - Number(contributionGammaLow.value)).toFixed(2).replace(/\.?0+$/, "")} token(s) in their private account.`; const value = parseFloat(contributionGammaLow.value); // Convert 0–10 → 0–100% const percentage = value * 10; bar.style.background = `linear-gradient(to right, red ${percentage}%, blue ${percentage}%)`; } else if (contributionGammaLow.value > 10) { validationInputLow.textContent = "The other participant cannot contribute more than the 10 tokens in the shared account"; bar.style.background = "#eee"; } else if (contributionGammaLow.value < 0) { validationInputLow.textContent = "The other participant cannot contribute a negative number of tokens in the shared account"; bar.style.background = "#eee"; } }); } else {} // assistance for expected proba gamma high (draft) if (document.getElementById("id_proba_gamma_high_message")) { const probaGammaHigh = document.getElementById("id_proba_gamma_high_message"); const validationInputProbaGammaHigh = document.getElementById("validation-input-expected-gamma"); probaGammaHigh.addEventListener("input", function() { if (probaGammaHigh.value=="" ) { validationInputProbaGammaHigh.textContent = "" validationInputProbaGammaHigh.appendChild(br) circle.style.background = "#eee"; redLabel.textContent = ""; blueLabel.textContent = "" } else if (probaGammaHigh.value<= 100 && probaGammaHigh.value>= 0) { validationInputProbaGammaHigh.textContent = `You think there is a ${Number(probaGammaHigh.value).toFixed(2).replace(/\.?0+$/, "")}% chance that the value of the return factor is 1.1 and a ${(100 - Number(probaGammaHigh.value)).toFixed(2).replace(/\.?0+$/, "")}% chance that it is 0.6.`; const value = parseFloat(probaGammaHigh.value); // Convert 0–10 → 0–100% const percentage = value * 360/100; circle.style.background = `conic-gradient(red 0deg ${percentage}deg, blue ${percentage}deg 360deg)`; // container center and radius const radius = circle.offsetWidth / 2; const center = radius; // compute label positions (50% of radius from center) const labelRadius = radius * 0.5; // red arc mid-angle const redMidAngle = (0 + percentage) / 2; const redX = 50 + value*0.2; const redY = center + labelRadius * Math.sin((redMidAngle - 90) * Math.PI / 180); // blue arc mid-angle const blueMidAngle = (percentage + 360) / 2; const blueX = 35 - value*0.2; const blueY = center + labelRadius * Math.sin((blueMidAngle - 90) * Math.PI / 180); // set label texts and positions redLabel.textContent = value.toFixed(2).replace(/\.?0+$/, "") + "%"; redLabel.style.left = redX + "%"; redLabel.style.top = redY + "px"; blueLabel.textContent = (100 - value).toFixed(2).replace(/\.?0+$/, "") + "%"; blueLabel.style.left = blueX + "%"; blueLabel.style.top = blueY + "px"; } else if (probaGammaHigh.value > 100) { validationInputProbaGammaHigh.textContent = "You cannot enter a probability greater than 100%."; circle.style.background = "#eee"; redLabel.textContent = ""; blueLabel.textContent = "" } else if (probaGammaHigh.value < 0) { validationInputProbaGammaHigh.textContent = "You cannot enter a negative probability."; circle.style.background = "#eee"; redLabel.textContent = ""; blueLabel.textContent = "" } }); } else {} // assistance for contribution unknown gamma no message(draft) if (document.getElementById("id_contribution_no_message")) { const contributionGammaHigh = document.getElementById("id_contribution_no_message"); const validationInputHigh = document.getElementById("validation-input"); contributionGammaHigh.addEventListener("input", function() { if (contributionGammaHigh.value=="" ) { validationInputHigh.textContent = "" validationInputHigh.appendChild(br) bar.style.background = "#eee"; } else if (contributionGammaHigh.value<= 10 && contributionGammaHigh.value>= 0) { validationInputHigh.textContent = `You decided to contribute ${Number(contributionGammaHigh.value).toFixed(2).replace(/\.?0+$/, "")} token(s) to the shared account. You will keep ${(10 - Number(contributionGammaHigh.value)).toFixed(2).replace(/\.?0+$/, "")} token(s) in your private account.`; const value = parseFloat(contributionGammaHigh.value); // Convert 0–10 → 0–100% const percentage = value * 10; bar.style.background = `linear-gradient(to right, red ${percentage}%, blue ${percentage}%)`; } else if (contributionGammaHigh.value > 10) { validationInputHigh.textContent = "You cannot contribute more than the 10 tokens you own in the shared account"; bar.style.background = "#eee"; } else if (contributionGammaHigh.value < 0) { validationInputHigh.textContent = "You cannot contribute a negative number of tokens in the shared account"; bar.style.background = "#eee"; } }); } else { } // assistance for other player's contribution unknown gamma (draft) if (document.getElementById("id_expected_other_player_contribution_no_message")) { const contributionGammaLow = document.getElementById("id_expected_other_player_contribution_no_message"); const validationInputLow = document.getElementById("validation-input"); contributionGammaLow.addEventListener("input", function() { if (contributionGammaLow.value=="" ) { validationInputLow.textContent = "" validationInputLow.appendChild(br) bar.style.background = "#eee"; } else if (contributionGammaLow.value<= 10 && contributionGammaLow.value>= 0) { validationInputLow.textContent = `You think the other participant will contribute ${Number(contributionGammaLow.value).toFixed(2).replace(/\.?0+$/, "")} token(s) to the shared account. This means they will keep ${(10 - Number(contributionGammaLow.value)).toFixed(2).replace(/\.?0+$/, "")} token(s) in their private account.`; const value = parseFloat(contributionGammaLow.value); // Convert 0–10 → 0–100% const percentage = value * 10; bar.style.background = `linear-gradient(to right, red ${percentage}%, blue ${percentage}%)`; } else if (contributionGammaLow.value > 10) { validationInputLow.textContent = "The other participant cannot contribute more than the 10 tokens in the shared account"; bar.style.background = "#eee"; } else if (contributionGammaLow.value < 0) { validationInputLow.textContent = "The other participant cannot contribute a negative number of tokens in the shared account"; bar.style.background = "#eee"; } }); } else {} // assistance for expected proba gamma high no message(draft) if (document.getElementById("id_proba_gamma_high_no_message")) { const probaGammaHigh = document.getElementById("id_proba_gamma_high_no_message"); const validationInputProbaGammaHigh = document.getElementById("validation-input-expected-gamma"); probaGammaHigh.addEventListener("input", function() { if (probaGammaHigh.value=="" ) { validationInputProbaGammaHigh.textContent = "" validationInputProbaGammaHigh.appendChild(br) circle.style.background = "#eee"; redLabel.textContent = ""; blueLabel.textContent = "" } else if (probaGammaHigh.value<= 100 && probaGammaHigh.value>= 0) { validationInputProbaGammaHigh.textContent = `You think there is a ${Number(probaGammaHigh.value).toFixed(2).replace(/\.?0+$/, "")}% chance that the value of the return factor is 1.1 and a ${(100 - Number(probaGammaHigh.value)).toFixed(2).replace(/\.?0+$/, "")}% chance that it is 0.6.`; const value = parseFloat(probaGammaHigh.value); // Convert 0–10 → 0–100% const percentage = value * 360/100; circle.style.background = `conic-gradient(red 0deg ${percentage}deg, blue ${percentage}deg 360deg)`; // container center and radius const radius = circle.offsetWidth / 2; const center = radius; // compute label positions (50% of radius from center) const labelRadius = radius * 0.5; // red arc mid-angle const redMidAngle = (0 + percentage) / 2; const redX = 50 + value*0.2; const redY = center + labelRadius * Math.sin((redMidAngle - 90) * Math.PI / 180); // blue arc mid-angle const blueMidAngle = (percentage + 360) / 2; const blueX = 35 - value*0.2; const blueY = center + labelRadius * Math.sin((blueMidAngle - 90) * Math.PI / 180); // set label texts and positions redLabel.textContent = value.toFixed(2).replace(/\.?0+$/, "") + "%"; redLabel.style.left = redX + "%"; redLabel.style.top = redY + "px"; blueLabel.textContent = (100 - value).toFixed(2).replace(/\.?0+$/, "") + "%"; blueLabel.style.left = blueX + "%"; blueLabel.style.top = blueY + "px"; } else if (probaGammaHigh.value > 100) { validationInputProbaGammaHigh.textContent = "You cannot enter a probability greater than 100%."; circle.style.background = "#eee"; redLabel.textContent = ""; blueLabel.textContent = "" } else if (probaGammaHigh.value < 0) { validationInputProbaGammaHigh.textContent = "You cannot enter a negative probability."; circle.style.background = "#eee"; redLabel.textContent = ""; blueLabel.textContent = "" } }); } else {}