2020-08-04 07:46:04 +08:00
|
|
|
class SettingsGroup {
|
|
|
|
constructor(
|
|
|
|
configName,
|
|
|
|
toggleFunction,
|
|
|
|
setCallback = null,
|
|
|
|
updateCallback = null
|
|
|
|
) {
|
|
|
|
this.configName = configName;
|
|
|
|
this.configValue = config[configName];
|
|
|
|
if (this.configValue === true || this.configValue === false) {
|
|
|
|
this.onOff = true;
|
|
|
|
} else {
|
|
|
|
this.onOff = false;
|
|
|
|
}
|
|
|
|
this.toggleFunction = toggleFunction;
|
|
|
|
this.setCallback = setCallback;
|
|
|
|
this.updateCallback = updateCallback;
|
|
|
|
|
|
|
|
this.updateButton();
|
|
|
|
|
|
|
|
$(document).on(
|
|
|
|
"click",
|
|
|
|
`.pageSettings .section.${this.configName} .button`,
|
|
|
|
(e) => {
|
|
|
|
if (this.onOff) {
|
|
|
|
if ($(e.currentTarget).hasClass("on")) {
|
|
|
|
this.toggleFunction(true);
|
|
|
|
} else {
|
|
|
|
this.toggleFunction(false);
|
|
|
|
}
|
|
|
|
this.updateButton();
|
|
|
|
if (this.setCallback !== null) this.setCallback();
|
|
|
|
} else {
|
|
|
|
let value = $(e.currentTarget).attr(configName);
|
|
|
|
let params = $(e.currentTarget).attr("params");
|
|
|
|
if (params === undefined) {
|
|
|
|
this.toggleFunction(value);
|
|
|
|
} else {
|
|
|
|
this.toggleFunction(value, ...params);
|
|
|
|
}
|
|
|
|
this.updateButton();
|
|
|
|
if (this.setCallback !== null) this.setCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateButton() {
|
|
|
|
this.configValue = config[this.configName];
|
|
|
|
$(`.pageSettings .section.${this.configName} .button`).removeClass(
|
|
|
|
"active"
|
|
|
|
);
|
|
|
|
if (this.onOff) {
|
|
|
|
let onoffstring;
|
|
|
|
if (this.configValue) {
|
|
|
|
onoffstring = "on";
|
|
|
|
} else {
|
|
|
|
onoffstring = "off";
|
|
|
|
}
|
|
|
|
$(
|
|
|
|
`.pageSettings .section.${this.configName} .buttons .button.${onoffstring}`
|
|
|
|
).addClass("active");
|
|
|
|
} else {
|
|
|
|
$(
|
|
|
|
`.pageSettings .section.${this.configName} .button[${this.configName}='${this.configValue}']`
|
|
|
|
).addClass("active");
|
|
|
|
}
|
|
|
|
if (this.updateCallback !== null) this.updateCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let settingsGroups = {};
|
|
|
|
|
|
|
|
settingsGroups.smoothCaret = new SettingsGroup("smoothCaret", setSmoothCaret);
|
|
|
|
settingsGroups.difficulty = new SettingsGroup("difficulty", setDifficulty);
|
|
|
|
settingsGroups.quickTab = new SettingsGroup("quickTab", setQuickTabMode);
|
|
|
|
settingsGroups.showLiveWpm = new SettingsGroup(
|
|
|
|
"showLiveWpm",
|
|
|
|
setShowLiveWpm,
|
|
|
|
() => {
|
|
|
|
settingsGroups.keymapMode.updateButton();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
settingsGroups.showTimerProgress = new SettingsGroup(
|
|
|
|
"showTimerProgress",
|
|
|
|
setShowTimerProgress
|
|
|
|
);
|
|
|
|
settingsGroups.keymapMode = new SettingsGroup(
|
|
|
|
"keymapMode",
|
|
|
|
changeKeymapMode,
|
|
|
|
() => {
|
|
|
|
settingsGroups.showLiveWpm.updateButton();
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
if (config.keymapMode === "off") {
|
2020-08-11 14:13:44 +08:00
|
|
|
$(".pageSettings .section.keymapStyle").addClass("hidden");
|
2020-08-04 07:46:04 +08:00
|
|
|
$(".pageSettings .section.keymapLayout").addClass("hidden");
|
|
|
|
} else {
|
2020-08-11 14:13:44 +08:00
|
|
|
$(".pageSettings .section.keymapStyle").removeClass("hidden");
|
2020-08-04 07:46:04 +08:00
|
|
|
$(".pageSettings .section.keymapLayout").removeClass("hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2020-08-11 01:48:14 +08:00
|
|
|
settingsGroups.keymapMatrix = new SettingsGroup(
|
2020-08-11 14:13:44 +08:00
|
|
|
"keymapStyle",
|
|
|
|
changeKeymapStyle
|
2020-08-11 01:48:14 +08:00
|
|
|
);
|
2020-08-04 07:46:04 +08:00
|
|
|
settingsGroups.keymapLayout = new SettingsGroup(
|
|
|
|
"keymapLayout",
|
|
|
|
changeKeymapLayout
|
|
|
|
);
|
|
|
|
settingsGroups.quickTab = new SettingsGroup(
|
|
|
|
"showKeyTips",
|
|
|
|
setKeyTips,
|
|
|
|
null,
|
|
|
|
() => {
|
|
|
|
if (config.showKeyTips) {
|
|
|
|
$(".pageSettings .tip").removeClass("hidden");
|
|
|
|
} else {
|
|
|
|
$(".pageSettings .tip").addClass("hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
settingsGroups.freedomMode = new SettingsGroup(
|
|
|
|
"freedomMode",
|
|
|
|
setFreedomMode,
|
|
|
|
() => {
|
|
|
|
settingsGroups.confidenceMode.updateButton();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
settingsGroups.confidenceMode = new SettingsGroup(
|
|
|
|
"confidenceMode",
|
|
|
|
setConfidenceMode,
|
|
|
|
() => {
|
|
|
|
settingsGroups.freedomMode.updateButton();
|
2020-08-16 03:36:51 +08:00
|
|
|
settingsGroups.stopOnError.updateButton();
|
2020-08-04 07:46:04 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
settingsGroups.blindMode = new SettingsGroup("blindMode", setBlindMode);
|
|
|
|
settingsGroups.quickEnd = new SettingsGroup("quickEnd", setQuickEnd);
|
2020-08-07 07:42:25 +08:00
|
|
|
settingsGroups.alwaysShowWordsHistory = new SettingsGroup(
|
|
|
|
"alwaysShowWordsHistory",
|
|
|
|
setAlwaysShowWordsHistory
|
|
|
|
);
|
2020-08-04 07:46:04 +08:00
|
|
|
settingsGroups.flipTestColors = new SettingsGroup(
|
|
|
|
"flipTestColors",
|
|
|
|
setFlipTestColors
|
|
|
|
);
|
|
|
|
settingsGroups.colorfulMode = new SettingsGroup(
|
|
|
|
"colorfulMode",
|
|
|
|
setColorfulMode
|
|
|
|
);
|
|
|
|
settingsGroups.randomTheme = new SettingsGroup("randomTheme", setRandomTheme);
|
2020-08-14 06:11:53 +08:00
|
|
|
settingsGroups.stopOnError = new SettingsGroup(
|
2020-08-16 03:36:51 +08:00
|
|
|
"stopOnError",
|
|
|
|
setStopOnError,
|
|
|
|
() => {
|
|
|
|
settingsGroups.confidenceMode.updateButton();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
settingsGroups.playSoundOnError = new SettingsGroup(
|
2020-08-14 06:11:53 +08:00
|
|
|
"playSoundOnError",
|
|
|
|
setPlaySoundOnError
|
|
|
|
);
|
2020-08-04 07:46:04 +08:00
|
|
|
settingsGroups.showAllLines = new SettingsGroup(
|
|
|
|
"showAllLines",
|
|
|
|
setShowAllLines
|
|
|
|
);
|
|
|
|
settingsGroups.smoothLineScroll = new SettingsGroup(
|
|
|
|
"smoothLineScroll",
|
|
|
|
setSmoothLineScroll
|
|
|
|
);
|
|
|
|
settingsGroups.layout = new SettingsGroup("layout", changeLayout);
|
|
|
|
settingsGroups.language = new SettingsGroup("language", changeLanguage);
|
|
|
|
settingsGroups.fontSize = new SettingsGroup("fontSize", changeFontSize);
|
|
|
|
settingsGroups.caretStyle = new SettingsGroup("caretStyle", setCaretStyle);
|
|
|
|
settingsGroups.timerStyle = new SettingsGroup("timerStyle", setTimerStyle);
|
|
|
|
settingsGroups.timerOpacity = new SettingsGroup(
|
|
|
|
"timerOpacity",
|
|
|
|
setTimerOpacity
|
|
|
|
);
|
|
|
|
settingsGroups.timerColor = new SettingsGroup("timerColor", setTimerColor);
|
|
|
|
settingsGroups.fontFamily = new SettingsGroup("fontFamily", setFontFamily);
|
2020-08-04 08:54:35 +08:00
|
|
|
settingsGroups.alwaysShowDecimalPlaces = new SettingsGroup(
|
|
|
|
"alwaysShowDecimalPlaces",
|
|
|
|
setAlwaysShowDecimalPlaces
|
|
|
|
);
|
2020-08-04 07:46:04 +08:00
|
|
|
|
2020-08-04 08:26:17 +08:00
|
|
|
fillSettingsPage();
|
|
|
|
|
|
|
|
async function fillSettingsPage() {
|
2020-07-03 08:35:45 +08:00
|
|
|
let themesEl = $(".pageSettings .section.themes .buttons").empty();
|
2020-08-06 01:52:52 +08:00
|
|
|
|
2020-08-04 08:26:17 +08:00
|
|
|
getThemesList().then((themes) => {
|
2020-08-06 01:52:52 +08:00
|
|
|
themes = themes.sort((a, b) => {
|
|
|
|
let b1 = hexToHSL(a.bgColor);
|
|
|
|
let b2 = hexToHSL(b.bgColor);
|
|
|
|
return b2.lgt - b1.lgt;
|
|
|
|
});
|
2020-08-04 08:26:17 +08:00
|
|
|
themes.forEach((theme) => {
|
|
|
|
themesEl.append(
|
|
|
|
`<div class="theme button" theme='${theme.name}' style="color:${
|
|
|
|
theme.textColor
|
|
|
|
};background:${theme.bgColor}">${theme.name.replace(/_/g, " ")}</div>`
|
|
|
|
);
|
|
|
|
});
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
|
|
|
|
2020-08-04 07:46:04 +08:00
|
|
|
let langEl = $(".pageSettings .section.language .buttons").empty();
|
2020-07-03 08:35:45 +08:00
|
|
|
Object.keys(words).forEach((language) => {
|
|
|
|
if (language === "english_10k") return;
|
|
|
|
langEl.append(
|
|
|
|
`<div class="language button" language='${language}'>${language.replace(
|
|
|
|
"_",
|
|
|
|
" "
|
|
|
|
)}</div>`
|
|
|
|
);
|
|
|
|
if (language === "english_expanded") {
|
|
|
|
langEl.append(
|
|
|
|
`<div class="language button" language='english_10k'>english 10k</div>`
|
|
|
|
);
|
2020-06-27 08:23:50 +08:00
|
|
|
}
|
2020-07-03 08:35:45 +08:00
|
|
|
});
|
|
|
|
|
2020-08-04 07:46:04 +08:00
|
|
|
let layoutEl = $(".pageSettings .section.layout .buttons").empty();
|
2020-07-03 08:35:45 +08:00
|
|
|
Object.keys(layouts).forEach((layout) => {
|
|
|
|
layoutEl.append(
|
|
|
|
`<div class="layout button" layout='${layout}'>${layout.replace(
|
|
|
|
"_",
|
|
|
|
" "
|
|
|
|
)}</div>`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-07-28 22:57:45 +08:00
|
|
|
let keymapEl = $(".pageSettings .section.keymapLayout .buttons").empty();
|
2020-07-28 08:59:06 +08:00
|
|
|
Object.keys(layouts).forEach((layout) => {
|
|
|
|
if (layout.toString() != "default") {
|
|
|
|
keymapEl.append(
|
2020-08-04 07:51:02 +08:00
|
|
|
`<div class="layout button" keymapLayout='${layout}'>${layout.replace(
|
2020-07-28 08:59:06 +08:00
|
|
|
"_",
|
|
|
|
" "
|
|
|
|
)}</div>`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-31 08:33:17 +08:00
|
|
|
let funboxEl = $(".pageSettings .section.funbox .buttons").empty();
|
|
|
|
funboxEl.append(`<div class="funbox button" funbox='none'>none</div>`);
|
2020-08-04 08:26:17 +08:00
|
|
|
getFunboxList().then((funboxModes) => {
|
|
|
|
funboxModes.forEach((funbox) => {
|
|
|
|
if (funbox.name === "mirror") {
|
|
|
|
funboxEl.append(
|
|
|
|
`<div class="funbox button" funbox='${funbox.name}' type="${
|
|
|
|
funbox.type
|
|
|
|
}" style="transform:scaleX(-1);">${funbox.name.replace(
|
|
|
|
/_/g,
|
|
|
|
" "
|
|
|
|
)}</div>`
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
funboxEl.append(
|
|
|
|
`<div class="funbox button" funbox='${funbox.name}' type="${
|
|
|
|
funbox.type
|
|
|
|
}">${funbox.name.replace(/_/g, " ")}</div>`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2020-07-31 08:33:17 +08:00
|
|
|
});
|
|
|
|
|
2020-08-01 21:40:52 +08:00
|
|
|
let fontsEl = $(".pageSettings .section.fontFamily .buttons").empty();
|
2020-08-04 08:26:17 +08:00
|
|
|
getFontsList().then((fonts) => {
|
|
|
|
fonts.forEach((font) => {
|
|
|
|
fontsEl.append(
|
|
|
|
`<div class="button" style="font-family:${
|
|
|
|
font.display !== undefined ? font.display : font.name
|
|
|
|
}" fontFamily="${font.name.replace(/ /g, "_")}" tabindex="0"
|
|
|
|
onclick="this.blur();">${
|
|
|
|
font.display !== undefined ? font.display : font.name
|
|
|
|
}</div>`
|
|
|
|
);
|
|
|
|
});
|
2020-08-01 21:40:52 +08:00
|
|
|
});
|
2020-08-04 08:26:17 +08:00
|
|
|
}
|
2020-08-01 21:40:52 +08:00
|
|
|
|
2020-08-04 08:26:17 +08:00
|
|
|
function updateSettingsPage() {
|
2020-08-04 07:46:04 +08:00
|
|
|
Object.keys(settingsGroups).forEach((group) => {
|
|
|
|
settingsGroups[group].updateButton();
|
|
|
|
});
|
2020-07-03 08:35:45 +08:00
|
|
|
|
2020-08-04 07:46:04 +08:00
|
|
|
refreshTagsSettingsSection();
|
2020-07-31 08:33:17 +08:00
|
|
|
setActiveFunboxButton();
|
2020-07-03 08:35:45 +08:00
|
|
|
setActiveThemeButton();
|
|
|
|
setActiveThemeTab();
|
|
|
|
setCustomThemeInputs();
|
2020-07-07 23:39:48 +08:00
|
|
|
updateDiscordSettingsSection();
|
2020-06-27 08:23:50 +08:00
|
|
|
}
|
|
|
|
|
2020-07-14 05:47:28 +08:00
|
|
|
function showCustomThemeShare() {
|
|
|
|
if ($("#customThemeShareWrapper").hasClass("hidden")) {
|
|
|
|
let save = [];
|
|
|
|
$.each(
|
|
|
|
$(".pageSettings .section.customTheme [type='color']"),
|
|
|
|
(index, element) => {
|
|
|
|
save.push($(element).attr("value"));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$("#customThemeShareWrapper input").val(JSON.stringify(save));
|
|
|
|
$("#customThemeShareWrapper")
|
|
|
|
.stop(true, true)
|
|
|
|
.css("opacity", 0)
|
|
|
|
.removeClass("hidden")
|
|
|
|
.animate({ opacity: 1 }, 100, (e) => {
|
|
|
|
$("#customThemeShare input").focus();
|
|
|
|
$("#customThemeShare input").select();
|
|
|
|
$("#customThemeShare input").focus();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideCustomThemeShare() {
|
|
|
|
if (!$("#customThemeShareWrapper").hasClass("hidden")) {
|
|
|
|
try {
|
|
|
|
config.customThemeColors = JSON.parse(
|
|
|
|
$("#customThemeShareWrapper input").val()
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
showNotification(
|
|
|
|
"Something went wrong. Reverting to default custom colors.",
|
|
|
|
3000
|
|
|
|
);
|
|
|
|
config.customThemeColors = defaultConfig.customThemeColors;
|
|
|
|
}
|
|
|
|
setCustomThemeInputs();
|
|
|
|
applyCustomThemeColors();
|
|
|
|
$("#customThemeShareWrapper input").val("");
|
|
|
|
$("#customThemeShareWrapper")
|
|
|
|
.stop(true, true)
|
|
|
|
.css("opacity", 1)
|
|
|
|
.animate(
|
|
|
|
{
|
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
100,
|
|
|
|
(e) => {
|
|
|
|
$("#customThemeShareWrapper").addClass("hidden");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#customThemeShareWrapper").click((e) => {
|
|
|
|
if ($(e.target).attr("id") === "customThemeShareWrapper") {
|
|
|
|
hideCustomThemeShare();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#customThemeShare .button").click((e) => {
|
|
|
|
hideCustomThemeShare();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#shareCustomThemeButton").click((e) => {
|
|
|
|
showCustomThemeShare();
|
|
|
|
});
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function refreshTagsSettingsSection() {
|
|
|
|
if (firebase.auth().currentUser !== null && dbSnapshot !== null) {
|
|
|
|
let tagsEl = $(".pageSettings .section.tags .tagsList").empty();
|
|
|
|
dbSnapshot.tags.forEach((tag) => {
|
|
|
|
if (tag.active === true) {
|
|
|
|
tagsEl.append(`
|
2020-08-04 07:46:04 +08:00
|
|
|
|
|
|
|
<div class="tag" id="${tag.id}">
|
|
|
|
<div class="active" active="true">
|
|
|
|
<i class="fas fa-check-square"></i>
|
|
|
|
</div>
|
|
|
|
<div class="title">${tag.name}</div>
|
|
|
|
<div class="editButton"><i class="fas fa-pen"></i></div>
|
|
|
|
<div class="removeButton"><i class="fas fa-trash"></i></div>
|
|
|
|
</div>
|
|
|
|
|
2020-06-12 01:02:04 +08:00
|
|
|
`);
|
2020-07-03 08:35:45 +08:00
|
|
|
} else {
|
|
|
|
tagsEl.append(`
|
2020-08-04 07:46:04 +08:00
|
|
|
|
|
|
|
<div class="tag" id="${tag.id}">
|
|
|
|
<div class="active" active="false">
|
|
|
|
<i class="fas fa-square"></i>
|
|
|
|
</div>
|
|
|
|
<div class="title">${tag.name}</div>
|
|
|
|
<div class="editButton"><i class="fas fa-pen"></i></div>
|
|
|
|
<div class="removeButton"><i class="fas fa-trash"></i></div>
|
|
|
|
</div>
|
|
|
|
|
2020-06-12 05:31:06 +08:00
|
|
|
`);
|
2020-07-03 08:35:45 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$(".pageSettings .section.tags").removeClass("hidden");
|
|
|
|
} else {
|
|
|
|
$(".pageSettings .section.tags").addClass("hidden");
|
|
|
|
}
|
2020-05-15 05:22:11 +08:00
|
|
|
}
|
|
|
|
|
2020-07-31 08:33:17 +08:00
|
|
|
function setActiveFunboxButton() {
|
|
|
|
$(`.pageSettings .section.funbox .button`).removeClass("active");
|
2020-08-12 09:09:46 +08:00
|
|
|
$(`.pageSettings .section.funbox .button[funbox='${activeFunBox}']`).addClass(
|
2020-07-31 08:33:17 +08:00
|
|
|
"active"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-16 21:57:01 +08:00
|
|
|
function setActiveThemeButton() {
|
2020-07-03 08:35:45 +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
|
|
|
}
|
|
|
|
|
2020-06-25 13:26:58 +08:00
|
|
|
function setActiveThemeTab() {
|
2020-07-03 08:35:45 +08:00
|
|
|
config.customTheme === true
|
2020-08-05 22:29:57 +08:00
|
|
|
? $(".pageSettings .section.themes .tabs .button[tab='custom']").click()
|
|
|
|
: $(".pageSettings .section.themes .tabs .button[tab='preset']").click();
|
2020-06-25 13:26:58 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 09:10:33 +08:00
|
|
|
function setCustomThemeInputs() {
|
2020-08-05 22:29:57 +08:00
|
|
|
$(
|
|
|
|
".pageSettings .section.themes .tabContainer .customTheme input[type=color]"
|
|
|
|
).each((n, index) => {
|
2020-07-03 08:35:45 +08:00
|
|
|
let currentColor =
|
|
|
|
config.customThemeColors[colorVars.indexOf($(index).attr("id"))];
|
|
|
|
$(index).val(currentColor);
|
|
|
|
$(index).attr("value", currentColor);
|
|
|
|
$(index).prev().text(currentColor);
|
|
|
|
});
|
2020-07-01 09:10:33 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function showActiveTags() {
|
|
|
|
dbSnapshot.tags.forEach((tag) => {
|
|
|
|
if (tag.active === true) {
|
|
|
|
$(
|
|
|
|
`.pageSettings .section.tags .tagsList .tag[id='${tag.id}'] .active`
|
|
|
|
).html('<i class="fas fa-check-square"></i>');
|
|
|
|
} else {
|
|
|
|
$(
|
|
|
|
`.pageSettings .section.tags .tagsList .tag[id='${tag.id}'] .active`
|
|
|
|
).html('<i class="fas fa-square"></i>');
|
|
|
|
}
|
|
|
|
});
|
2020-06-24 00:15:21 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
function toggleTag(tagid, nosave = false) {
|
|
|
|
dbSnapshot.tags.forEach((tag) => {
|
|
|
|
if (tag.id === tagid) {
|
|
|
|
if (tag.active === undefined) {
|
|
|
|
tag.active = true;
|
|
|
|
} else {
|
|
|
|
tag.active = !tag.active;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
updateTestModesNotice();
|
|
|
|
if (!nosave) saveActiveTagsToCookie();
|
2020-06-12 01:18:15 +08:00
|
|
|
}
|
2020-05-15 05:22:11 +08:00
|
|
|
|
2020-07-07 23:39:48 +08:00
|
|
|
function updateDiscordSettingsSection() {
|
|
|
|
//no code and no discord
|
|
|
|
if (firebase.auth().currentUser == null) {
|
|
|
|
$(".pageSettings .section.discordIntegration").addClass("hidden");
|
|
|
|
} else {
|
2020-07-08 03:14:28 +08:00
|
|
|
if (dbSnapshot == null) return;
|
2020-07-07 23:39:48 +08:00
|
|
|
$(".pageSettings .section.discordIntegration").removeClass("hidden");
|
|
|
|
|
|
|
|
if (
|
|
|
|
dbSnapshot.pairingCode === undefined &&
|
|
|
|
dbSnapshot.discordId === undefined
|
|
|
|
) {
|
|
|
|
//show button
|
|
|
|
$(".pageSettings .section.discordIntegration .howto").addClass("hidden");
|
|
|
|
$(".pageSettings .section.discordIntegration .buttons").removeClass(
|
|
|
|
"hidden"
|
|
|
|
);
|
|
|
|
$(".pageSettings .section.discordIntegration .info").addClass("hidden");
|
|
|
|
$(".pageSettings .section.discordIntegration .code").addClass("hidden");
|
|
|
|
} else if (
|
|
|
|
dbSnapshot.pairingCode !== undefined &&
|
|
|
|
dbSnapshot.discordId === undefined
|
|
|
|
) {
|
|
|
|
//show code
|
|
|
|
$(".pageSettings .section.discordIntegration .code .bottom").text(
|
|
|
|
dbSnapshot.pairingCode
|
|
|
|
);
|
|
|
|
$(".pageSettings .section.discordIntegration .howtocode").text(
|
|
|
|
dbSnapshot.pairingCode
|
|
|
|
);
|
|
|
|
$(".pageSettings .section.discordIntegration .howto").removeClass(
|
|
|
|
"hidden"
|
|
|
|
);
|
|
|
|
$(".pageSettings .section.discordIntegration .buttons").addClass(
|
|
|
|
"hidden"
|
|
|
|
);
|
|
|
|
$(".pageSettings .section.discordIntegration .info").addClass("hidden");
|
|
|
|
$(".pageSettings .section.discordIntegration .code").removeClass(
|
|
|
|
"hidden"
|
|
|
|
);
|
|
|
|
} else if (
|
|
|
|
dbSnapshot.pairingCode !== undefined &&
|
|
|
|
dbSnapshot.discordId !== undefined
|
|
|
|
) {
|
|
|
|
$(".pageSettings .section.discordIntegration .howto").addClass("hidden");
|
|
|
|
$(".pageSettings .section.discordIntegration .buttons").addClass(
|
|
|
|
"hidden"
|
|
|
|
);
|
|
|
|
$(".pageSettings .section.discordIntegration .info").removeClass(
|
|
|
|
"hidden"
|
|
|
|
);
|
|
|
|
$(".pageSettings .section.discordIntegration .code").addClass("hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 08:35:45 +08:00
|
|
|
$(document).on("click", ".pageSettings .section.themes .theme", (e) => {
|
|
|
|
let theme = $(e.currentTarget).attr("theme");
|
|
|
|
setTheme(theme);
|
|
|
|
setActiveThemeButton();
|
|
|
|
});
|
2020-05-15 05:22:11 +08:00
|
|
|
|
2020-07-07 23:39:48 +08:00
|
|
|
//discord
|
|
|
|
$(
|
|
|
|
".pageSettings .section.discordIntegration .buttons .generateCodeButton"
|
|
|
|
).click((e) => {
|
|
|
|
showBackgroundLoader();
|
|
|
|
generatePairingCode({ uid: firebase.auth().currentUser.uid }).then((ret) => {
|
|
|
|
hideBackgroundLoader();
|
|
|
|
if (ret.data.status === 1 || ret.data.status === 2) {
|
|
|
|
dbSnapshot.pairingCode = ret.data.pairingCode;
|
|
|
|
$(".pageSettings .section.discordIntegration .code .bottom").text(
|
|
|
|
ret.data.pairingCode
|
|
|
|
);
|
|
|
|
$(".pageSettings .section.discordIntegration .howtocode").text(
|
|
|
|
ret.data.pairingCode
|
|
|
|
);
|
|
|
|
updateDiscordSettingsSection();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-31 08:33:17 +08:00
|
|
|
//funbox
|
|
|
|
$(document).on("click", ".pageSettings .section.funbox .button", (e) => {
|
|
|
|
let funbox = $(e.currentTarget).attr("funbox");
|
|
|
|
let type = $(e.currentTarget).attr("type");
|
|
|
|
activateFunbox(funbox, type);
|
|
|
|
setActiveFunboxButton();
|
|
|
|
});
|
|
|
|
|
2020-06-12 01:18:15 +08:00
|
|
|
//tags
|
2020-07-03 08:35:45 +08:00
|
|
|
$(document).on(
|
|
|
|
"click",
|
|
|
|
".pageSettings .section.tags .tagsList .tag .active",
|
|
|
|
(e) => {
|
2020-06-12 01:18:15 +08:00
|
|
|
let target = e.currentTarget;
|
2020-07-03 08:35:45 +08:00
|
|
|
let tagid = $(target).parent(".tag").attr("id");
|
2020-06-24 00:15:21 +08:00
|
|
|
toggleTag(tagid);
|
|
|
|
showActiveTags();
|
2020-07-03 08:35:45 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$(document).on("click", ".pageSettings .section.tags .addTagButton", (e) => {
|
|
|
|
showEditTags("add");
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on(
|
|
|
|
"click",
|
|
|
|
".pageSettings .section.tags .tagsList .tag .editButton",
|
|
|
|
(e) => {
|
|
|
|
let tagid = $(e.currentTarget).parent(".tag").attr("id");
|
|
|
|
let name = $(e.currentTarget).siblings(".title").text();
|
|
|
|
showEditTags("edit", tagid, name);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$(document).on(
|
|
|
|
"click",
|
|
|
|
".pageSettings .section.tags .tagsList .tag .removeButton",
|
|
|
|
(e) => {
|
|
|
|
let tagid = $(e.currentTarget).parent(".tag").attr("id");
|
|
|
|
let name = $(e.currentTarget).siblings(".title").text();
|
|
|
|
showEditTags("remove", tagid, name);
|
|
|
|
}
|
|
|
|
);
|
2020-06-19 09:55:11 +08:00
|
|
|
|
2020-06-11 12:18:05 +08:00
|
|
|
//theme tabs & custom theme
|
2020-07-03 08:35:45 +08:00
|
|
|
const colorVars = [
|
|
|
|
"--bg-color",
|
|
|
|
"--main-color",
|
|
|
|
"--caret-color",
|
|
|
|
"--sub-color",
|
|
|
|
"--text-color",
|
|
|
|
"--error-color",
|
|
|
|
"--error-extra-color",
|
2020-07-04 09:59:21 +08:00
|
|
|
"--colorful-error-color",
|
|
|
|
"--colorful-error-extra-color",
|
2020-07-03 08:35:45 +08:00
|
|
|
];
|
|
|
|
|
2020-08-05 22:29:57 +08:00
|
|
|
$(".pageSettings .section.themes .tabs .button").click((e) => {
|
|
|
|
$(".pageSettings .section.themes .tabs .button").removeClass("active");
|
2020-07-03 08:35:45 +08:00
|
|
|
var $target = $(e.currentTarget);
|
|
|
|
$target.addClass("active");
|
|
|
|
setCustomThemeInputs();
|
|
|
|
if ($target.attr("tab") == "preset") {
|
2020-08-08 04:29:16 +08:00
|
|
|
setCustomTheme(false, true);
|
2020-07-03 08:35:45 +08:00
|
|
|
applyCustomThemeColors();
|
2020-07-23 21:21:16 +08:00
|
|
|
swapElements(
|
2020-08-05 22:29:57 +08:00
|
|
|
$('.pageSettings .section.themes .tabContainer [tabContent="custom"]'),
|
|
|
|
$('.pageSettings .section.themes .tabContainer [tabContent="preset"]'),
|
2020-07-23 21:21:16 +08:00
|
|
|
250
|
|
|
|
);
|
2020-07-03 08:35:45 +08:00
|
|
|
} else {
|
2020-08-08 04:29:16 +08:00
|
|
|
setCustomTheme(true, true);
|
2020-07-03 08:35:45 +08:00
|
|
|
applyCustomThemeColors();
|
2020-07-23 21:21:16 +08:00
|
|
|
swapElements(
|
2020-08-05 22:29:57 +08:00
|
|
|
$('.pageSettings .section.themes .tabContainer [tabContent="preset"]'),
|
|
|
|
$('.pageSettings .section.themes .tabContainer [tabContent="custom"]'),
|
2020-07-23 21:21:16 +08:00
|
|
|
250
|
|
|
|
);
|
2020-07-03 08:35:45 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-08-05 22:29:57 +08:00
|
|
|
$(
|
|
|
|
".pageSettings .section.themes .tabContainer .customTheme input[type=color]"
|
|
|
|
).on("input", (e) => {
|
2020-07-03 08:35:45 +08:00
|
|
|
setCustomTheme(true, true);
|
|
|
|
let $colorVar = $(e.currentTarget).attr("id");
|
|
|
|
let $pickedColor = $(e.currentTarget).val();
|
|
|
|
|
|
|
|
document.documentElement.style.setProperty($colorVar, $pickedColor);
|
|
|
|
$("#" + $colorVar).attr("value", $pickedColor);
|
|
|
|
$("[for=" + $colorVar + "]").text($pickedColor);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".pageSettings .saveCustomThemeButton").click((e) => {
|
|
|
|
let save = [];
|
|
|
|
$.each(
|
|
|
|
$(".pageSettings .section.customTheme [type='color']"),
|
|
|
|
(index, element) => {
|
|
|
|
save.push($(element).attr("value"));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
setCustomThemeColors(save);
|
|
|
|
showNotification("Custom theme colors saved", 1000);
|
|
|
|
});
|
2020-08-03 04:48:19 +08:00
|
|
|
|
|
|
|
$(".pageSettings .sectionGroupTitle").click((e) => {
|
|
|
|
let group = $(e.currentTarget).attr("group");
|
|
|
|
$(`.pageSettings .settingsGroup.${group}`)
|
|
|
|
.stop(true, true)
|
|
|
|
.slideToggle(250)
|
|
|
|
.toggleClass("slideup");
|
|
|
|
if ($(`.pageSettings .settingsGroup.${group}`).hasClass("slideup")) {
|
|
|
|
$(`.pageSettings .sectionGroupTitle[group=${group}] .fas`)
|
|
|
|
.stop(true, true)
|
|
|
|
.animate(
|
|
|
|
{
|
|
|
|
deg: -90,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
duration: 250,
|
|
|
|
step: function (now) {
|
|
|
|
$(this).css({ transform: "rotate(" + now + "deg)" });
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$(`.pageSettings .sectionGroupTitle[group=${group}] .fas`)
|
|
|
|
.stop(true, true)
|
|
|
|
.animate(
|
|
|
|
{
|
|
|
|
deg: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
duration: 250,
|
|
|
|
step: function (now) {
|
|
|
|
$(this).css({ transform: "rotate(" + now + "deg)" });
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|