User:Whiteknight/per book/Wikibooks:Reading room.js

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
  • Konqueror: simply click the Reload button, or press F5;
  • Opera users may need to completely clear their cache in Tools→Preferences.
//<pre>

$(function () {
  var editlinks = wk.getElementsByClass("editsection");
  for(var i = 0; i < editlinks.length; i++) {
    var j = i + 1
    var b = document.createElement("a");
    b.href = "javascript:TagSection(" + j + ");";
    b.innerHTML = "tag";
    b.id = "WK_Tag_" + j;
    var c = document.createElement("a");
    c.href = "javascript:DeleteSection(" + j + ");";
    c.innerHTML = "delete";
    c.id = "WK_Delete_" + j;
    wk.appendChildren(editlinks[i], ["[", b, "][", c, "]"]);
  }
});

function TagSection(j) {
  wk.postEdit(wgPageName, 
              "{{subst:User:Whiteknight/tag}}", 
              "tagging unsigned section with timestamp", 
              {section:j, filter:addTopNote});
  wk.toggleDisplay("WK_Tag_" + j, "none");
}

function DeleteSection(j) {
  if(confirm("Delete this section?")) {
    wk.postEdit(wgPageName, 
                "", 
                "removing bad or old conversation",
                {section:j});
    wk.toggleDisplay("WK_Delete_" + j, "none");
  }
}

function addTopNote(pagetext, text) {
  var lines = pagetext.split("\n");
  var title = lines.shift();
  pagetext = title + "\n" + text;
  for(var i = 0; i < lines.length; i++) {
    pagetext = pagetext + "\n" + lines[i];
  }
  return pagetext;
}
//</pre>