wiki_ghostguild/theme/license-footer.js

73 lines
1.8 KiB
JavaScript

(function () {
var URL_HREF = "https://creativecommons.org/licenses/by-sa/4.0/";
var PREFIX =
"Content on this site by Baby Ghosts Studio Development Fund is licensed under CC BY-SA 4.0. " +
"To view a copy of this license, visit ";
function isDoc() {
return location.pathname.indexOf("/doc/") === 0;
}
function removeAll() {
document.querySelectorAll(".cc-license-footer").forEach(function (el) {
el.remove();
});
}
function render() {
if (!isDoc()) {
removeAll();
return;
}
var pm = document.querySelector(".ProseMirror");
if (!pm || !pm.parentElement) return;
var target = pm.parentElement;
if (target.querySelector(":scope > .cc-license-footer")) return;
removeAll();
var footer = document.createElement("footer");
footer.className = "cc-license-footer";
var p = document.createElement("p");
p.appendChild(document.createTextNode(PREFIX));
var a = document.createElement("a");
a.href = URL_HREF;
a.target = "_blank";
a.rel = "noopener noreferrer";
a.textContent = URL_HREF;
p.appendChild(a);
footer.appendChild(p);
target.appendChild(footer);
}
var pending = false;
function schedule() {
if (pending) return;
pending = true;
requestAnimationFrame(function () {
pending = false;
render();
});
}
["pushState", "replaceState"].forEach(function (m) {
var orig = history[m];
history[m] = function () {
orig.apply(this, arguments);
schedule();
};
});
window.addEventListener("popstate", schedule);
function start() {
new MutationObserver(schedule).observe(document.body, {
childList: true,
subtree: true,
});
schedule();
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", start);
} else {
start();
}
})();