User:Steptrip/Miscellaneous

From Wikipedia, the free encyclopedia

//

// Fix wikipedia's lowercase first letter problem // Fix the lowercase first letter problem by changing the page title to the correct one and hiding the template. // by pile0nades addOnloadHook(function (){


try {

var ch = get("//div[@id='bodyContent']/dl/dd/span[@class='plainlinks']/i[contains(.,'initial letter is capitalized')]/b").snapshotItem(0);
var correction = ch.innerHTML;
var articleTitle = get("//div[@id='content']/h1[@class='firstHeading']").snapshotItem(0);
var template = ch.parentNode.parentNode.parentNode;
// check if the original and correct versions match
// this avoids acting on non-"real" uses of the template
if(articleTitle.innerHTML.toLowerCase() == correction.toLowerCase()) {
  // Correct the page title
  document.title = document.title.replace(articleTitle.innerHTML, correction);

  // Correct the article title
  articleTitle.innerHTML = correction;

  // Remove template
  template.style.display = "none";
}

} catch(e){}

function get(query, context) {

return document.evaluate(
  query,
  document,
  null,
  XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  context
);

} });

//

// Script from User:Tra/sidebartranslate.js importScript('User:Tra/sidebartranslate.js'); //User:Tra/sidebartranslate.js

//

// addPurge addOnloadHook(function () {

  var hist; var url;
  if (!(hist = document.getElementById('ca-history') )) return;
  if (!(url = hist.getElementsByTagName('a')[0] )) return;
  if (!(url = url.href )) return;
  addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
                 'purge', 'ca-purge', 'Purge server cache for this page', 'p');

});

//

//

//Conflicts with force edit summary script!

var scIndex = 0; var scKeys = new Array(); var scValues = new Array();

function scFormSubmit() {

  var i=0
  var textArea = document.getElementById("wpTextbox1");
  var text = textArea.value;
  while (i<scIndex) {
     text = text.replace(scKeys[i], scValues[i]);
     ++i;
  }
  textArea.value = text;

}

addOnloadHook(function() {

  if (document.title.indexOf("Editing ") != 0) {return;}
  document.getElementById("wpSave").onclick = scFormSubmit;
  document.getElementById("wpPreview").onclick = scFormSubmit;
  document.getElementById("wpDiff").onclick = scFormSubmit;
  //TODO: make it work with previews too!

});


addOnloadHook(function() {

  if (document.title.indexOf("Editing ") != 0) {return;}
  var textArea = document.getElementById("wpTextbox1");
  var text = textArea.value;
  var re = /.*/g;
  var lastIndex = 0;

/* while (1) {

     var textSubstr = text.substr(lastIndex);
     alert(lastIndex);
     alert(textSubstr); //TODO: remove
     var newIndex = textSubstr.search(re);
     alert("newindex:" + newIndex);
     if (newIndex == -1) {

break;

     }
     lastIndex += newIndex+1;*/
     text = text.replace(re,

function(str, p1, p2, offset, s) { // alert("In replacement function"); if (p1 == p2) { var newString = "-" + p1 + ""; scKeys[scIndex] = newString; scValues[scIndex] = str; ++scIndex; return newString; } else { return str; } });

  //}
  textArea.value = text;

});