User:Aesulus/common.js: Difference between revisions

From Hololive Fan Wiki
Content added Content deleted
(Created page with "function addButton() { if(!(document.body.classList.contains('ns-subject') && document.body.classList.contains('action-view') && navigator.cookieEnabled)) { // only run pekofy script while viewing wiki subject pages, and only if cookies are enabled return; } // create the button const pekofyButton = document.createElement('svg'); pekofyButton.innerHTML ='<svg xmlns="http://www.w3.org/2000/svg" viewBox="-0.8 -0.5 235 235"><circle id="pekofyButtonCircle" cx="116.7...")
 
(Blanked the page)
Tag: Blanking
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
function addButton() {
if(!(document.body.classList.contains('ns-subject') && document.body.classList.contains('action-view') && navigator.cookieEnabled)) { // only run pekofy script while viewing wiki subject pages, and only if cookies are enabled
return;
}
// create the button
const pekofyButton = document.createElement('svg');
pekofyButton.innerHTML ='<svg xmlns="http://www.w3.org/2000/svg" viewBox="-0.8 -0.5 235 235"><circle id="pekofyButtonCircle" cx="116.7" cy="117" r="117.5" fill="#7dc4fc"/><g fill="none" stroke="#fff" stroke-linecap="round"><path stroke-width="26.296" d="M116.8 42.409v75.292"/><path stroke-width="30" d="M62.7 69.001c-11.6 12.9-18.7 30-18.7 48.7 0 40.1 32.5 72.7 72.7 72.7 40.1 0 72.7-32.5 72.7-72.7 0-18.7-7.1-35.8-18.7-48.7"/></g></svg>';
pekofyButton.setAttribute('style', 'width: 72px; z-index: 100; position: fixed; bottom: 0px; right: 0px; margin: 10px;');
pekofyButton.setAttribute('onclick', 'changeImage()');
document.body.appendChild(pekofyButton);
if (mw.cookie.get("pekofyButtonState") == "true") {
pekofy(document.body);
}
else {
document.getElementById('pekofyButtonCircle').setAttribute('fill', '#000000');
}
}

function pekofy(node) {
if (node.nodeType === Node.TEXT_NODE) {
if (node.nodeValue.trim().length > 0) {
node.unpekofied = node.nodeValue; // store text node's original value in a new property
node.nodeValue = node.nodeValue.replaceAll(/([\.\?!\n]+)/ig, ' peko$1');
}
}
else if (node.nodeType === Node.ELEMENT_NODE) {
var children = node.childNodes;
for (var i = children.length; i--;) {
pekofy(children[i]);
}
}
}

function unpekofy(node) {
if (node.nodeType === Node.TEXT_NODE) {
if (node.hasOwnProperty('unpekofied')) {
node.nodeValue = node.unpekofied;
}
}
else if(node.nodeType === Node.ELEMENT_NODE) {
var children = node.childNodes;
for (var i = children.length; i--;) {
unpekofy(children[i]);
}
}
}

function changeImage() {
var toggleState = mw.cookie.get("pekofyButtonState") == "true";
if (toggleState) {
unpekofy(document.body);
document.getElementById('pekofyButtonCircle').setAttribute('fill', '#000000');
}
else {
pekofy(document.body);
document.getElementById('pekofyButtonCircle').setAttribute('fill', '#7dc4fc');
}
mw.cookie.set("pekofyButtonState", !toggleState);
}

addButton();

Latest revision as of 00:00, 1 April 2022