From ca7a3543a07a70398018b48b1a35997d2153e737 Mon Sep 17 00:00:00 2001 From: Joshua Laymon Date: Tue, 2 Sep 2025 03:01:11 +0000 Subject: [PATCH] Add web/static/js/source-validator.v1.js --- web/static/js/source-validator.v1.js | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 web/static/js/source-validator.v1.js diff --git a/web/static/js/source-validator.v1.js b/web/static/js/source-validator.v1.js new file mode 100644 index 0000000..a04360e --- /dev/null +++ b/web/static/js/source-validator.v1.js @@ -0,0 +1,31 @@ +/* source-validator.v1.js + Centralizes logic for deciding if a "Source" string should link to WOL. + Exposes: + - SourceValidator.isWOLSource(text) -> boolean + - SourceValidator.buildWOLSearchURL(text) -> string +*/ +window.SourceValidator = (function () { + // Publications / codes that produce valid WOL links (from your template list) + const PUB_CODES = [ + "wp","ws","yb","mwb","w","g","ap","apf","be","bh","br","bt","btg","cf","cl","ct","dp", + "fg","fy","gt","hb","im","ip","it","jv","ka","kj","kl","lf","lff","ll","ly","my","od", + "pe","po","pt","rr","rs","sg","sh","si","td","tp","tr","ts","un","jy" + ]; + + function normalize(s) { return (s || "").trim().toLowerCase(); } + + function isWOLSource(text) { + const t = normalize(text); + if (!t) return false; + // Keep this simple: if the string starts with any known code, treat it as WOL-capable. + return PUB_CODES.some(code => t.startsWith(code)); + } + + function buildWOLSearchURL(text) { + const q = encodeURIComponent(text || ""); + // Same search endpoint you’re already using + return `https://wol.jw.org/en/wol/l/r1/lp-e?q=${q}`; + } + + return { isWOLSource, buildWOLSearchURL }; +})(); \ No newline at end of file