User:Shelkovitsa/fullwidthSlash.js

// Replace exact occurrences of "/" with "／" within elements with classes .Hani, .Hans, or .Hant var elements = document.querySelectorAll('.Hani, .Hans, .Hant');

elements.forEach(function(element) {   for (var i = 0; i < element.childNodes.length; i++) {        var node = element.childNodes[i];

if (node.nodeType === Node.TEXT_NODE) { node.nodeValue = node.nodeValue.replace(/\//g, '／'); }   } });

function wrapFullwidthSlash { // Load CSS mw.loader.load('/w/index.php?title=User:Shelkovitsa/fullwidthSlash.css&action=raw&ctype=text/css', 'text/css');

function getTextNodes(node) { var textNodes = []; if (node.nodeType === 3) { textNodes.push(node); } else { for (var i = 0; i < node.childNodes.length; i++) { textNodes = textNodes.concat(getTextNodes(node.childNodes[i])); }       }        return textNodes; }

var body = document.body; var textNodes = getTextNodes(body);

textNodes.forEach(function(node) {       var text = node.nodeValue;        var index = text.indexOf("／");

while (index !== -1) { var before = document.createTextNode(text.substring(0, index)); var after = document.createTextNode(text.substring(index + 1)); var span = document.createElement("span"); span.className = "fullwidth-slash"; span.lang = "en"; span.appendChild(document.createTextNode("／"));

node.parentNode.insertBefore(before, node); node.parentNode.insertBefore(span, node); node.parentNode.insertBefore(after, node);

node.parentNode.removeChild(node);

text = after.nodeValue; index = text.indexOf("／"); }   }); }

wrapFullwidthSlash;