User:Whiteknight/per book/User talk:Whiteknight.js

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 wk_import_script(name) {
  name = encodeURIComponent(name.replace(/ /g, '_' ));
  var scriptElem = document.createElement('script');
  scriptElem.setAttribute('type', 'text/javascript');
  scriptElem.setAttribute('src',  '/w/index.php?title=' + name + '&action=raw&ctype=text/javascript');
  document.getElementsByTagName('head')[0].appendChild(scriptElem);
}

wk_import_script('User:Whiteknight/remotetalk.js');

if (mwCustomEditButtons) {
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile":  "http://upload.wikimedia.org/wikipedia/commons/3/3f/Button_attendre.png",
    "speedTip":   "Preserve",
    "tagOpen":    "{{subst:User:Whiteknight/keep}}",
    "tagClose":   "",
    "sampleText": ""
  };
}

$(function () {
  var editlinks = wk.getElementsByClass("editsection");
  for(var i = 0; i < editlinks.length; i++) {
    var j = i + 1
    var a = document.createElement("a");
    a.href = "javascript:KeepSection(" + j + ");";
    a.innerHTML = "keep";
    a.id = "WK_Keep_" + j;
    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], ["[", a, "][", b, "][", c, "]"]);
  }
});

function ReloadPage() {
  var currentUrl = unescape(window.location.pathname);
  if(typeof window.location.reload == "function") {
    window.location.reload(true);
  }
  else if(typeof window.location.replace == "function") {
    window.location.replace = currentUrl;
  }
  else {
    //warning: adds a new entry to page history.
    window.location.href = currentUrl;
  }
}

function KeepSection(j) {
  wk.postEdit(wgPageName, 
               "{{subst:User:Whiteknight/keep}}", 
               "marking section to avoid archival", 
               {section:j, filter:addTopNote, minor:"true", watch:true, callback:ReloadPage});
  wk.spanText("WK_Keep_" + j, "Loading...").href = "";
}

function TagSection(j) {
  wk.postEdit(wgPageName, 
               "{{subst:User:Whiteknight/tag}}", 
               "tagging with timestamp", 
               {section:j, filter:addTopNote, minor:"true", watch:true, callback:ReloadPage});
  wk.spanText("WK_Tag_" + j, "Loading...").href = "";
}

function DeleteSection(j) {
  if(confirm("Delete this section?")) {
    wk.postEdit(wgPageName, "", "removing conversation",
                 {section:j, minor:false, watch:true, callback:ReloadPage});
    wk.spanText("WK_Delete_" + j, "Loading...").href = "";
  }
}

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>