add a 'disable spell checker' checkbox and rename settings

This commit is contained in:
Raphaël Jakse 2020-10-07 20:10:46 +02:00
parent 06d7d0b117
commit 85b0bd04a0
5 changed files with 78 additions and 62 deletions

View File

@ -225,3 +225,6 @@ msgstr "Astuce !"
msgid "Next tip"
msgstr "Astuce suivante"
msgid "Disable the spell checker"
msgstr "Désactiver la vérification orthographique"

View File

@ -230,3 +230,6 @@ msgstr ""
msgid "Next tip"
msgstr ""
msgid "Disable the spell checker"
msgstr ""

View File

@ -58,6 +58,14 @@
<p><label><input type="checkbox" id="tiles-sound" /><span data-l10n="text-content">Sound of the tiles</span></label></p>
<p><label><input type="checkbox" id="msg-sound" /><span data-l10n="text-content">Sound of messages</span></label></p>
</div>
<div>
<p id="disable-spell-checker-p" hide="true">
<label>
<input type="checkbox" id="disable-spell-checker" />
<span data-l10n="text-content">Disable the spell checker</span>
</label>
</p>
</div>
<div>
<p>
<label for="double-tap-duration" data-l10n="text-content">Double tap duration:</label>

View File

@ -59,11 +59,6 @@
setConf("FLASH_LIGHT_DURATION", middle("FLASH_LIGHT_DURATIONS"));
setConf("FLASH_LIGHT_COLOR", "#ee6633");
function isSetting(key) {
return Object.prototype.hasOwnProperty.call(Conf, key) ||
Object.prototype.hasOwnProperty.call(localStorage, key);
}
function getSetting(key) {
let type;
let value;
@ -75,13 +70,13 @@
}
/* try to retrieve value from localstorage */
if (Object.prototype.hasOwnProperty.call(localStorage, key)) {
value = localStorage.getItem(key);
if (Object.prototype.hasOwnProperty.call(localStorage, "trivabble" + key)) {
value = localStorage.getItem("trivabble" + key);
/* get type from localStorage if no default is set */
if (typeof type === "undefined") {
if (Object.prototype.hasOwnProperty.call(localStorage, key + "_type")) {
type = localStorage.getItem(key + "_type");
if (Object.prototype.hasOwnProperty.call(localStorage, "trivabble" + key + "_type")) {
type = localStorage.getItem("trivabble" + key + "_type");
} else {
type = "string";
}
@ -118,8 +113,8 @@
/* try to retrieve type from localstorage */
if (typeof type === "undefined") {
if (Object.prototype.hasOwnProperty.call(localStorage, key)) {
type = localStorage.getItem(key + "_type");
if (Object.prototype.hasOwnProperty.call(localStorage, "trivabble" + key)) {
type = localStorage.getItem("trivabble" + key + "_type");
}
}
@ -137,11 +132,11 @@
(type === "number") ||
(type === "object") ||
(type === "string")) {
localStorage.setItem(key, value);
localStorage.setItem("trivabble" + key, value);
/* store type into localstorage if no default value in configuration */
if (!Object.prototype.hasOwnProperty.call(Conf, key)) {
localStorage.setItem(key + "_type", type);
localStorage.setItem("trivabble" + key + "_type", type);
}
} else {
console.error("Unsupported type");
@ -152,17 +147,18 @@
}
function migrateSetting(key, type) {
if (Object.prototype.hasOwnProperty.call(localStorage, key)) {
localStorage.setItem(key + "_type", type);
if (Object.prototype.hasOwnProperty.call(localStorage, "trivabble" + key)) {
localStorage.setItem("trivabble" + key + "_type", type);
}
}
migrateSetting("spellCheckerEnabled", "boolean");
migrateSetting("trivabbleGameNumber", "number");
migrateSetting("trivabbleBoardLang", "string");
migrateSetting("trivabbleGameNumber", "number");
migrateSetting("trivabbleLang", "string");
migrateSetting("trivabblePlayerName", "string");
migrateSetting("SpellCheckerEnabledOnce", "boolean");
migrateSetting("DisableSpellChecker", "boolean");
migrateSetting("GameNumber", "number");
migrateSetting("BoardLang", "string");
migrateSetting("GameNumber", "number");
migrateSetting("Lang", "string");
migrateSetting("PlayerName", "string");
const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) {
return s;
@ -282,11 +278,11 @@
return;
}
if (!force && !getSetting("spellCheckerEnabled")) {
if (!force && !getSetting("SpellCheckerEnabledOnce")) {
myConfirm(
_("Spell checking requires Trivabble to download a dictionary. Do you confirm?"),
function () {
setSetting("spellCheckerEnabled", true);
setSetting("SpellCheckerEnabledOnce", true);
getDictionary(code, callback, true);
}
);
@ -744,15 +740,15 @@
switch (key) {
case "playerName":
name.textContent = value;
setSetting("trivabblePlayerName", value);
setSetting("PlayerName", value);
break;
case "gameNumber":
document.getElementById("number").textContent = value;
setSetting("trivabbleGameNumber", value);
setSetting("GameNumber", value);
break;
case "boardLang":
document.getElementById("board-lang").value = value;
setSetting("trivabbleBoardLang", value);
setSetting("BoardLang", value);
break;
}
}
@ -768,7 +764,7 @@
myAlert(
format(
_("You are about to leave the current game. To recover it, please note its number: {0}"),
getSetting("trivabbleGameNumber")
getSetting("GameNumber")
),
f
);
@ -849,7 +845,7 @@
chatMessages.scrollTop = chatMessages.scrollHeight;
if (sender && sender !== getSetting("trivabblePlayerName")) {
if (sender && sender !== getSetting("PlayerName")) {
if (getSetting("ENABLE_MSG_SOUND")) {
audioChat.play();
}
@ -889,7 +885,7 @@
case "changeBoardLang": {
const newLang = boardLangSelect.querySelector("[value=" + msg.specialMsg.newBoardLang + "]").textContent;
infoMessage(
(msg.sender === getSetting("trivabblePlayerName"))
(msg.sender === getSetting("PlayerName"))
? format(_("You changed the language of the board to {0}"), newLang)
: format(_("{0} changed the language of the board to {1}"), msg.sender, newLang)
);
@ -1076,13 +1072,13 @@
}
if (data.to === "board") {
setCell(data.indexTo, data.letter, Object.prototype.hasOwnProperty.call(data, "player") && data.player !== getSetting("trivabblePlayerName"));
setCell(data.indexTo, data.letter, Object.prototype.hasOwnProperty.call(data, "player") && data.player !== getSetting("PlayerName"));
} else if (data.to === "rack") {
setRackCell(data.indexTo, data.letter);
}
break;
case "setCell":
setCell(data.indexTo, data.letter, Object.prototype.hasOwnProperty.call(data, "player") && data.player !== getSetting("trivabblePlayerName"));
setCell(data.indexTo, data.letter, Object.prototype.hasOwnProperty.call(data, "player") && data.player !== getSetting("PlayerName"));
if ((data.letter !== "") && (currentTilePlayed[data.indexTo] === "-")) {
currentTilePlayed[data.indexTo] = data.letter;
}
@ -1441,9 +1437,9 @@
function cmdsWithContext(cmds) {
return {
gameNumber: getSetting("trivabbleGameNumber") || "",
playerName: getSetting("trivabblePlayerName"),
boardLang: getSetting("trivabbleBoardLang"),
gameNumber: getSetting("GameNumber") || "",
playerName: getSetting("PlayerName"),
boardLang: getSetting("BoardLang"),
version: VERSION,
cmds: cmds
};
@ -1475,13 +1471,13 @@
checkGameInProgress(
function () {
myPrompt(
_("To join a game, please give the number which is displayed on your adversary(ies)' screen.\nIf you do not know it, ask them.\n\nWarning: your adversary must not take your number, (s)he must keep his/her own. If you whish to recover your current game, please not the following number: {0}.").replace("{0}", getSetting("trivabbleGameNumber")),
_("To join a game, please give the number which is displayed on your adversary(ies)' screen.\nIf you do not know it, ask them.\n\nWarning: your adversary must not take your number, (s)he must keep his/her own. If you whish to recover your current game, please not the following number: {0}.").replace("{0}", getSetting("GameNumber")),
function (n) {
n = parseInt(n);
if (isNaN(n)) {
myAlert(_("It seems your did not give a correct number, or you clicked on “Cancel”. As a result, the current game continues, if any. To join a game, click on “Join a game” again."));
} else {
setSetting("trivabbleGameNumber", n);
setSetting("GameNumber", n);
location.reload();
}
}
@ -1510,17 +1506,17 @@
_("To change your name, enter a new one. You can keep using your current name by cancelling. Please note that if you change your name and you have games in progress, you will not be able to keep playing them anymore unless you get back to your current name."),
function (newName) {
if (newName && newName.trim()) {
setSetting("trivabblePlayerName", newName.trim());
name.textContent = getSetting("trivabblePlayerName");
setSetting("PlayerName", newName.trim());
name.textContent = getSetting("PlayerName");
}
},
getSetting("trivabblePlayerNamer")
getSetting("PlayerNamer")
);
}
function startGame(number) {
if (number) {
setSetting("trivabbleGameNumber", number);
setSetting("GameNumber", number);
}
startConnection();
}
@ -1588,7 +1584,7 @@
sendCmds([{cmd: "changeBoard", lang: code}]);
},
function () {
boardLangSelect.value = getSetting("trivabbleBoardLang");
boardLangSelect.value = getSetting("BoardLang");
}
);
}
@ -1778,11 +1774,11 @@
}
function checkSpellingClicked() {
if (getSetting("spellCheckerEnabled") === "false") {
if (getSetting("SpellCheckerEnabledOnce") === "false") {
return;
}
getDictionary(getSetting("trivabbleBoardLang"), checkSpelling);
getDictionary(getSetting("BoardLang"), checkSpelling);
}
function checkSpelling(dictionary) {
@ -2002,16 +1998,21 @@
}
}
function initSpellChecker() {
if (getSetting("ENABLE_SPELL_CHECKER")) {
document.getElementById("check-spelling").hidden = false;
document.getElementById("info-spell-checking").hidden = false;
} else {
document.getElementById("check-spelling").hidden = true;
document.getElementById("info-spell-checking").hidden = true;
function toggleSpellChecker(e) {
const disabled = !getSetting("ENABLE_SPELL_CHECKER") || document.getElementById("disable-spell-checker").checked;
document.getElementById("check-spelling").hidden = disabled;
document.getElementById("info-spell-checking").hidden = disabled;
if (e) {
setSetting("DisableSpellChecker", disabled);
}
}
function initSpellChecker() {
document.getElementById("disable-spell-checker-p").hidden = !getSetting("ENABLE_SPELL_CHECKER");
document.getElementById("disable-spell-checker").checked = getSetting("DisableSpellChecker");
toggleSpellChecker();
}
function translateDuration(x, values) {
if (x < 0) {
return null;
@ -2095,14 +2096,14 @@
}
function repromptName(f) {
if (getSetting("trivabblePlayerName") && getSetting("trivabblePlayerName").trim()) {
if (getSetting("PlayerName") && getSetting("PlayerName").trim()) {
f();
} else {
myPrompt(
_("It seems your did not give your name. You need to do it for the game to run properly."),
function (name) {
if (name && name.trim()) {
setSetting("trivabblePlayerName", name.trim());
setSetting("PlayerName", name.trim());
}
repromptName(f);
@ -2151,7 +2152,7 @@
);
});
boardLangSelect.value = getSetting("trivabbleBoardLang");
boardLangSelect.value = getSetting("BoardLang");
}
function langSelectionChange(e) {
@ -2193,6 +2194,7 @@
document.getElementById("btn-settings").onclick = showSettings;
document.getElementById("btn-settings-close").onclick = hideSettings;
document.getElementById("next-help-msg").onclick = nextHelpMessage;
document.getElementById("disable-spell-checker").onclick = toggleSpellChecker;
window.addEventListener("keydown", function (e) {
if (e.key === "Escape") {
document.querySelector(".modal").classList.remove("show-modal");
@ -2201,12 +2203,12 @@
}
function initGame() {
if (!getSetting("trivabblePlayerName")) {
if (!getSetting("PlayerName")) {
myPrompt(
_("Hello! To begin, enter your name. Your adversaries will see this name when you play with them."),
function (name) {
if (name && name.trim()) {
setSetting("trivabblePlayerName", name);
setSetting("PlayerName", name);
}
repromptName(initGame);
}
@ -2215,7 +2217,7 @@
return;
}
name.textContent = getSetting("trivabblePlayerName");
name.textContent = getSetting("PlayerName");
const letters = "ABCDEFGHIJKLMNO";
@ -2290,15 +2292,15 @@
row.appendChild(board.rows[0].cells[0].cloneNode(false));
if (getSetting("trivabbleGameNumber")) {
document.getElementById("number").textContent = getSetting("trivabbleGameNumber");
if (getSetting("GameNumber")) {
document.getElementById("number").textContent = getSetting("GameNumber");
}
if (getSetting("trivabbleBoardLang")) {
document.getElementById("board-lang").value = getSetting("trivabbleBoardLang");
if (getSetting("BoardLang")) {
document.getElementById("board-lang").value = getSetting("BoardLang");
}
startGame(getSetting("trivabbleGameNumber"));
startGame(getSetting("GameNumber"));
}
function initLang() {

View File

@ -1007,7 +1007,7 @@ function handleRequest(request, response) {
"style-src 'self'; " +
"img-src 'self'; " +
(disableCSP ? "" : "connect-src 'self' " + (
// uzbl (like Safari 9 / iPad 2) does not like unsecure websockets on the
// uzbl (like Safari 9 / iPad 2) does not like insecure websockets on the
// same port with connect-src 'self'
// See https://github.com/w3c/webappsec-csp/issues/7
"ws://" + host + ":" + port + " " +