User:Shelkovitsa/common.js

mw.loader.load('https://en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:MusikAnimal/customWatchlists.js'); importScript("User:Shelkovitsa/fullwidthSlash.js");

// Removes pesky s from my horizontal ".Mong" text. var elements = document.querySelectorAll('.citation-whole, .h-usage-example, .h-quotation, .e-quotation, figcaption, .NavFrame, .nyms');

elements.forEach(function (element) {	var mongElements = element.getElementsByClassName('Mong');	for (var j = 0; j < mongElements.length; j++) {		var content = mongElements[j].innerHTML;		var updatedContent = content.replace(/ /g, ' ');		mongElements[j].innerHTML = updatedContent;	} });

// Makes my mobile viewing experience of certain language headwords just a little bit better. var paragraphs = document.getElementsByTagName('p');

for (var i = 0; i < paragraphs.length; i++) { var paragraph = paragraphs[i];

var hasHeadwordLineChild = paragraph.querySelector('span.headword-line');

if (hasHeadwordLineChild) { var htmlContent = paragraph.innerHTML; var updatedContent = htmlContent.replace(/ /g, ' '); updatedContent = updatedContent.replace(/ (?= )/g, ''); paragraph.innerHTML = updatedContent; } }

// Make every ".wikitable.floatright" have ".kanji-table" added to it. // Now, when "Alternative spelling" comes after "Kanji in this tab", they will have the same styling! // How neat. var sourceTables = document.querySelectorAll('.wikitable.floatright, .kanji-forms');

sourceTables.forEach(function (sourceTable) {	if (hasJpanClass(sourceTable)) {		sourceTable.classList.add('kanji-table');	} });

function hasJpanClass(element) { var descendants = element.querySelectorAll('.Jpan'); return descendants.length > 0; }

// Create hanzi-tables. They're like kanji-tables, but hanzi! var tables = document.querySelectorAll('table');

tables.forEach(function(table) {	if ( table.getAttribute('style') === 'clear: right;margin: 1em;border-collapse: collapse;text-align: center' ) {		table.classList.add('wikitable', 'hanzi-table');	} });

// Remove the trailing " " from the class "vsToggleElement" because it messes with my hanzi-tables on mobile. var elements = document.querySelectorAll('span.vsToggleElement'); for (var i = 0; i < elements.length; i++) { elements[i].innerHTML = elements[i].innerHTML.replace(/ /g, ' '); }