User:DTLHS/exclude.js

$(function {	var location = window.location.toString;	if (!location.toString.includes("User:DTLHS/word_tracking")) {		return;	}

var wordStatus = {}; function modifyText(text, wordStatus) { var result = []; text.split("\n").forEach(function(item) {			if (item.startsWith("# {{User:DTLHS/tracking_line|")) {				var parts = item.split("|");				var word = parts[2];				if (word in wordStatus) {					parts[3] = "excluded=" + wordStatus[word] + "}}";					result.push(parts.join("|"))				} else {					result.push(item);				}			} else {				result.push(item);			}		}); return result.join("\n"); }

function include_exclude_click(event) { event.preventDefault;

var el = event.target; var inner = el.innerText; if (inner == "exclude") { el.innerText = "include"; var i = el.parentElement.parentElement.getElementsByTagName("i")[0];

var str = document.createElement("s"); i.parentNode.insertBefore(str, i); str.appendChild(i); var word = i.innerText;

wordStatus[word] = "False"; } else { el.innerText = "exclude";

var i = el.parentElement.parentElement.getElementsByTagName("i")[0]; var str = i.parentElement; str.outerHTML = str.innerHTML;

var word = i.innerText;

}		editor.addEdit({	       'edit': function(text) {	        	wordStatus[word] = "True";	        	return modifyText(text, wordStatus);	        },	        'redo': function  {			},			'undo': function  {			},	        'summary': 'update excluded words'	    });

}

$('.toggle_include_exclude').each(function {		var link = document.createElement('a');

this.parentNode.insertBefore(link, this); link.appendChild(this);

this.addEventListener("click", include_exclude_click); });	var editor = new Editor;

});