User:Magnus Manske/templates only talk.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
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' ;
}