monkeytype/public/js/settings.js

193 lines
6.6 KiB
JavaScript
Raw Normal View History

2020-05-15 05:22:11 +08:00
function updateSettingsPage(){
2020-05-28 07:35:41 +08:00
let themesEl = $(".pageSettings .section.themes .buttons").empty();
themesList.forEach(theme => {
2020-05-29 23:29:27 +08:00
themesEl.append(`<div class="theme" theme='${theme.name}' style="color:${theme.textColor};background:${theme.bgColor}">${theme.name.replace('_', ' ')}</div>`);
2020-05-16 21:57:01 +08:00
})
2020-05-28 07:35:41 +08:00
let langEl = $(".pageSettings .section.languages .buttons").empty();
2020-05-16 21:57:01 +08:00
Object.keys(words).forEach(language => {
langEl.append(`<div class="language" language='${language}'>${language.replace('_', ' ')}</div>`);
})
2020-05-15 05:22:11 +08:00
setSettingsButton('smoothCaret', config.smoothCaret);
setSettingsButton('quickTab', config.quickTab);
setSettingsButton('liveWpm', config.showLiveWpm);
setSettingsButton('keyTips', config.showKeyTips);
2020-05-23 02:39:35 +08:00
setSettingsButton('freedomMode', config.freedomMode);
2020-05-16 21:57:01 +08:00
setActiveThemeButton();
setActiveLanguageButton();
setActiveFontSizeButton();
setActiveDifficultyButton();
2020-05-29 12:32:38 +08:00
setActiveCaretStyleButton();
2020-05-15 05:22:11 +08:00
if (config.showKeyTips) {
$(".pageSettings .tip").removeClass('hidden');
} else {
$(".pageSettings .tip").addClass('hidden');
}
}
2020-05-16 21:57:01 +08:00
function setActiveThemeButton() {
2020-05-28 07:35:41 +08:00
$(`.pageSettings .section.themes .theme`).removeClass('active');
$(`.pageSettings .section.themes .theme[theme=${config.theme}]`).addClass('active');
2020-05-16 21:57:01 +08:00
}
function setActiveFontSizeButton() {
$(`.pageSettings .section.fontSize .buttons .button`).removeClass('active');
$(`.pageSettings .section.fontSize .buttons .button[fontsize=`+config.fontSize+`]`).addClass('active');
}
function setActiveDifficultyButton() {
$(`.pageSettings .section.difficulty .buttons .button`).removeClass('active');
$(`.pageSettings .section.difficulty .buttons .button[difficulty=`+config.difficulty+`]`).addClass('active');
}
2020-05-16 21:57:01 +08:00
function setActiveLanguageButton() {
2020-05-28 07:35:41 +08:00
$(`.pageSettings .section.languages .language`).removeClass('active');
$(`.pageSettings .section.languages .language[language=${config.language}]`).addClass('active');
}
2020-05-29 12:32:38 +08:00
function setActiveCaretStyleButton() {
$(`.pageSettings .section.caretStyle .buttons .button`).removeClass('active');
$(`.pageSettings .section.caretStyle .buttons .button[caret=`+config.caretStyle+`]`).addClass('active');
}
2020-05-15 05:22:11 +08:00
function setSettingsButton(buttonSection,tf) {
if (tf) {
$(".pageSettings .section."+buttonSection+" .buttons .button.on").addClass('active');
$(".pageSettings .section."+buttonSection+" .buttons .button.off").removeClass('active');
} else {
$(".pageSettings .section."+buttonSection+" .buttons .button.off").addClass('active');
$(".pageSettings .section."+buttonSection+" .buttons .button.on").removeClass('active');
}
}
//smooth caret
$(".pageSettings .section.smoothCaret .buttons .button.on").click(e => {
setSmoothCaret(true);
showNotification('Smooth caret on', 1000);
setSettingsButton('smoothCaret', config.smoothCaret);
})
$(".pageSettings .section.smoothCaret .buttons .button.off").click(e => {
setSmoothCaret(false);
showNotification('Smooth caret off', 1000);
setSettingsButton('smoothCaret', config.smoothCaret);
})
//quick tab
$(".pageSettings .section.quickTab .buttons .button.on").click(e => {
setQuickTabMode(true);
showNotification('Quick tab on', 1000);
setSettingsButton('quickTab', config.quickTab);
})
$(".pageSettings .section.quickTab .buttons .button.off").click(e => {
setQuickTabMode(false);
showNotification('Quick tab off', 1000);
setSettingsButton('quickTab', config.quickTab);
})
//live wpm
$(".pageSettings .section.liveWpm .buttons .button.on").click(e => {
config.showLiveWpm = true;
saveConfigToCookie();
2020-05-15 05:22:11 +08:00
showNotification('Live WPM on', 1000);
setSettingsButton('liveWpm', config.showLiveWpm);
})
$(".pageSettings .section.liveWpm .buttons .button.off").click(e => {
config.showLiveWpm = false;
saveConfigToCookie();
2020-05-15 05:22:11 +08:00
showNotification('Live WPM off', 1000);
setSettingsButton('liveWpm', config.showLiveWpm);
})
2020-05-23 02:39:35 +08:00
//freedom mode
$(".pageSettings .section.freedomMode .buttons .button.on").click(e => {
setFreedomMode(true);
saveConfigToCookie();
showNotification('Freedom mode on', 1000);
setSettingsButton('freedomMode', config.freedomMode);
})
$(".pageSettings .section.freedomMode .buttons .button.off").click(e => {
setFreedomMode(false);
saveConfigToCookie();
showNotification('Freedom mode off', 1000);
setSettingsButton('freedomMode', config.freedomMode);
})
2020-05-15 05:22:11 +08:00
//keytips
$(".pageSettings .section.keyTips .buttons .button.on").click(e => {
setKeyTips(true);
showNotification('Key tips on', 1000);
setSettingsButton('keyTips', config.showKeyTips);
if (config.showKeyTips) {
$(".pageSettings .tip").removeClass('hidden');
} else {
$(".pageSettings .tip").addClass('hidden');
}
})
$(".pageSettings .section.keyTips .buttons .button.off").click(e => {
setKeyTips(false);
showNotification('Key tips off', 1000);
setSettingsButton('keyTips', config.showKeyTips);
if (config.showKeyTips) {
$(".pageSettings .tip").removeClass('hidden');
} else {
$(".pageSettings .tip").addClass('hidden');
}
})
2020-05-16 21:57:01 +08:00
//themes
// $(document).on("mouseover",".pageSettings .section.themes .theme", (e) => {
// let theme = $(e.currentTarget).attr('theme');
// previewTheme(theme);
// })
2020-05-15 05:22:11 +08:00
2020-05-28 07:35:41 +08:00
$(document).on("click",".pageSettings .section.themes .theme", (e) => {
2020-05-15 05:22:11 +08:00
let theme = $(e.currentTarget).attr('theme');
setTheme(theme);
2020-05-16 21:57:01 +08:00
setActiveThemeButton();
2020-05-15 05:22:11 +08:00
})
// $(document).on("mouseleave",".pageSettings .section.themes", (e) => {
// setTheme(config.theme);
// })
2020-05-16 21:57:01 +08:00
//languages
2020-05-28 07:35:41 +08:00
$(document).on("click",".pageSettings .section.languages .language", (e) => {
2020-05-16 21:57:01 +08:00
let language = $(e.currentTarget).attr('language');
changeLanguage(language);
showNotification('Language changed', 1000);
2020-05-16 21:57:01 +08:00
restartTest();
setActiveLanguageButton();
})
//fontsize
$(document).on("click",".pageSettings .section.fontSize .button", (e) => {
let fontSize = $(e.currentTarget).attr('fontsize');
changeFontSize(fontSize);
showNotification('Font size changed', 1000);
setActiveFontSizeButton();
})
//difficulty
$(document).on("click",".pageSettings .section.difficulty .button", (e) => {
let difficulty = $(e.currentTarget).attr('difficulty');
setDifficulty(difficulty);
showNotification('Difficulty changed', 1000);
setActiveDifficultyButton();
2020-05-29 12:32:38 +08:00
})
//caret style
$(document).on("click",".pageSettings .section.caretStyle .button", (e) => {
let caretStyle = $(e.currentTarget).attr('caret');
setCaretStyle(caretStyle);
showNotification('Caret style updated', 1000);
setActiveCaretStyleButton();
})