משתמש:Neriah/common.js: הבדלים בין גרסאות בדף
קפיצה לניווט
קפיצה לחיפוש
אין תקציר עריכה |
אין תקציר עריכה |
||
שורה 11: | שורה 11: | ||
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js&action=raw&ctype=text/javascript'); | mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js&action=raw&ctype=text/javascript'); | ||
var buttonSpan = document.createElement("span"); | // סקריפט לצנזור שם ה' - נכתב ע"י [[user:Neriah]] | ||
buttonSpan.className = "plainlinks mw-ui-button"; | if ( | ||
buttonSpan.innerText = " | mw.config.get('wgNamespaceNumber') === 0 || | ||
mw.config.get('wgNamespaceNumber') === 106 || | |||
mw.config.get('wgNamespaceNumber') === 14 | |||
) { | |||
// Check if the script is required before creating the button. | |||
var plain_text = document.getElementById('mw-content-text').textContent; | |||
plain_text = plain_text.replaceAll(/[\u0591-\u05BD\u05BF]/g, ''); // Remove Nikkud and Cantillation marks | |||
const pattern = /(יהוה|אל(וה|ו?הים?)|שדי)/; | |||
if (!document.querySelector('.law') && pattern.test(plain_text)) { | |||
var buttonSpan = document.createElement("span"); | |||
buttonSpan.className = "plainlinks mw-ui-button"; | |||
buttonSpan.id = "censorButton"; | |||
buttonSpan.innerText = "צנזור שם ה'"; | |||
var buttonDiv = document.createElement("div"); | |||
buttonDiv.className = "mw-parser-output"; | |||
buttonDiv.id = "censorButton-div"; | |||
buttonDiv.appendChild(buttonSpan); | |||
var | var heading = document.getElementById('firstHeading'); | ||
heading.appendChild(buttonDiv); | |||
buttonSpan.addEventListener("click", function() { | |||
function censore(element, word) { | |||
let split_str = word.split(""); | |||
const nikud = "[-/]*" | |||
const reg_list = split_str.reduce((list, elem, i) => { | |||
list.push(elem, nikud); | |||
return list; | |||
}, []); | |||
reg_list.splice(0, 0, '('); | |||
reg_list.splice(3, 0, ')', '('); | |||
reg_list.push(')'); | |||
if (word === "אדני") reg_list[reg_list.length-4] = "[-֯/ָּ]*" | |||
const regex = new RegExp(reg_list.join(""), "g"); | |||
element.innerHTML = element.innerHTML.replace(regex, "$1-$2"); | |||
} | |||
var elements = document.getElementsByTagName("*"); | |||
for (var i = 0; i < elements.length; i++) { | |||
censore(elements[i], "יהוה"); | |||
censore(elements[i], "אדני"); | |||
censore(elements[i], "אלוה"); | |||
censore(elements[i], "אלהי"); | |||
}); | censore(elements[i], "אלהים"); | ||
censore(elements[i], "אלוהים"); | |||
censore(elements[i], "צבאות"); | |||
censore(elements[i], "שדי"); | |||
} | |||
}); | |||
} | |||
} |
גרסה מ־23:56, 11 בינואר 2024
/** This script contains the code required for loading [[User:Joeytje50/JWB.js]].
* All other code is located at that page.
*/
//Idea by [[User:Epicgenius]]
$.when(mw.loader.using(['mediawiki.util'], $.ready)).done( function() {
mw.util.addPortletLink("p-tb", mw.config.get('wgArticlePath').replace('$1', "Project:AutoWikiBrowser/Script"), "AWB אונליין", "tb-awbscript", "Run Javascript Wiki Browser");
});
if (mw.config.get('wgCanonicalNamespace')+':'+mw.config.get('wgTitle') === 'Project:AutoWikiBrowser/Script' && mw.config.get('wgAction') == 'view')
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js&action=raw&ctype=text/javascript');
// סקריפט לצנזור שם ה' - נכתב ע"י [[user:Neriah]]
if (
mw.config.get('wgNamespaceNumber') === 0 ||
mw.config.get('wgNamespaceNumber') === 106 ||
mw.config.get('wgNamespaceNumber') === 14
) {
// Check if the script is required before creating the button.
var plain_text = document.getElementById('mw-content-text').textContent;
plain_text = plain_text.replaceAll(/[\u0591-\u05BD\u05BF]/g, ''); // Remove Nikkud and Cantillation marks
const pattern = /(יהוה|אל(וה|ו?הים?)|שדי)/;
if (!document.querySelector('.law') && pattern.test(plain_text)) {
var buttonSpan = document.createElement("span");
buttonSpan.className = "plainlinks mw-ui-button";
buttonSpan.id = "censorButton";
buttonSpan.innerText = "צנזור שם ה'";
var buttonDiv = document.createElement("div");
buttonDiv.className = "mw-parser-output";
buttonDiv.id = "censorButton-div";
buttonDiv.appendChild(buttonSpan);
var heading = document.getElementById('firstHeading');
heading.appendChild(buttonDiv);
buttonSpan.addEventListener("click", function() {
function censore(element, word) {
let split_str = word.split("");
const nikud = "[-/]*"
const reg_list = split_str.reduce((list, elem, i) => {
list.push(elem, nikud);
return list;
}, []);
reg_list.splice(0, 0, '(');
reg_list.splice(3, 0, ')', '(');
reg_list.push(')');
if (word === "אדני") reg_list[reg_list.length-4] = "[-֯/ָּ]*"
const regex = new RegExp(reg_list.join(""), "g");
element.innerHTML = element.innerHTML.replace(regex, "$1-$2");
}
var elements = document.getElementsByTagName("*");
for (var i = 0; i < elements.length; i++) {
censore(elements[i], "יהוה");
censore(elements[i], "אדני");
censore(elements[i], "אלוה");
censore(elements[i], "אלהי");
censore(elements[i], "אלהים");
censore(elements[i], "אלוהים");
censore(elements[i], "צבאות");
censore(elements[i], "שדי");
}
});
}
}