User:Tpbradbury/monobook.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin is at User:Tpbradbury/monobook.css. |
console.log("Monobook.js is loading");
$(function() {
var search = document.getElementById("p-search");
var cactions = document.getElementById("p-cactions");
if (search && cactions) {
document.getElementById("column-one").insertBefore(search, cactions);
}
});
mw.loader.load("https://en.wiktionary.org/w/index.php?title=User:Connel_MacKenzie/spellcheck.js&action=raw&ctype=text/javascript");
importStylesheet('User:Anomie/linkclassifier.css');
function addStylesheet() {
const stylesheet = document.createElement('style');
stylesheet.innerHTML = `
.highlight-unreferenced {
background-color: LightPink !important;
border: 2px solid red !important;
}
`;
document.head.appendChild(stylesheet);
console.log("Stylesheet added");
}
function highlightUnreferencedPassages() {
console.log("highlightUnreferencedPassages function is executed");
var contentText = document.getElementById('mw-content-text');
if (!contentText) {
console.log("mw-content-text element not found");
return;
}
console.log("mw-content-text element found");
var elements = contentText.querySelectorAll('p, li, h2, h3');
console.log("Total elements found:", elements.length);
var stopHighlighting = false;
var stopSections = ["references", "see also", "external links", "further reading", "citations", "notes", "bibliography", "explanatory notes"];
elements.forEach(function (element) {
if (stopHighlighting) return;
var tag = element.tagName.toLowerCase();
if ((tag === 'h2' || tag === 'h3') && stopSections.some(section => element.textContent.trim().toLowerCase().includes(section))) {
stopHighlighting = true;
console.log("Stopping at section:", element.textContent.trim().toLowerCase());
return;
}
if (!stopHighlighting && (tag === 'p' || tag === 'li') && element.querySelectorAll('.reference').length === 0) {
element.classList.add('highlight-unreferenced');
console.log("Highlighted unreferenced element:", element);
}
});
}
function isMainNamespaceContentPage() {
var namespace = mw.config.get('wgNamespaceNumber');
var action = mw.config.get('wgAction');
return namespace === 0 && action === 'view';
}
mw.loader.using(['mediawiki.util'], function () {
console.log("HighlightUnreferencedPassages.js is loading");
$(document).ready(function() {
console.log("Document ready");
if (isMainNamespaceContentPage()) {
addStylesheet();
highlightUnreferencedPassages();
console.log("Highlighting completed");
} else {
console.log("Not a main namespace content page, skipping highlighting");
}
});
});