User:Pecoes/global.js

$(function {    talkNameSpaces = [1,3,5,7,9,11,13,15,110,111,114,401,500,501,502,503];    if (-1 < $.inArray(wgNamespaceNumber, talkNameSpaces) && 'edit' == $.getUrlVar('action')) {        window.Sine = function  {            var my = {                add: function  {                    if ($('input#wpMinoredit').is(':checked')) return;                    switch (editorInstance.mode) {                        case 'wysiwyg':                            sineWYSIWYG;                            break;                        case 'source':                            sineSource;                            break;                    }                }            };            function sine  { return '' + String.fromCharCode(126) + '~' };            function sineWYSIWYG  {                var wysiwyg = editorInstance.getEditbox;                var block = wysiwyg.find('> *:last')                console.log(wysiwyg.find('> *')); if (!block.length) return; if (block.is('p')) { if (insertSine(block)) return; }               else if (block.is('dl')) { if (insertSine(block.find('dd:last-child'))) return; }               console.log(' '); var prevBlock = block; while (prevBlock.prev.length) { if (prevBlock.is('p,dl')) break; prevBlock = prevBlock.prev; }               var s = sine; if (prevBlock.is('p')) { console.log('p indent: '); console.log(prevBlock.css('marginLeft')); s = $(' ' + s + ' ').css({                        marginLeft: prevBlock.css('marginLeft')                    }); } else if (prevBlock.is('dl')) { console.log('prev:dl'); var indent = prevBlock.find('dd').length; console.log('dd indent: '); console.log(indent); for (var i = 0; i < indent; i++) { s = '' + s + ''; }               } else { console.log('prev:other'); s = ' ' + s + ' '; }               wysiwyg.append(s); }           function insertSine (block) { var sub = block.contents; if (!sub.length) return false; console.log('insertSine'); console.log(sub); for (var i = sub.length-1; i >= 0; i--) { console.log(sub[i]); console.log(sub[i].nodeType); console.log(sub[i].nodeName); if (3 == sub[i].nodeType && sub[i].nodeValue.trim.length) { if (sine != sub[i].nodeValue.trim.substr(-4)) { $(sub[i]).after(' -- ' + sine); }                       return true; }                   if ($(sub[i]).is('br')) continue; if ('block' != $(sub[i]).css('display')) { $(sub[i]).after(' -- ' + sine); return true; }                   break; }               if (1 == sub.length && $(sub[0]).is('br')) { if (block.prev.length && sine == block.prev.text.trim.substr(-4)) return true; block.prepend(sine); return true; }               return false; }           function sineSource  { var source = editorInstance.getContent; if (!source.trim.length) return; var lines = source.split(/\r\n|\r|\n/).reverse; var l = lines[0].trim; var s;               if (l.length) { if (sine == l.substr(-4)) return; var isBlock = /^\:*[*#]/.test(l) || /^(={2,6})[^=]+\1$/.test(l) || /(?:|}}|<\/(?:blockquote|div|pre|code|nowiki)>)$/.test(l); s = (isBlock ? "\r\n" : " -- ") + sine; } else { for (var i = 1; i < lines.length; i++) { l = lines[i].trim; if (!l.length) continue; if (sine == l.substr(-4)) return; m = l.match(/^(\:+)/); if (m) s = m[1] + sine; break; }               }                editorInstance.setContent(source + s); }           return my; };       window.initSine = function  { if (typeof window.editorInstance == 'undefined') { console.log('waiting'); window.setTimeout(                   function  {                        window.initSine;                    }, 100                ) return; }           console.log('adding events'); $('input#wpSave').click(function (event) {               Sine.add;                console.log(editorInstance.getEditbox.find('> *:last'));                event.preventDefault;            }); $('a#publish').click(function (event) {               Sine.add;                console.log(editorInstance.getEditbox.find('> *:last'));                event.preventDefault;            }); }       window.initSine; } });

importScriptPage('PurgeButton/code.js', 'dev' );

var menu = [ ['JE Modding', 'http://jadeempire-modding.wikia.com/', ['Admin Dashboard', 'http://jadeempire-modding.wikia.com/wiki/Special:AdminDashboard'], ['Sandbox', 'http://jadeempire-modding.wikia.com/wiki/User:Pecoes/Sandbox'], ['Wikia.css', 'http://jadeempire-modding.wikia.com/wiki/MediaWiki:Wikia.css'], ['Common.js', 'http://jadeempire-modding.wikia.com/wiki/MediaWiki:Common.js'] ],   ['Community Central', 'http://community.wikia.com/', ['Admin Forum', 'http://community.wikia.com/wiki/Admin_Central:Forum'], ['Community Forum', 'http://community.wikia.com/wiki/Forum:Community_Central_Forum'], ['Global.js',, 'http://community.wikia.com/wiki/User:Pecoes/global.js'], ],   ['Dev', 'http://dev.wikia.com/', ['Cheatsheet', 'http://dev.wikia.com/wiki/JS_and_CSS_Cheatsheet'], ['JavaScript', 'http://dev.wikia.com/wiki/List_of_JavaScript_Enhancements'] ],   ['API', 'http://jadeempire-modding.wikia.com/api.php'] ];

function renderMenu (menu) { if (undefined == window.wgUserName) return ''; var html = ''; html += ''; html += ''; html += ''; if (undefined != menu && menu instanceof Array) { html += ''; for (var i = 0; i < menu.length; i++) { html += renderMenuLevelOne(menu[i]); }       html += ""; }   html += ''; return html; }

function renderMenuLevelOne (menu) { if (undefined == menu || !(menu instanceof Array)) return ' '; var url, title, html; title = typeof menu[0] == 'string' ? menu[0] : 'undefined'; url  = typeof menu[1] == 'string' ? menu[1] : 'undefined'; html = ''; html += '' + title; if (menu.length > 2) { html += ''; html += ''; html += ''; for (var i = 2; i < menu.length; i++) { html += renderMenuLevelTwo(menu[i]); }       html += "</ul>"; }   else html += '</a>'; html += '</li>'; return html; }

function renderMenuLevelTwo (menu) { var url, title, html; title = typeof menu[0] == 'string' ? menu[0] : 'undefined'; url  = typeof menu[1] == 'string' ? menu[1] : 'undefined'; html = '<a class="subnav-3a" href="' + url + '">' + title + '</a></li>'; return html; }

$('#WikiHeader nav ul:first').append(renderMenu(menu)); $('#WikiHeader > nav').css({ width: "580" }); var navWidth = 0;

$(function {

// adjust size of main navigation to make room for bookmark menu: var navWidth = 0; $('#WikiHeader > nav > ul > li').each(function { navWidth += $(this).width; }); if (560 < navWidth) $('#WikiHeader > nav > ul > li > a').css({ paddingLeft: "11px", paddingRight: "11px" });

// see w:c:dev:Fix_for_Special:WantedImages if ("Special" == wgCanonicalNamespace && "WantedFiles" == wgCanonicalSpecialPageName) { $('ol.special a.new').each(function {           var m = $(this).attr('href').match(/title=File:([^&]+)/);            if (m) {                $(this).attr({ href: '/wiki/Special:Upload?wpDestFile=' + m[1], title: 'Upload ' + m[1] });           }        });    } });