31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
/* 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 };
|
||
})(); |