Jump to content

User:Arjayay/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Arjayay (talk | contribs) at 07:43, 14 May 2009 (add Sympletic Map/spell.js). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
// To install, include this script in your monobook.js and clear your cache
// You should see a 'spell' tab next to the watch/unwatch tab.
//
// The script interface created by copying/modifying [[WP:AutoEd]]
//
// USE WITH CAUTION and CHECK THE EDIT CHANGES
// REPORT BUGS TO [[User talk:Symplectic Map]]
//
if( typeof( SM_minor ) == 'undefined' ) {
  var SM_minor = true;
}
 
if( typeof( SM_click ) == 'undefined' ) {
  var SM_click = true;
}
 
if( typeof( SM_tag ) == 'undefined' ) {
  var SM_tag = "[[WP:LCM|Common misspellings]] corrected by [[User:Symplectic_Map/spell.js|script]]";
}
 
if( typeof( SM_hover ) == 'undefined' ) {
  var SM_hover = "Spellcheck";
}
 
if( typeof( SM_name ) == 'undefined' ) {
  var SM_name = "spell";
}
 
if( typeof( SM_loc ) == 'undefined' ) {
  var SM_loc = "p-cactions";
}
 
importScript('User:Symplectic_Map/misspellings.js');
importScript('User:Symplectic_Map/capitalizations.js');
importScript('User:Symplectic_Map/script.js');
 
function SM_edit() {
    var txt = document.editform.wpTextbox1;
    txt.value = common_misspellings(txt.value);
    txt.value = common_capitalizations(txt.value);
}
 
function SM_exec() {
  if(!document.getElementById('wpTextbox1')) return;
  SM_edit();
  SM_summary();
}
 
//Tags summary textbox
function SM_summary() {
  var txt = document.editform.wpSummary;
  var tag = SM_tag;
 
  // Is the tag blank?
  if( tag.match(/[^\s]/) ) {
    // Has it already been tagged?
    if( txt.value.indexOf(tag) == -1 ) {
    // Append a pipe if necessary
    if( txt.value.match(/[^\*\/\s][^\/\s]?\s*$/) ) {
      txt.value += " | ";
    }
    // Append our tag
    txt.value += tag;
    }
  }
  // Check 'This is a minor edit'
  if( SM_minor ) {
    document.editform.wpMinoredit.checked = SM_minor;
  }
  // Click 'Show changes'
  if( SM_click ) {
    document.editform.wpDiff.click();
  }
}
 
//Allows URI to be properly decoded when run from View Mode 
function SM_QueryString(p) {
  var re = RegExp('[&?]' + p + '=([^&]*)');
  var matches;
  if (matches = re.exec(document.location)) {
    try {
      return decodeURI(matches[1]);
    } catch (e) {
    }
  }
  return null;
}
 
 
//Execute after call from View Mode
if( SM_QueryString('SM_spell') ) {
  addOnloadHook(function() { 
    SM_exec();
  });
}
 
// Add tabs and associate with actions
addOnloadHook(function () {
  if(wgCanonicalNamespace == "" || wgCanonicalNamespace == "Image" 
   ||  wgCanonicalNamespace == "File" || wgCanonicalNamespace == "Template" 
   || wgCanonicalNamespace == "Project" || wgCanonicalNamespace == "Portal") {
    if(document.forms.editform) {
      addPortletLink( SM_loc, 'javascript:SM_exec()', SM_name, 'ca-SM', SM_hover, '', document.getElementById('ca-move'));
    } //End editform if
    if(wgAction == "view"){
      var url = wgServer + wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=edit';
      addPortletLink( SM_loc, url + '&SM_spell=true', SM_name, 'ca-SM', SM_hover, '', document.getElementById('ca-move'));
    } //End pageview if
  } //End namespace if
});