User:Magnus Manske/templates only talk.js

if ( mw.config.get('wgNamespaceNumber') == 0 ) addOnloadHook ( templates_only_talk ) ;

function templates_only_talk { talk = document.getElementById ( 'ca-talk' ) ; if ( talk.className == 'new' ) return ; // No talk page

talk_url = mw.config.get('wgServer') + mw.config.get('wgScript') + "?action=raw&title=Talk:" + mw.config.get('wgPageName') ; var request = new XMLHttpRequest;

request.open("GET", talk_url, true); request.onreadystatechange = function { if ( request.readyState == 4 && request.status == 200 ) { if ( request.responseText ) { templates_only_talk_callback ( request.responseText ) ; }   }  }; request.send(""); }

function templates_only_talk_callback ( s ) { s = s.split("\n").join(" "); s = s.replace ( /\{\{.*?\}\}/g, '' ) ; s = s.replace ( /\s*/g, '' ) ; if ( s != '' ) return ; // Something other than templates! talk = document.getElementById ( 'ca-talk' ) ; talk.className = 'new' ; }