Jump to content

User:Symplectic Map/script.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Symplectic Map (talk | contribs) at 19:57, 28 May 2009 (one more). 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.
// lowercase first letter
function SM_lower(str) {
 if (str != "") {
  var x = str.search( /[a-z]/gi );
  if( x >= 0 ) {
   var let = str.slice(x,x+1);
   str = str.replace(let, let.toLowerCase());
  }
 }
 return str;
}

// uppercase first letter
function SM_upper(str) {
 if (str != "") {
  var x = str.search( /[a-z]/gi );
  if( x >= 0 ) {
   var let = str.slice(x,x+1);
   str = str.replace(let, let.toUpperCase());
  }
 }
 return str;
}

// Obfuscation using sic template
function SM_obfuscate(str) {
 if (str != "") {
  str = str.replace(/\(/g, '(?:');
  var x = str.search( /[a-z][a-z]/gi );
  if( x >= 0 ) {
   str = '('+ str.slice(0,x+1) +')('+ str.slice(x+1) +')';
  }
 }
 return str;
}

// special replace
function SM_replace(str, spair) {
 var r = "";
 var s = new RegExp("", "gm");
 var m = spair.match(/^(.*)\/(.*)$/);

 // obfuscate misspellings in file names
 var sfile = new RegExp("(\\[\\[(?:FILE|IMAGE)[^\\]\\|]*[^\\w\\/\\.])" + SM_obfuscate(m[1]) + "([^\\w\\/])", 'gim' );
 str = str.replace(sfile, '$1{{sic|$2|$3|hide=y}}$4');

 // case insensitive check
 var sgim = new RegExp("([^\\w\\/\\.])" + m[1] + "([^\\w\\/])","gim");
 if( str.search(sgim) >= 0 ) {
  // lowercase
  s.compile("([^\\w\\/\\.])" + SM_lower(m[1]) + "([^\\w\\/])","gm");
  r = SM_lower(m[2].replace(/\$1/g, '$2'));
  if( r.search( /\$2/g ) >= 0 ) {
   r = "$1" + r + "$3";
  } else {
   r = "$1" + r + "$2";
  }
  str = str.replace(s, r);
  // uppercase
  s.compile("([^\\w\\/\\.])" + SM_upper(m[1]) + "([^\\w\\/])","gm");
  r = SM_upper(r);
  str = str.replace(s, r);
 }

 return str;
}

// Foreign cite web
function SM_cita(str) {
  str = str.replace(/{{cita web/g, '{{cite web');
  str = str.replace(/({{cite web[^{}]*[^a-z{}])autor[ ]*=[ ]*/g, '$1author = ');
  str = str.replace(/({{cite web[^{}]*[^a-z{}])editor[ ]*=[ ]*/g, '$1publisher = ');
  str = str.replace(/({{cite web[^{}]*[^a-z{}])año[ ]*=[ ]*/g, '$1year = ');
  str = str.replace(/({{cite web[^{}]*[^a-z{}])título[ ]*=[ ]*/g, '$1title = ');
  str = str.replace(/({{cite web[^{}]*[^a-z{}])fechaacceso[ ]*=[ ]*/g, '$1accessdate = ');
  return str;
}