/**
* Overrides "Bibliography" UI labels to set a custom term (Reference)(set on the last line).
*/
(function renameBibliography(newLabel) {
// Replace all occurrences of substrings without using replaceAll
function replaceAllStr(str, find, repl) {
return String(str).split(find).join(repl);
}
// Patch the DKI translation dictionary when available
function patchDictionary() {
try {
if (!window.DKI || !DKI.translatedPlayerStrings) { return false; }
var locales = DKI.translatedPlayerStrings;
for (var loc in locales) {
if (!locales.hasOwnProperty(loc)) continue;
var t = locales[loc] || {};
if (t.doc && t.doc["Bibliography Heading"]) {
t.doc["Bibliography Heading"] = newLabel;
}
if (t.references) {
if (t.references.bibliographyWindowTitle) {
t.references.bibliographyWindowTitle = newLabel;
}
if (t.references.viewBibliography) {
t.references.viewBibliography = "View " + newLabel;
}
}
if (t.endCourse && t.endCourse.viewBibliography) {
t.endCourse.viewBibliography = "View " + newLabel;
}
}
return true;
} catch (e) {
return false;
}
}
// Walk text nodes and swap visible strings as a safety net
function replaceInDOM(root) {
try {
var pairs = [
["Bibliography", newLabel],
["View Bibliography", "View " + newLabel],
["View the bibliography.", "View the " + newLabel.toLowerCase() + "."],
["Bibliography:", newLabel + ":"]
];
function processTextNode(n) {
var v = n.nodeValue;
if (!v || !(/\S/).test(v)) return;
for (var i = 0; i < pairs.length; i++) {
v = replaceAllStr(v, pairs[i][0], pairs[i][1]);
}
if (v !== n.nodeValue) { n.nodeValue = v; }
}
if (document.createTreeWalker && window.NodeFilter) {
var walker = document.createTreeWalker(
root || document.body,
NodeFilter.SHOW_TEXT,
null,
false
);
var node;
while ((node = walker.nextNode())) {
processTextNode(node);
}
} else {
// Fallback traversal for very old engines
var all = (root || document.body).getElementsByTagName("*");
for (var j = 0; j < all.length; j++) {
var el = all[j];
for (var k = 0; k < el.childNodes.length; k++) {
var cn = el.childNodes[k];
if (cn.nodeType === 3) processTextNode(cn);
}
}
}
} catch (e) {}
}
// Try to patch immediately; if not ready, poll briefly
function init() {
if (patchDictionary()) return;
var tries = 0, max = 120; // ~6s at 50ms
var iv = setInterval(function () {
if (patchDictionary() || ++tries >= max) clearInterval(iv);
}, 50);
}
function onReady(fn) {
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", fn);
} else {
fn();
}
}
onReady(function () {
init();
replaceInDOM(document.body);
});
// Observe late inserts if supported
if (window.MutationObserver) {
try {
var mo = new MutationObserver(function (muts) {
for (var i = 0; i < muts.length; i++) {
var m = muts[i];
if (!m.addedNodes) continue;
for (var j = 0; j < m.addedNodes.length; j++) {
var n = m.addedNodes[j];
if (n.nodeType === 1) replaceInDOM(n);
else if (n.nodeType === 3) replaceInDOM(n.parentNode || document.body);
}
}
});
mo.observe(document.documentElement, { subtree: true, childList: true, characterData: true });
} catch (e) {}
} else {
// Last-resort periodic sweep for older browsers
setInterval(function(){ replaceInDOM(document.body); }, 1000);
}
})("References"); // <-- set your preferred label here
Confirm
Comments ( 0 )
Sign in to join the discussion.