User:RazoreRobin/cologneblue.js

Source: Wikipedia, the free encyclopedia.
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.
//This is just a useful little function.
function importPage(site){
  document.write('<script type="text/javascript" src="/w/index.php?title='
 + site + '&action=raw&ctype=text/javascript&dontcountme=s"><\/script>');
}

//Import two prerequisites for some scripts.
importPage('Wikipedia:WikiProject User scripts/Scripts/addLink');
importPage('Wikipedia:WikiProject User scripts/Scripts/addTab');

//add in cacyle's editor
// include comfortable javascript editor by cacycle
// levels of undo (each level holds the whole text)
undoBufferMax = 20;
// style for preview box
stylePreviewBox = 'background-color: #f9f9f9;';
// style for custom edit buttons
styleButtons = 'font-size: smaller; padding-left: 0.1em; padding-right: 0.1em';
// presets for input field dropdown options
findHistoryLength = 10;
// preset for combo box select options
presetOptions = [];
presetOptions['summary'] = [
  'Copyedit',
  'Linkfix',
  'Reverting vandalism',
  'Formatting source text'
];
// expiration time span for history cookies in seconds
cookieExpireSec = (365 * 24 * 60 * 60);
// enable cursor horizontal position memory
cursorMemory = true;
// show at least this number of lines ahead of cursor movement
scrollMargin = 1;
// show at least this number of lines ahead of cursor movement for
findMargin = 2;
// find ahead checkbox selected by default
findAheadSelected = true;
// css for change indicators
styleDelete = 'font-weight: normal; text-decoration: none; color: #ffffff; background-color: #990033;';
styleInsert = 'font-weight: normal; text-decoration: none; color: #ffffff; background-color: #009933;';
styleMoved  = 'font-weight: bold; vertical-align: text-bottom; font-size: xx-small; padding: 0; border: solid 1px;';
styleBlock  = [
        'background-color: #ffff44;',
        'background-color: #b0ff90;',
        'background-color: #ffcc99;',
        'background-color: #99ffff;',
        'background-color: #99ccff;',
        'background-color: #cc99ff;',
        'background-color: #ff99cc;',
        'background-color: #ffd040;',
        'background-color: #d0d0d0;'
];
// html for change indicators, {number} is replaced by the block number, {block} is replaced by the block style
htmlMovedRight  = '<input type="button" value=">" style="' + styleMoved + ' {block}">';
htmlMovedLeft   = '<input type="button" value="<" style="' + styleMoved + ' {block}">';
htmlBlockStart  = '<span style="{block}">';
htmlBlockEnd    = '</span>';
htmlDeleteStart = '<span style="' + styleDelete + '">';
htmlDeleteEnd   = '</span>';
htmlInsertStart = '<span style="' + styleInsert + '">';
htmlInsertEnd   = '</span>';
// minimal number of real words for a moved block (0 for always displaying block move indicators)
blockMinLength = 3;
// exclude identical sequence starts and endings from change marking
wordDiff = true;
// enable recursive diff to resolve problematic sequences
recursiveDiff = true;
// enable block move display
showBlockMoves = true;
// install User:Cacycle/diff text diff code
document.write('<script type="text/javascript" src="' 
  + 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/diff.js' 
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
// install [[User:Pilaf/Live_Preview]] page preview tool
document.write('<script type="text/javascript" src="' 
  + 'http://en.wikipedia.org/w/index.php?title=User:Pilaf/livepreview.js' 
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
// install [[User:Cacycle/editor]] edit tool
document.write('<script type="text/javascript" src="' 
  + 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/editor.js' 
  + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

function getAnchors() {
  var s=[''], anchs=document.getElementsByTagName('A');
  for (var i=0; i<anchs.length; ++i) if (anchs[i].name && anchs[i].name!='top') 
    s.push(anchs[i].name);
  return s;
}
window.handleKeys=function(evt){
  if (window.handleKeys.disabled) { 
    return true; 
  }
  var k = window.event ? window.event.keyCode : ( evt.keyCode ? evt.keyCode : evt.which);
  if (!k) return;
  var letter=String.fromCharCode(k);
  switch (letter) {
    case 'j': changeAnchor(1);       return false; 
    case 'J': changeAnchor('last');  return false;
    case 'k': changeAnchor(-1);      return false;
    case 'K': changeAnchor('first'); return false;
    default: return true;
  }
}
window.handleKeys.disabled=false;
window.handleKeys.disableFlags=[];
function setupFocusHandlers(elType, startAt) {
  var inputs=document.getElementsByTagName(elType);
  var j=startAt || 0;
  for (var i=0; i<inputs.length; ++i) {
    if (elType=='input' && inputs[i].type.toLowerCase()!='text') { continue; }
    window.handleKeys.disableFlags[j]=false;
    inputs[i].onfocus=function(){ window.handleKeys.disableFlags[j]=true; updateDisabledFlag(); }
    inputs[i].onblur=function(){ window.handleKeys.disableFlags[j]=false; updateDisabledFlag(); }
    ++j;
  }
  //alert(j + ' handlers installed');
  return j;
}
function updateDisabledFlag() {
  for (var i=0; i<window.handleKeys.disableFlags.length; ++i) {
    if (window.handleKeys.disableFlags[i]===true) { 
      window.handleKeys.disabled=true; 
      return true; 
    }
  }
  window.handleKeys.disabled=false;
  return false;
}
var anchs, pos;
window.changeAnchor=function(step, loop) {
  if(!anchs && !(anchs=getAnchors()) ) return;
  var loc=document.location.toString().split('#');
  switch (step) {
    case 'first': pos=0; break;
    case 'last':  pos=anchs.length-1; break;
    default:
      if (loc.length > 0) {
        var target=loc.slice(1).join('#');
        for (var i=0; i<anchs.length; ++i) { if (anchs[i]==target) { pos=i; break; } }
      }
      if(typeof pos==='number') { 
        pos += step; 
        if (loop) { while(pos < 0) pos += anchs.length; pos %= anchs.length; }
        else { if (pos<0) pos=0; if(pos>=anchs.length) pos=anchs.length-1; }
      }
      else pos = 0;
  } /* switch */
  var newloc=loc[0] + '#' + anchs[pos];
  if(document.location!=newloc)  document.location=newloc;
}  
var sectionKeysPage=( ! /^(Editing|Search -|Confirm|Move page|Logs|E-mail user|All pages|Block user)/.test(document.title) 
 && 
 ! /([?&]=|wiki\/)[Ss]pecial:/.test(document.location) );
if (sectionKeysPage) {
  addOnloadHook(function(){
      var j=setupFocusHandlers('input');
      setupFocusHandlers('textarea', j);
      document.onkeypress=window.handleKeys;
    });
}


// CHECK THAT I'VE REMEMBERED TO SIGN TALK PAGES AND IF SURE DO IT AUTOMATIC:
// *** aut. signing / (automatische Unterschrift) *** 23. Apr. 2006 by [[User:Olliminatore]]
// updated by [[:en:User:Ilmari Karonen]] v1.43
//<pre><nowiki>
// helper-function
String.prototype.trim = function(){return this.replace(/^\s*|\s*$/g,"")};
addOnloadHook(function () {
  if(!document.editform) return;
  title = document.title; // Object to String
  // regarded pages
  regpages=new Array('talk:', 'Talk:', ':Village pump', ':Articles for deletion', ':Requests for adminship', ':Current surveys');
  for (p in regpages)
    if(title.indexOf(regpages[p])!=-1){
      regpages=false;
      break
    }
  if(regpages) return;
  var txtObj=document.editform.wpTextbox1;
  var txtOld=txtObj.value.trim();
  txtOld_l=txtOld.length
  var txtOldEnd=txtOld.slice(-24);

  function doSign(){
    if(document.editform.onsubmit==''){ // only once!
      removeEvent(document.editform.wpSave,"click",doSign);
      removeEvent(document.editform.wpPreview,"click",doSign);
    }
    if(document.editform.wpMinoredit.checked) return true;
    signing = ' --\&nbsp;~\~\~ <small>~\~\~\~\~<\/small>\n';
    if(!txtObj.value.match(/~{3}/)){
      txt=txtObj.value.trim();
      txtEnd=txt.slice(-24);
      if(txtOldEnd!=txtEnd) return txtObj.value = txt + signing;  // aut. underwrite
      else { // post between
       pos = getCaretPos(txtObj);
       pos = txt.indexOf('\n', pos); // go to the post-end
       txtEnds = txt.substr(pos,24).replace(/^\s*/,""); // after
       txtpEnds = txt.slice(pos-18,pos); // before
       olldp = txtOld.indexOf(txtEnds);
       if(olldp!=-1 && olldp < pos - 3 && txtOld.search(txtpEnds+txtEnds)==-1) // if some added
         return txtObj.value = txt.slice(0,pos).trim() + signing + txt.slice(pos+1);
      }
     // FIXME: the edit-end is not found
    }
    else if(txtOld.search(/~{3}/)==-1 || !txtOld.match(/<nowiki>.*?~{3}.*?<\/nowiki>/i)) return 1;
    else if(txtOld.match(/~{3}/g).length < txtObj.value.match(/~{3}/g).length) return 1;
    return document.editform.onsubmit=new Function("document.editform.onsubmit='';return confirm('No signing was found. Save anyway?')");
  };
  addEvent(document.editform.wpSave,"click", doSign)
  addEvent(document.editform.wpPreview,"click", doSign)
});
function getCaretPos(txtObj) {
  if(txtObj.setSelectionRange) return txtObj.selectionStart; // NS like
  else if(!document.selection) return 0;  // not IE like
  txtObj.focus();
  var c="\001", pos=0;
  var range=document.selection.createRange();
  var txt=range.text, dul=range.duplicate();
  dul.moveToElementText(txtObj);
  range.text=txt+c;
  pos=(dul.text.indexOf(c));
  range.moveStart('character',-1);
  range.text="";
  return pos;
};
/* add/removeEvent Original idea by John Resig
 Tweaked by Scott Andrew LePera, Dean Edwards and Peter-Paul Koch
 Fixed for IE by Tino Zijdel (crisp) @date 2005-10 */
function addEvent(obj,type,fn){if(obj.addEventListener){obj.addEventListener(type,fn,false)}else if(obj.attachEvent){var eProp=type+fn;obj["e"+eProp]=fn;obj[eProp]=function(){obj["e"+eProp](window.event)};obj.attachEvent("on"+type,obj[eProp])}else{obj['on'+type]=fn}};
function removeEvent(obj,type,fn){if(obj.removeEventListener){obj.removeEventListener(type,fn,false)}else if(obj.detachEvent){var eProp=type+fn;obj.detachEvent("on"+type,obj[eProp]);obj['e'+eProp]=null;obj[eProp]=null}else{obj['on'+type]=null}};

//*** end ***
//</nowiki></pre>
// Interwiki <noinclude>[[de:Benutzer:Olliminatore/Signatur.js]]</noinclude>


//User:Lupin/popups.js
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'
);
popupShortcutKeys=true; // optional: enable keyboard shortcuts
popupAdminLinks=true;   // optional: enable admin links
popupDelay=.7;
popupFixRedits=true;
popupInitialWidth=200;
popupFixRedirs=true;
popupFixDabs=true;
popupLastModified=true;
popupMaxPreviewSentences=1;
popupImages=false;
popupSubpopups=true;
popupWatchRedirredPages=false;
popupRedirAutoClick='wpSave';
popupRedlinkRemoval=true;
popupLastModified=true;
popupDiffDates=true;
popupOnlyArticleLinks=true;
imagePopupsForImages=false;
//popupEditCounterTool="kate";
popupStructure='fancy2';


/* This script adds scroll bars to wide diffs such as [1]. It replaces the table-based diff layout with a CSS-based layout where the column width is always exactly 50%. Known to work in Firefox, Konqueror, Opera and at least some versions of Internet Explorer. This script is a workaround for Bug 1229. If you have any problems with this script, please let me know. */
importPage('Wikipedia:WikiProject_User_scripts/Scripts/Fix_diff_width');


//Formats the article by removing excess whitespace and simplifying links.
importPage('Wikipedia:WikiProject User scripts/Scripts/Formatter');


//Sam Hocevar's "ubergod-mode.js", doesn't seem to be doing any harm, so why not.
document.write('<SCRIPT SRC="http://sam.zoy.org/wikipedia/ubergodmode.js"><\/SCRIPT>');


/* Syntax highlighter */
if(document.title.indexOf(".js") == -1)     //   Ignore pages that end in .js
 addOnloadHook(function () {
  /* CSS syntax highlighting */
    multicommentRE = new RegExp('(/\\*[\\s\\S]*?\\*/)', 'g');
    ruleRE = new RegExp('([^\\{]+)\\{([^\\}]+)\\}', 'g');
    idselectorRE = new RegExp('(#[a-zA-Z0-9\-\_]+)\\b', 'g');
    classselectorRE = new RegExp('(\\.[a-zA-Z0-9\-\_]+)\\b', 'g');
    pairRE = new RegExp('([a-zA-Z-]+):([^;]+);', 'g');
    css = document.getElementsByTagName('pre');
    for (i = 0; i < css.length; i++) {
      c = css[i];
      content = c.innerHTML;
      content=content.replace(multicommentRE, '<span class="comment">$1</span>');
      content = content.replace(ruleRE, function(text, selector, body) {
        selector = selector.replace(idselectorRE, '<span class="idselector">$1</span>');
        selector = selector.replace(classselectorRE, '<span class="classselector">$1</span>');
        body = body.replace(pairRE, '<span class="property">$1</span>:<span class="value">$2</span>;');
        return selector + '{' + body + '}';
      });
      c.innerHTML = content;
    }
 });
else  /* Extreme Syntax highlighter (js)*/
 importPage('User:Olliminatore/shCore.js');  // [[User:Olliminatore/shCore.js]]

//This simplifies the sidebar to read "Edit" instead of "Edit this page". 
importPage('User:Ilmari Karonen/cologneblue/shorteditlinks.js');