User:AoV2/talk filter

From Wikipedia, the free encyclopedia

This script makes talk-pages appear as red-links if they are empty except for banner templates. ―AoV² 09:45, 14 March 2010 (UTC)

function talk_filter(){
	if(wgNamespaceNumber < 0) return;
	if(document.getElementById("ca-talk").className.match(/\bnew\b/)) return;
	talk_page = wgFormattedNamespaces[(wgNamespaceNumber % 2) + 1] + ":" + wgTitle;
	f1 = function(obj) {
		for(x in obj.query.pages) txt = obj.query.pages[x].revisions[0]["*"].replace(/\n/g, "");
		for(i = 0; i < 10; i++) txt = txt.replace(/(?:\{\{[^\{\}]+\}\}|\s*)/g, "");
		if(!txt.length) document.getElementById("ca-talk").className="new";
		}
	mw.loader.load(mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&prop=revisions&rvprop=content&callback=f1&titles=" + talk_page);
	}
addOnloadHook(talk_filter);