Add web/static/js/source-validator.v1.js
This commit is contained in:
parent
0daa7acc63
commit
ca7a3543a0
31
web/static/js/source-validator.v1.js
Normal file
31
web/static/js/source-validator.v1.js
Normal file
@ -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 };
|
||||
})();
|
||||
Loading…
Reference in New Issue
Block a user