v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Difference between revisions of "User:Random832/monobook.js"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(first version (not adapted at all yet, but it won't run anyway until common.js gets fixed))
 
(display nicer)
 
Line 1: Line 1:
 +
/* <pre> */
 
document.attachEvent = function(){}
 
document.attachEvent = function(){}
 
window.attachEvent = function(){}
 
window.attachEvent = function(){}

Latest revision as of 21:05, 14 October 2008

/* <pre> */
document.attachEvent = function(){}
window.attachEvent = function(){}

// Experimental edittools {{{

// for common.js {{{

var edittoolsDefs = {
wikimarkup:[{start:'\{\{',end:'\}\}'}, {start:'\{\{\{',end:'\}\}\}'}, {start:'|',end:''}, {start:'[',end:']'}, {start:'\[\[',end:'\]\]'}, {start:'\[\[Category:',end:'\]\]'}, {start:'#REDIRECT \[\[',end:'\]\]'}, {start:'&nbsp;',end:''}, {start:'<s>',end:'</s>'}, {start:'<sup>',end:'</sup>'}, {start:'<sub>',end:'</sub>'}, {start:'<code>',end:'</code>'}, {start:'<blockquote>',end:'</blockquote>'}, {start:'<ref>',end:'</ref>'}, {start:'{{Reflist}}',end:''}, {start:'<references/>',end:''}, {start:'<includeonly>',end:'</includeonly>'}, {start:'<noinclude>',end:'</noinclude>'}, {start:'{{DEFAULTSORT:',end:'}}'}, {start:'<nowiki>',end:'</nowiki>'}, {start:'<!-- ',end:' -->'}, {start:'<span class="plainlinks">',end:'</span>'}],
symbols: "~|¡¿†‡↔↑↓•¶ #¹²³½⅓⅔¼¾⅛⅜⅝⅞∞ ‘“’”«» ¤₳฿₵¢₡₢$₫₯€₠₣ƒ₴₭₤ℳ₥₦№₧₰£៛₨₪৳₮₩¥ ♠♣♥♦",
characters: "ÁáĆćÉéÍíĹĺŃńÓóŔশÚúÝýŹź ÀàÈèÌìÒòÙù ÂâĈĉÊêĜĝĤĥÎîĴĵÔôŜŝÛûŴŵŶŷ ÄäËëÏïÖöÜüŸÿ ß ÃãẼẽĨĩÑñÕõŨũỸỹ ÇçĢģĶķĻļŅņŖŗŞşŢţ Đđ Ůů ǍǎČčĎďĚěǏǐĽľŇňǑǒŘřŠšŤťǓǔŽž ĀāĒēĪīŌōŪūȲȳǢǣ ǖǘǚǜ ĂăĔĕĞğĬĭŎŏŬŭ ĊċĖėĠġİıŻż ĄąĘęĮįǪǫŲų ḌḍḤḥḶḷḸḹṂṃṆṇṚṛṜṝṢṣṬṭ Łł ŐőŰű Ŀŀ Ħħ ÐðÞþ Œœ ÆæØøÅå Əə",
greek: "ΆάΈέΉήΊίΌόΎύΏώ ΑαΒβΓγΔδ ΕεΖζΗηΘθ ΙιΚκΛλΜμ ΝνΞξΟοΠπ ΡρΣσςΤτΥυ ΦφΧχΨψΩω",
cyrillic: "АаБбВвГг ҐґЃѓДдЂђ ЕеЁёЄєЖж ЗзЅѕИиІі ЇїЙйЈјКк ЌќЛлЉљМм НнЊњОоПп РрСсТтЋћ УуЎўФфХх ЦцЧчЏџШш ЩщЪъЫыЬь ЭэЮюЯя",
ipa: ['t̪','d̪','ʈ','ɖ','ɟ','ɡ','ɢ','ʡ','ʔ',' ','ɸ','ʃ','ʒ','ɕ','ʑ','ʂ','ʐ','ʝ','ɣ','ʁ','ʕ','ʜ','ʢ','ɦ',' ','ɱ','ɳ','ɲ','ŋ','ɴ',' ','ʋ','ɹ','ɻ','ɰ',' ','ʙ','ʀ','ɾ','ɽ',' ','ɫ','ɬ','ɮ','ɺ','ɭ','ʎ','ʟ',' ','ɥ','ʍ','ɧ',' ','ɓ','ɗ','ʄ','ɠ','ʛ',' ','ʘ','ǀ','ǃ','ǂ','ǁ',' ','ɨ','ʉ','ɯ',' ','ɪ','ʏ','ʊ',' ','ɘ','ɵ','ɤ',' ','ə','ɚ',' ','ɛ','ɜ','ɝ','ɞ','ʌ','ɔ',' ','ɐ','ɶ','ɑ','ɒ',' ','ʰ','ʷ','ʲ','ˠ','ˤ','ⁿ','ˡ',' ','ˈ','ˌ','ː','ˑ','̪']
};

var edittoolsExtrasDefs = {
characters: [{start:'{{unicode|',end:'}}'}],
ipa:[{start:'{{IPA|',end:'}}'}]
};

// default is ucfirst
var edittoolsTitles = {wikimarkup:'Wiki markup',ipa:'IPA'};

var edittoolsEnabledList = [
'wikimarkup','symbols','characters','greek','cyrillic','ipa'
];

//avoid instantiating many closures by using the actual text of the link
function edittoolsSimpleInsert() {
    insertTags(this.firstChild.nodeValue,'','');
    return false;
}

var edittoolsFontClass = { characters:'Unicode',ipa:'IPA' }

function edittoolsSetup() {
    function ucfirst(x) { // the simpler way doesn't work on IE
      var parts = x.match(/(.)(.*)/);
      return parts[1].toUpperCase() + parts[2].toLowerCase();
    }
        if (window.edittoolsDisabled) return;
        if (!document.getElementById('editpage-specialchars')) return;
        document.getElementById('editpage-specialchars')
                .appendChild(document.createElement('HR'))
        for(var i=0;i<edittoolsEnabledList.length;i++) {
            var x=edittoolsEnabledList[i]; if(!x) continue;
            var title=ucfirst(x);
            if(edittoolsTitles[x]) title = edittoolsTitles[x];
            var sec = edittoolsAddSection('edittoolsX_'+x,title,
                     edittoolsDefs[x],edittoolsExtrasDefs [x]);
            if(edittoolsFontClass[x]) sec.className += ' '+edittoolsFontClass[x];
        }
}

function edittoolsAddSection(id,title,arr,extra) {
var sec = document.createElement("DIV");
sec.className="edittools_section";
sec.style.fontSize='small'; sec.style.lineHeight='1.5em';
var head = document.createElement("B");
head.appendChild(document.createTextNode(title + ":"))
sec.appendChild(head)
function process(item) {
    if (item == null) return;
sec.appendChild(document.createTextNode(' '));
    var ln = document.createElement('A');
    ln.href='#'
if(typeof(item ) == 'string') {
    if(item == ' ') sec.appendChild(document.createTextNode('\u00a0'));
    else {ln.appendChild(document.createTextNode(item));
    ln.onclick = edittoolsSimpleInsert; }
} else {
  // here's the complex case.
  var start = '', end = '', sample = '', click = '';
  if (item.start != undefined) start = item.start;
  if (item.end != undefined) end = item.end;
  if (item.sample != undefined) sample = item.sample;
  if (item.click != undefined) click = item.click;
  else click = start + end
    ln.onclick = (function(a,b,c){return (function() {
        insertTags(a,b,c);
        return false;
    })})(start,end,sample)
    ln.appendChild(document.createTextNode(click));
}
sec.appendChild(ln);
}
if(typeof(arr) == 'string')
for(var i=0;i<arr.length;i++) process(arr.charAt(i));
else
for(var i=0;i<arr.length;i++) process(arr[i]);
if(extra) {
sec.appendChild(document.createTextNode(" \u2022"));
if(typeof(extra) == 'string')
for(var i=0;i<extra.length;i++) process(extra.charAt(i));
else
for(var i=0;i<extra.length;i++) process(extra[i]);

}

sec.appendChild(document.createElement("BR"))
sec.id = id;
document.getElementById('editpage-specialchars').appendChild(sec);
return sec;
}//addedittool

var test_edittool = [
'test',
'1234',
   { start: '<blockquote><div>' ,end:'</div></blockquote>',sample:'foo',click:'better-blockquote'},
'meh'];

// }}}

/* probably should instead call from runonloadhook
 */
addOnloadHook(edittoolsSetup);

// For Gadget {{{
edittoolsDefs['cyrillic2'] = 'ӘәӨөҒғҖҗҚқҜҝҢңҮүҰұҲҳҸҹҺһ ҔҕӢӣӮӯҘҙҠҡҤҥҪҫӐӑӒӓӔӕӖӗӰӱӲӳӸӹ ҟҦҧҨҩҬҭҴҵҶҷҼҽҾҿӁӂӃӄӇӈӋӌӚӛӜӝӞӟӠӡӤӥӦӧӪӫӴӵ';
edittoolsTitles['cyrillic2'] = 'More Cyrillic';

(function() {
// add it after "cyrillic" if "cyrillic" is enabled, otherwise at the end.
var tmp = edittoolsEnabledList;
edittoolsEnabledList = [];
var did = false;
for(var i=0;i<tmp.length;i++) {
edittoolsEnabledList[edittoolsEnabledList.length] = tmp[i];
if(!did && tmp[i] == 'cyrillic') {edittoolsEnabledList[edittoolsEnabledList.length] = 'cyrillic2'; did = true }
}
if(!did) edittoolsEnabledList[edittoolsEnabledList.length] = 'cyrillic2';
})()
// }}}

// for user js {{{
for(var i=0;i<edittoolsEnabledList.length;i++) {
    switch(edittoolsEnabledList[i]) {
        case 'wikimarkup': edittoolsEnabledList[i] = false; break;
    }
}
// }}}
// }}} END OF EDIT TOOLS TEST CODE

/* change diff to history in new messages {{{
addOnloadHook(function() {
    var contentSub = document.getElementById("contentSub");
    if(!contentSub) return;
    var elem = contentSub.nextSibling;
    while(elem.nodeType != 1) elem = elem.nextSibling;
    if(elem.className != 'usermessage') return;
    elem.getElementsByTagName('A')[1].href = elem.getElementsByTagName('A')[1].href.replace("diff=cur","action=history")
    elem.getElementsByTagName('A')[1].textContent = "history";
});
// }}}*/

// Section organizer for ANI {{{
if (wgPageName == "Wikipedia:Administrators\'_noticeboard/Incidents" && wgAction == "view") {
   addOnloadHook(function ani_sections() {
       var headers = document.getElementsByTagName('H2');
       for(var i=1;i<headers.length;i++) {
           // starting from 1, to skip the toc header.
           var section = document.createElement("DIV");
           section.className = "sectionContainer";
           var anchor = headers[i].previousSibling;
           while(anchor.nodeType != 1) anchor = anchor.previousSibling;
           headers[i].parentNode.insertBefore(section,headers[i]);
           section.appendChild(anchor);
           section.appendChild(headers[i]);
           var innerSection = document.createElement("DIV");
           innerSection.className = "sectionContentHolder";
           section.appendChild(innerSection);
           while(section.nextSibling && section.nextSibling.tagName != 'H2' && section.nextSibling.id != 'catlinks') {
               // look ahead
               var anchorcheck = section.nextSibling.nextSibling;
               while(anchorcheck && anchorcheck.nodeType!=1) anchorcheck = anchorcheck.nextSibling;
               if(anchorcheck && anchorcheck.tagName == 'H2') break;
               innerSection.appendChild(section.nextSibling);
           }

           var ntimestamps = 0;
           // evil evil hack
           var lastTimestamp = new Date(0);
           var lastTimestampText = '(No Timestamp)';
           innerSection.textContent.replace(/[0-9][0-9]:[0-9][0-9], [0-3]?[0-9] [A-Z][a-z]* [0-9][0-9][0-9][0-9]/g,function(match) {
               var thisTimestamp = new Date(match);
               if(thisTimestamp.valueOf() > lastTimestamp.valueOf()) {
                   lastTimestamp = thisTimestamp;
                   lastTimestampText = match;
               }
               ntimestamps++;
           });
           // was done incorrrectly in local time, convert from UTC
           lastTimestamp.setMinutes(
              lastTimestamp.getMinutes()-lastTimestamp.getTimezoneOffset()
           );
           var age = (new Date()).getTime() - lastTimestamp.getTime();
           var hideDefault = false;
           if (age > 21600000) // 6 hours
              hideDefault = true;
           if(innerSection.textContent.length < 600) // bytes
              hideDefault = false; // no reason to hide in this case
           if(ntimestamps < 2) // unanswered
              hideDefault = false;

           // hide if resolved, also, place the resolved header in the visible part.
           var resolved = getElementsByClassName(innerSection,'DIV','resolved');
           if(resolved.length) {
             resolved = resolved[0];
             // [1] to skip an annoying whitespace node
             if (resolved != innerSection.firstChild && resolved != innerSection.childNodes[1]) resolved = resolved.cloneNode(true);
             section.insertBefore(resolved,innerSection);
             hideDefault = true;
           }

           section.insertBefore(document.createTextNode('Last: ' + lastTimestampText + ".  "),innerSection);
           section.insertBefore(document.createTextNode(innerSection.textContent.length + " text bytes. "),innerSection);
           section.insertBefore(document.createTextNode(ntimestamps + " comments. "),innerSection);

           (function ani_sections_closure(){
               var header = headers[i];
               var innerSectionFix = innerSection;
               var button = document.createElement('BUTTON');
               if(hideDefault)
               button.textContent = 'show';
               else
               button.textContent = 'hide';
               button.onclick = function ani_sections_onclick() {
                   if(innerSectionFix.style.display == 'none') {
                     innerSectionFix.style.display = 'block';
                     this.textContent = 'hide'; }
                   else {
                     innerSectionFix.style.display = 'none';
                     this.textContent = 'show'; }
               }
               header.insertBefore(button,header.firstChild);
               button.style.cssText='float: right';
               if(hideDefault) innerSection.style.display='none';
           })();
       }
   });
}
// }}}