1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-09-13 09:26:23 -07:00

Add custom JS to new script tag instead of calling eval, use ?? instead of ||

This commit is contained in:
Eggbertx 2024-02-28 10:21:23 -08:00
parent 4fd7f91346
commit 001cb9b611
2 changed files with 10 additions and 7 deletions

View file

@ -8,7 +8,7 @@ function updateFlagPreview($sel: JQuery<HTMLSelectElement>) {
if(val === "" || val === "geoip") {
val = "blank.gif";
}
$preview.attr("src", path.join(webroot || "/", "static/flags", val));
$preview.attr("src", path.join(webroot ?? "/", "static/flags", val));
}
function setupQRFlags($flags: JQuery<HTMLSelectElement>) {
@ -17,7 +17,7 @@ function setupQRFlags($flags: JQuery<HTMLSelectElement>) {
$("<div/>").append(
$flags.clone(true, true).attr("id", "qrpost-flag"),
$("<img/>").addClass("flag-preview")
.attr("src", path.join(webroot || "/", "static/flags/blank.gif"))
.attr("src", path.join(webroot ?? "/", "static/flags/blank.gif"))
)
);
}
@ -65,6 +65,6 @@ export function initFlags() {
loadFlagSelection();
$("form").filter((_,el) =>
el.getAttribute("action") === path.join(webroot || "/", "post"))
el.getAttribute("action") === path.join(webroot ?? "/", "post"))
.on("submit", saveFlagSelection);
}

View file

@ -150,10 +150,13 @@ function createLightbox() {
* executes the custom JavaScript set in the settings
*/
export function setCustomJS() {
const customJS = getStorageVal("customjs");
if(customJS !== "") {
eval(customJS);
}
const customJS = getStorageVal("customjs", "");
$("script.customjs").remove();
if(customJS === "") return;
$("<script/>")
.addClass("customjs")
.text(customJS)
.appendTo(document.head);
}
/**