User:Alien333/tocify.js

/* global mw,$ */ "use strict"; mw.loader.using(['mediawiki.util'], => {

$( => {    if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) < 0) { // if not editing        return;    }    if (mw.config.get('wgCanonicalNamespace') == 'Page' && mw.config.get('wgPageContentModel') == 'proofread-page') { // text-cleaning and other functions in Page:    	var poemisebtn = mw.util.addPortletLink( 'p-tb', '#', 'TOCify', 'TOCify', // not sure what this last string does 'Transform list of rows into a TOC.' ); 	   $(poemisebtn).click(event => { event.preventDefault; TOCify; });   }    }); }); function TOCify {	var l = $("#wpTextbox1").val.split("\n");	var mainpage = l[0];	var def = l[1];	var mode;	var param;	for (let i = 2; i < l.length; i++) {		if (l[i] == "-") {			l[i] = "";		} else if (l[i] != "") {			var t = l[i].split("|");			if (t[0][0] == "!") {				mode = t[0].slice(1);				param = "|" + t.slice(1).join("|");			} else {				mode = def;				var addr = t[0];				if (t[0].search(/ \(.*\)/) != -1) {					t[0] = t[0].slice(0, t[0].search(/ \(.*\)/));				}				addr = addr.replaceAll("", "———");				var tmp = "";				if (addr == t[0]) {					tmp += "|";				} else {					tmp += "|" + t[0] + "";				}				param = tmp + "|" + t.slice(1).join("|");			}			l[i] = "";		}	}	$("#wpTextbox1").val(l.slice(2).join("\n")); }