User:Vorziblix/common.js
Note – after saving, you may have to bypass your browser’s cache to see the changes.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This script lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
This JavaScript is executed for Vorziblix on every page load.
// importScript("User:Jberkel/semhide.js");
importScript("User:Erutuon/contributionsTab.js");
/*
jQuery(document).ready(function($){
console.log("executing common.js");
/********* T210695 WikiHiero kludge : https://phabricator.wikimedia.org/T210695 *********/
/*
$('table.mw-hiero-outer').first().each(function() {
// copies (or rather moves) all child nodes from one to another
var mergeElement = function(src, dst, prepend) {
var el, oldFirst = dst.firstChild;
while ((el = src.firstChild))
prepend ? dst.insertBefore(el, oldFirst) : dst.appendChild(el);
};
var shouldWrap = function() {
return this.parentNode && this.parentNode.tagName == "DIV" && this.parentNode.className != "";
};
var shouldRewrap = function(node) {
return (node.tagName == "SPAN" && $(node).hasClass("mention-tr")) || (["A", "B", "I"].indexOf(node.tagName) >= 0);
};
$('table.mw-hiero-outer').filter(shouldWrap).wrap('<div class="wikt-hierokludge"></div>').each(function() {
var self = this.parentNode, oldSelf;
while (self.parentNode && shouldRewrap(self.parentNode)) {
// ok, there's something that should be inlined. do a swap/rotate;
// make the old parent the child of the div and not the other way around.
// we'll do this by rewrapping the element and then unwrapping the inner div
$(self.parentNode).wrap('<div class="wikt-hierokludge"></div>');
// self is now the outer <div> wrapper
oldSelf = self, self = self.parentNode.parentNode;
$(oldSelf.firstChild).unwrap();
}
var next = self.nextSibling, prev = self.previousSibling;
var allowNext = !!next, allowPrev = !!prev;
// text nodes if they follow or precede the hiero table
var nextText = "", prevText = "";
if (allowNext && next.nodeType == 3) // text node, extract text and disallow merge if it has a newline
allowNext = (nextText = next.textContent).indexOf('\n') < 0, next = next.nextSibling, allowNext &= !!next;
if (allowPrev && prev.nodeType == 3) // text node, extract text and disallow merge if it has a newline
allowPrev = (prevText = prev.textContent).indexOf('\n') < 0, prev = prev.previousSibling, allowPrev &= !!prev;
if (allowNext && next.tagName == "P") // merge <p>
nextText && self.appendChild(document.createTextNode(nextText)), mergeElement(next, self, false), $(next).remove();
if (allowPrev && prev.tagName == "P") // merge <p>
prevText && self.insertBefore(document.createTextNode(prevText), self.firstChild), mergeElement(prev, self, true), $(prev).remove();
else if (allowPrev && prev.tagName == "SPAN") // merge to <span>
prevText && self.insertBefore(document.createTextNode(prevText), self.firstChild), mergeElement(self, prev, false), $(self).remove();
else if (allowPrev && prev.tagName == "DIV" && $(prev).hasClass("wikt-hierokludge")) // merge to existing <div> wrapper
prevText && self.insertBefore(document.createTextNode(prevText), self.firstChild), mergeElement(self, prev, false), $(self).remove();
});
});
});
*/