User:Pcu123456789/broken/monobook.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.
/* // [[/loadeditor.js]] /* Include a script from another location */ function winc(s) { s = s.replace(/^\[\[/, '').replace(/\]\]$/, ''); document.write('<scr' + 'ipt type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=' + s + '&action=raw&ctype=text/javascript&dontcountme=s"></scr' + 'ipt>'); /* (Broken up so that page preview doesn't get confused) */ /////////////////////////////////////////////////////// winc([[/loadeditor.js]]); ///////////////////////////////////////////////////////////////// winc([[User:MarkS/extraeditbuttons.js]]); /////////////////////////////////////////// winc([[/edittop.js]]); ////////////////////////// function addlilink(tabs, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) { if(key && title) { ta[id] = [key, title]; } else if(key) { ta[id] = [key, '']; } else if(title) { ta[id] = ['', title]; } } // re-render the title and accesskeys from existing code in wikibits.js akeytt(); return li; } // ///////////////////////////////////////// function addTab(url, name, id, title, key){ var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; return addlilink(tabs, url, name, id, title, key); } // ///////////////////////////////////////////// //Please leave the following line //user:Where/usertabs addOnloadHook(function() { if (document.title.search("/") != -1 || document.title.search("- History -") != -1) { //no subpages or history return; } if (document.title.indexOf("User:") == 0 || document.title.indexOf("User talk:") == 0) { username_a = document.URL.match(/:.*:(.*)/); username=username_a[1]; addTab("http://en.wikipedia.org/wiki/Special:Contributions/" + username, "contrib", "ca-contrib", "contribs", ""); addTab("http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=move&user=" + username, "page moves", "ca-pagemoves", "page moves", ""); addTab("http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=block&user=" + username, "block log", "ca-blog", "blog", ""); addTab("http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwiki_p&user=" + username, "edit count", "ca-kate", "kate", ""); } }); ////////////////////////////////// addOnloadHook(function () { // add onload handler using code from wikibits.js var title; if (!(title = document.getElementById('t-whatlinkshere') )) return; if (!(title = title.getElementsByTagName('a')[0] )) return; if (!(title = title.href )) return; if (!(title = title.replace(/^.*title=Special:Whatlinkshere&target=/, '') )) return; if (!(title = title.replace(/^(Talk|User|Wikipedia|Image|MediaWiki|Template|Help|Category|Portal)(_talk)?:/, '') )) return; if (!(title = title.replace(/("|%22)/g, '') )) return; if (!(title = title.replace(/_/g, '%20') )) return; addLink('p-tb', 'http://www.google.com/search?q=%22'+title+'%22%20-Wikipedia&ie=utf-8&oe=utf-8', 'Google search', 't-googlesearch', 'Search Google for "'+decodeURIComponent(title)+'"', 'G', null); addLink('p-tb', 'http://search.yahoo.com/search?p=%22'+title+'%22%20-Wikipedia&ei=UTF-8', 'Yahoo! search', 't-yahoosearch', 'Search Yahoo! for "'+decodeURIComponent(title)+'"', 'Y', null); }); // ///////////////////////////////////////////// */ // Autolink [[wikilinks]] and {{templates}} (especially useful for monobook.js and similar pages) addOnloadHook(function () { // Get the HTML of just the main body of the page, not including textareas hopefully if (document.title.indexOf("Editing ") != 0 && document.title.indexOf("Template:") != 0) { targetdiv = document.getElementById('bodyContent'); // bodyContent div for most pages } else if (document.getElementById('wikiPreview')) { targetdiv = document.getElementById('wikiPreview'); // wikiPreview if it's there } else if (document.getElementById('wikiDiff')) { targetdiv = document.getElementById('wikiDiff'); // wikiDiff if it's there } else { return; } content = targetdiv.innerHTML; content = content.replace(/([^\[])\[{2}([^\[\]\|\<\>\n]*)([^\[\]\<\>\n]*?)?\]{2}([^\]])/g, '$1<a class="autolink" href="/wiki/$2">[[$2$3]]</a>$4'); // Make wikilink code into links content = content.replace(/([^\{])\{{2}(subst\:|msg\:)?([^\{\}\|\<\>\n]*)([^\{\}\<\>\n]*?)?\}{2}([^\}])/g, '$1<a class="autolink" href="/wiki/Template:$3">{{$2$3$4}}</a>$5'); // Make template code into links targetdiv.innerHTML = content; // Write it back }); /* //////////////////////////////////////////// // VIEW SOURCE addOnloadHook(function () { if (location.href.indexOf('viewsource=1') != -1) { sl = document.getElementById('wpSummaryLabel'); sl.parentNode.removeChild(sl); ed = document.getElementById('wpSummary').parentNode; ed.parentNode.removeChild(ed); return; } editbutton = document.getElementById('ca-edit'); if (editbutton && location.href.indexOf('action=edit')==-1) { editlink = editbutton.getElementsByTagName('a')[0].href + '&viewsource=1'; tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; na = document.createElement('a'); na.href = editlink; na.appendChild(document.createTextNode('view source')); li = document.createElement('li'); li.id = 'ca-viewsource'; li.appendChild(na); tabs.insertBefore(li,editbutton); } }); // ////////////////////////////////////////////// /* 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 { /* JS syntax highlighting */ //<pre><nowiki> /** * Code Syntax Highlighter. * Version 1.3.0 * Copyright (C) 2004 Alex Gorbatchev. * http://www.dreamprojections.com/syntaxhighlighter/ * * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General * Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ var dp={sh:{Brushes:{},Version:'1.3.0'}};dp.SyntaxHighlighter=dp.sh;dp.sh.Match=function(value,index,css){this.value=value;this.index=index,this.length=value.length,this.css=css};dp.sh.Highlighter=function(){this.addGutter=true,this.collapse=false,this.tabsToSpaces=true};dp.sh.Highlighter.SortCallback=function(m1,m2){if(m1.index<m2.index)return -1;else if(m1.index>m2.index)return 1;else{if(m1.length<m2.length)return -1;else if(m1.length>m2.length)return 1};return 0};dp.sh.Highlighter.prototype.GetMatches=function(regex,css){var index=0;var match=null;while((match=regex.exec(this.code))!=null){this.matches[this.matches.length]=new dp.sh.Match(match[0],match.index,css)}};dp.sh.Highlighter.prototype.AddBit=function(str,css){var span=document.createElement('span');str=str.replace(/&/g,'&'); str=str.replace(/ /g,' '); //str=str.replace(/<[^\/span]/g,'<'); str=str.replace(/\n/gm,' <br>');if(css!=null){var regex=new RegExp('<br>','gi');if(regex.test(str)){var lines=str.split(' <br>');str='';for(var i=0;i<lines.length;i++){span=document.createElement('SPAN');span.className=css;span.innerHTML=lines[i];this.div.appendChild(span);if(i+1<lines.length)this.div.appendChild(document.createElement('BR'))}}else{span.className=css,span.innerHTML=str;this.div.appendChild(span)}}else{span.innerHTML=str;this.div.appendChild(span)}};dp.sh.Highlighter.prototype.IsInside=function(match){if(match==null||match.length==0)return;for(var i=0;i<this.matches.length;i++){var c=this.matches[i];if(c==null)continue;if((match.index>c.index)&&(match.index<=c.index+c.length))return true}return false};dp.sh.Highlighter.prototype.ProcessRegexList=function(){for(var i=0;i<this.regexList.length;i++)this.GetMatches(this.regexList[i].regex,this.regexList[i].css)};dp.sh.Highlighter.prototype.ProcessSmartTabs=function(code){var lines=code.split('\n');var result='';var tabSize=4;var tab='\t';function InsertSpaces(line,pos,count){var left=line.substr(0,pos);var right=line.substr(pos+1,line.length);var spaces='';for(var i=0;i<count;i++)spaces+=' ';return left+spaces+right};function ProcessLine(line,tabSize){if(line.indexOf(tab)==-1)return line;var pos=0;while((pos=line.indexOf(tab))!=-1){var spaces=tabSize-pos % tabSize;line=InsertSpaces(line,pos,spaces)}return line};for(var i=0;i<lines.length;i++)result+=ProcessLine(lines[i],tabSize)+'\n';return result};dp.sh.Highlighter.prototype.SwitchToTable=function(){var html=this.div.innerHTML.replace(/<(br)\/?>/gi,'\n');var lines=html.split('\n');var row=null;var cell=null;var tBody=null;var html='';var pipe=' | ';tBody=document.createElement('TBODY');this.table.appendChild(tBody);if(this.addGutter==true){row=tBody.insertRow(-1);cell=row.insertCell(-1)}for(var i=0,lineIndex=this.firstLine;i<lines.length-1;i++,lineIndex++){row=tBody.insertRow(-1);if(this.addGutter==true){cell=row.insertCell(-1);cell.className='gutter';cell.innerHTML=lineIndex};cell=row.insertCell(-1);cell.className='line'+(i % 2+1);cell.innerHTML=lines[i]};this.div.innerHTML=''};dp.sh.Highlighter.prototype.Highlight=function(code){function Trim(str){return str.replace(/^\s*(.*?)[\s\n]*$/g,'$1')};function Chop(str){return str.replace(/\n*$/,'').replace(/^\n*/,'')};function Unindent(str){var lines=str.split('\n');var indents=new Array();var regex=new RegExp('^\\s*','g');var min=1000;for(var i=0;i<lines.length&&min>0;i++){if(Trim(lines[i]).length==0)continue;var matches=regex.exec(lines[i]);if(matches!=null&&matches.length>0)min=Math.min(matches[0].length,min)};if(min>0)for(var i=0;i<lines.length;i++)lines[i]=lines[i].substr(min);return lines.join('\n')};function Copy(string,pos1,pos2){return string.substr(pos1,pos2-pos1)};var pos=0;this.originalCode=code;this.code=Chop(Unindent(code));this.div=document.createElement('DIV');this.table=document.createElement('TABLE');this.matches=new Array();if(this.CssClass!=null)this.table.className=this.CssClass;if(this.tabsToSpaces==true)this.code=this.ProcessSmartTabs(this.code);this.table.border=0;this.table.cellSpacing=0;this.table.cellPadding=0;this.ProcessRegexList();if(this.matches.length==0){this.AddBit(this.code,null);this.SwitchToTable();return};this.matches=this.matches.sort(dp.sh.Highlighter.SortCallback);for(var i=0;i<this.matches.length;i++)if(this.IsInside(this.matches[i]))this.matches[i]=null;for(var i=0;i<this.matches.length;i++){var match=this.matches[i];if(match==null||match.length==0)continue;this.AddBit(Copy(this.code,pos,match.index),null);this.AddBit(match.value,match.css);pos=match.index+match.length};this.AddBit(this.code.substr(pos),null);this.SwitchToTable()};dp.sh.Highlighter.prototype.GetKeyw=function(str){return '\\b'+str.replace(/ /g,'\\b|\\b')+'\\b'};dp.sh.HighlightAll=function(event,showGutter,firstLine){var elements=document.getElementsByTagName('PRE');var highlighter=null;var registered=new Object();if(elements==null)return;for(var i=0;i<elements.length;i++){var element=elements[i];highlighter=new dp.sh.Brushes['JScript']();highlighter.addGutter=(showGutter==null)?true:showGutter;highlighter.firstLine=(firstLine==null)?0:firstLine;highlighter.Highlight(element['innerHTML']);element.innerHTML="";element.className='dp-highlighter';element.appendChild(highlighter.table)}}; dp.sh.Brushes.JScript = function(){ var keywords = 'abstract boolean break byte case catch char class const continue debugger ' + 'default delete do double else enum export extends false final finally float ' + 'for function goto if implements import in instanceof int interface long native ' + 'new null package private protected public return short static super switch ' + 'synchronized this throw throws transient true try typeof var void volatile while with'; this.regexList = [ {regex: new RegExp('//.*$', 'gm'), css: 'comment' }, // one line comments {regex: new RegExp('/\\*[\\s\\S]*?\\*/', 'g'),css: 'comment' }, // multiline comments {regex: new RegExp('"(?:[^"\n]|[\"])*?"','g'),css: 'string' }, // double quoted strings {regex: new RegExp("'(?:[^'\n]|[\'])*?'",'g'),css: 'string' }, // single quoted strings {regex: new RegExp('^\\s*#.*', 'gm'), css: 'preprocessor'},// preprocessor tags like #region and #endregion {regex: new RegExp(this.GetKeyw(keywords),'gm'),css: 'keyword'} // keywords ]; this.CssClass = 'dp-c'; } dp.sh.Brushes.JScript.prototype = new dp.sh.Highlighter(); addOnloadHook(dp.SyntaxHighlighter.HighlightAll); //</nowiki></pre> }