User:Joshurtree/talkthread.js

This is an old revision of this page, as edited by Joshurtree (talk | contribs) at 20:04, 31 August 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
//<pre><nowiki>

function createMessage(section) {
  var edit = document.getElementById('wpTextBox1');
  var replyToPos = document.URL.lastIndexOf('replyto=');
  
  edit.value += '{{msg start|id=' + wgArticleId;
  if (replyToPos != -1)
    edit.value += '|' + document.URL.slice(replyToPos); 

  edit.value += '}}\n';
  edit.value += '<!--Insert message here-->\n';
  edit.value += '{{msg end|signature=~~~~|username=' 
                + wgUserName + '|section=' + section + '}}';
}

addOnloadHook(function() {
  var addSection = document.getElementById('ca-addsection');
  var section = document.getElementsByName('wpSection')[0];

  if (addSection) {
    var sections = document.getElementsByTagName('h2').length + 1;
    addSection.firstChild.href = 
      wgServer + wgScriptPath + '/index.php?title=' + wgPageName + 
      '&action=edit&sectionnum=' + sections;
  } else if (section.value != "") {
      createMessage(section);
  } else if (section.value == "") {
      var url = document.URL;
      var sectionNum = 
        url.slice(parseInt(url.indexOf("sectionnum=")) + 11);
      if (isFinite(sectionNum)) {
        var sectionName = prompt("Enter new section name", "");
        if (sectionName != null && sectionName != "") 
          createMessage(sectionNum);
      }
  }
});
//</nowiki></pre>