1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-27 11:26:22 -07:00

Add defer to gochan.js script tag, add option to open external links in new tab

This commit is contained in:
Eggbertx 2025-02-22 11:35:03 -08:00
parent 41fa1f6280
commit 1339f58a66
3 changed files with 18 additions and 4 deletions

View file

@ -4,7 +4,7 @@ import "./vars";
import "./cookies";
import "./notifications";
import { setPageBanner } from "./dom/banners";
import { setCustomCSS, setCustomJS, setTheme } from "./settings";
import { setCustomCSS, setCustomJS, setTheme, updateExternalLinks } from "./settings";
import { handleKeydown } from "./boardevents";
import { initStaff, createStaffMenu, addStaffThreadOptions } from "./management/manage";
import { getPageThread } from "./postinfo";
@ -57,6 +57,7 @@ $(() => {
});
$(document).on("keydown", handleKeydown);
initFlags();
updateExternalLinks();
setCustomCSS();
setCustomJS();
});

View file

@ -217,6 +217,19 @@ function setLineHeight() {
}
}
export function updateExternalLinks(post?: JQuery<HTMLElement>) {
const $src = post ?? $(".post-text");
const extPostLinks = $src.find<HTMLAnchorElement>("a:not(.postref)");
const newTab = getBooleanStorageVal("extlinksnewtab", true);
for(const link of extPostLinks) {
if(link.hostname !== location.hostname) {
link.target = newTab?"_blank":"_self";
} else {
link.target = "_self";
}
}
}
/**
* executes the custom JavaScript set in the settings
*/
@ -266,6 +279,7 @@ $(() => {
if(getBooleanStorageVal("useqr", true)) initQR();
else closeQR();
}));
settings.set("extlinksnewtab", new BooleanSetting("extlinksnewtab", "Open external links in new tab", true, updateExternalLinks));
settings.set("persistentqr", new BooleanSetting("persistentqr", "Persistent Quick Reply", false));
settings.set("watcherseconds", new NumberSetting("watcherseconds", "Check watched threads every # seconds", 15, {
min: 2
@ -276,6 +290,5 @@ $(() => {
settings.set("customjs", new TextSetting("customjs", "Custom JavaScript", ""));
settings.set("customcss", new TextSetting("customcss", "Custom CSS", "", setCustomCSS));
if($settingsButton === null)
$settingsButton = new TopBarButton("Settings", createLightbox, {before: "a#watcher"});
$settingsButton ??= new TopBarButton("Settings", createLightbox, {before: "a#watcher"});
});

View file

@ -27,7 +27,7 @@
<link id="flags" rel="stylesheet" href="{{webPath `/css/flags.css`}}"/>
{{- end -}}
<script type="text/javascript" src="{{webPath "/js/consts.js"}}"></script>
<script type="text/javascript" src="{{webPath "/js/gochan.js"}}"></script>
<script type="text/javascript" src="{{webPath "/js/gochan.js"}}" defer></script>
</head>
<body>
{{template "topbar" .}}