User:HarJIT/Scripts/kutentemplate.js

// // XXX document this here // Adds a button below the source editor. // // I am not selling this and make no guarantees of safety, fitness or that it won't mangle the content. // You are advised to double check that the scripted process has produced the desired results, and // clean up where necessary. // // Usage: mw.loader.load("//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:HarJIT/Scripts/kutentemplate.js"); // // Canonical: m:w:User:HarJIT/Scripts/kutentemplate.js

( => {

String.prototype.pysplit = function { if (arguments.length == 1) { return this.split(arguments[0]); }   var temp = this.split(arguments[0], arguments[1]); var heading = temp.join(arguments[0]).length + arguments[0].length; temp[temp.length] = this.substring(heading); return temp; };

String.prototype.startswith = function (s) { return this.substring(0, s.length) == s; };

String.prototype.endswith = function (s) { return this.substring(this.length - s.length) == s; };

String.prototype.contains = function (s) { return this.indexOf(s) >= 0; };

var fix = function (inp) { var doz = inp.split("\n"); var output = doz[0]; doz.slice(1).forEach((ii) => {       var i = ii;        if (i.contains(" ")) {            i = i.pysplit("}} ", 1).join("|kuten=") + "}}";        } else if (i.contains("!{{chset-left|") && i.contains("_/")) {            i = i.pysplit("_/", 1).join("|");        }        output += "\n" + i;    }); return output; };

jQuery( => {   if (jQuery("#editpage-copywarn").length) {        var butn = document.createElement("input");        butn.setAttribute("type", "button");        butn.setAttribute("value", "Templatise kuten");        var nxt = jQuery("#editpage-copywarn")[0];        nxt.parentNode.insertBefore(butn, nxt);        butn.onclick =  => {            //var rprt = SUMMARY;            var txt = jQuery("#wpTextbox1")[0];            var vl = txt.value;            var fx = fix(vl);            if (fx != vl) {                txt.value = fx;                //jQuery("#wpSummary")[0].value = rprt;            }        }    } });

});

// End: m:w:User:HarJIT/Scripts/kutentemplate.js //