User:Kiz/uespvector.js

The UESPWiki – Your source for The Elder Scrolls since 1995
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
// <pre><nowiki>

function addSinceTab() {

    // Default number of revisions to check. Set to 0 to use your usual default for a history page.
    // Sensible options might be 300, 500 or 750. Values up to 5000 are valid, but will be quite slow.

    if (!window.defaultdiffs) defaultdiffs = 0;

    if (window.location.href.indexOf("&action=history&gotosince=true") != -1) {
        do_since_I_last_edited()
    } else if (mw.config.get('wgCanonicalNamespace') != "Special") {
        mw.util.addPortletLink("p-cactions", mw.config.get('wgScript') + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=history&gotosince=true" + ((defaultdiffs <= 0) ? "" : "&limit=" + defaultdiffs), 'since', '', "all changes since your last edit");
    }
}

function do_since_I_last_edited() {
    var csub = document.getElementById("contentSub");
    var msg = document.createElement("p");
    if (!csub || !msg) return;

    msg.appendChild(document.createTextNode("Parsing history... please wait..."));
    msg.className = "error";
    csub.insertBefore(msg, csub.firstChild)

    var hists = document.getElementById("pagehistory").getElementsByTagName('li');
    for (n = 0; n < hists.length; n++) {
        var userlink = $(hists[n]).find('.mw-userlink');
        if (userlink.length > 0 && userlink[0].innerHTML == mw.config.get('wgUserName')) {
            var histlinks = $(hists[n]).find('.mw-history-histlinks');
            if (histlinks.length > 0) {
                var histlinkas = histlinks[0].getElementsByTagName("a");
                if (histlinkas.length > 1) {
                    document.location = histlinkas[0].href;
                } else {
                    msg.replaceChild(document.createTextNode("You are the last editor. "), msg.firstChild);
                }
            }

            return;
        }
    }

    msg.replaceChild(document.createTextNode("You have not edited this page! (recently).  Look at more edits? "), msg.firstChild);

    var lookharderA = document.createElement("A");
    lookharderA.href = mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=history&gotosince=true&limit=1000';
    lookharderA.innerHTML = '1000';

    msg.appendChild(lookharderA);

    msg.appendChild(document.createTextNode(" "));

    lookharderA = document.createElement("A");
    lookharderA.href = mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=history&gotosince=true&limit=2500';
    lookharderA.innerHTML = '2500';

    msg.appendChild(lookharderA);

    msg.appendChild(document.createTextNode(" "));

    lookharderA = document.createElement("A");
    lookharderA.href = mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=history&gotosince=true&limit=5000';
    lookharderA.innerHTML = '5000';

    msg.appendChild(lookharderA);
}

$(addSinceTab);
// Navpopup Settings

window.popupHideDelay = '0.5';	

// WikEd Settings

var wikEdConfig = { 'clonedWarningsNote': false };

// JWB Import

mw.loader.load( '/w/index.php?title=User:Kiz/JWB.js&action=raw&ctype=text/javascript' );

// AjaxRC Import (Testing on by default)

mw.loader.load( '/w/index.php?title=User:Kiz/ajaxRC.js&action=raw&ctype=text/javascript' );

// Discussion page count

mw.loader.load( '/w/index.php?title=User:Kiz/discussion.js&action=raw&ctype=text/javascript' );

// Add no-redirect link after redirect links

$(function(){
	$('#mw-content-text .mw-redirect').after(function(){
		return this.href.indexOf('redirect=no') !== -1 || this.href.indexOf('action=') !== -1  || this.href.indexOf('diff=') !== -1  ? '' : ' <a href="' + this.href + (this.href.includes('?') ? '&' : '?') + 'redirect=no" title="' + (this.title || this.href) + ' (no redirect)">{⇨}</a>';
	});
});

//Fixed heading adjustment - only sort of, doesn't work with Anchor

$('div#bodyContent a').click(function(e) {
	if ($(e.target.hash)) {
		var hash = e.currentTarget.hash.substring(1);
		var anchorTag = $("span[id='" + hash + "']");
		$('html, div#content.mw-body').animate({
			scrollTop : anchorTag.offset().top - 100
		}, 250);
	}
});

//
// Modify Sidebar
//
// Note: do not import ModifySidebar; doing so will cause intermittent scripting issues due to
// asynchronous import; using window.addEventListener fixes that issue, but at the cost of
// significant delays in updating the menu.
function ModifySidebar(action, section, name, link, sub1name, sub1link, sub2name, sub2link, 
                       sub3name, sub3link, sub4name, sub4link, sub5name, sub5link) {
    try {
        switch (section) {
          case "languages":
            var target = "p-lang";
            break;
          case "toolbox":
            var target = "p-tb";
            break;
          default:
            var target = "p-" + section;
            break;
        }
 
        if (action == "add") {
            var node = document.getElementById(target)
                               .getElementsByTagName('div')[0]
                               .getElementsByTagName('ul')[0];
 
            var aNode = document.createElement('a');
            var liNode = document.createElement('li');
            var ulSub = document.createElement('ul');
 
            var a1Node = document.createElement('a');
            var li1Node = document.createElement('li2');
            var a2Node = document.createElement('a');
            var li2Node = document.createElement('li2');
            var a3Node = document.createElement('a');
            var li3Node = document.createElement('li2');
            var a4Node = document.createElement('a');
            var li4Node = document.createElement('li2');
            var a5Node = document.createElement('a');
            var li5Node = document.createElement('li2');

            aNode.appendChild(document.createTextNode(name));
            aNode.setAttribute('href', link);
            liNode.appendChild(aNode);
            liNode.className='plainlinks';

            if (!((sub1name === undefined) && (sub1link === undefined))) {
            a1Node.appendChild(document.createTextNode(sub1name));
            a1Node.setAttribute('href', sub1link);
            li1Node.appendChild(a1Node);
            li1Node.className='plainlinks';
            ulSub.appendChild(li1Node);

            if (!((sub2name === undefined) && (sub2link === undefined))) {
            a2Node.appendChild(document.createTextNode(sub2name));
            a2Node.setAttribute('href', sub2link);
            li2Node.appendChild(a2Node);
            li2Node.className='plainlinks';
            ulSub.appendChild(li2Node);

            if (!((sub3name === undefined) && (sub3link === undefined))) {
            a3Node.appendChild(document.createTextNode(sub3name));
            a3Node.setAttribute('href', sub3link);
            li3Node.appendChild(a3Node);
            li3Node.className='plainlinks';
            ulSub.appendChild(li3Node);

            if (!((sub4name === undefined) && (sub4link === undefined))) {
            a4Node.appendChild(document.createTextNode(sub4name));
            a4Node.setAttribute('href', sub4link);
            li4Node.appendChild(a4Node);
            li4Node.className='plainlinks';
            ulSub.appendChild(li4Node);

            if (!((sub5name === undefined) && (sub5link === undefined))) {
            a5Node.appendChild(document.createTextNode(sub5name));
            a5Node.setAttribute('href', sub5link);
            li5Node.appendChild(a5Node);
            li5Node.className='plainlinks';
            ulSub.appendChild(li5Node);
            }
            }
            }
            }
            liNode.appendChild(ulSub);
            }

            node.appendChild(liNode);
        }
 
        if (action == "remove") {
            var list = document.getElementById(target)
                               .getElementsByTagName('div')[0]
                               .getElementsByTagName('ul')[0];
 
            var listelements = list.children;
            var removeNextUl = false;
            for (var i = 0; i < listelements.length; i++) {
                var elem = listelements[i];
                if (elem.tagName == 'LI') {
                    if ((elem.getElementsByTagName('a')[0].innerHTML == name) || (elem.getElementsByTagName('a')[0].href == link)) {
                        list.removeChild(elem);
                        removeNextUl = true;
                        i--;
                    } else {
                        removeNextUl = false;
                    }
                } else {
                    if (elem.tagName == 'UL' && removeNextUl) {
                        list.removeChild(elem);
                    }

                    removeNextUl = false;
                }
            }
        }
 
        if (action == "clear") {
            var list = document.getElementById(target)
                               .getElementsByTagName('div')[0]
                               .getElementsByTagName('ul')[0];
 
            var listelements = list.childNodes;
            for (var i = list.childNodes.length-1; i>=0; i--) {
                list.removeChild(list.childNodes[i]);
            }
        }

    } catch(e) {
      // lets just ignore what's happened
      return;
    }
}
function CustomizeModificationsOfSidebar() {
//start customsidebar
//cleargeneral
   ModifySidebar("clear",  "general");

//general
   ModifySidebar("add",    "general",   "Main Page",             "https://www.uesp.net/wiki/Main_Page");
   ModifySidebar("add",    "general",   "Recent Changes",        "https://www.uesp.net/wiki/Special:RecentChanges");
   ModifySidebar("add",    "general",   "CSList Skyrim",         "https://cs.uesp.net/index.php?game=sr");
   ModifySidebar("add",    "general",   "CSList Oblivion",       "https://cs.uesp.net/index.php?game=ob"); 
   ModifySidebar("add",    "general",   "ESOLog",                "https://esolog.uesp.net/viewlog.php");
 
//sections
    ModifySidebar("clear", "sections");
    ModifySidebar("add",   "sections",  "Lore",                "https://www.uesp.net/wiki/Lore:Main_Page");
    ModifySidebar("add",   "sections",  "Books",               "https://www.uesp.net/wiki/Books:Books");
    ModifySidebar("add",   "sections",  "Blades",              "https://www.uesp.net/wiki/Blades:Blades");
    ModifySidebar("add",   "sections",  "Legends",             "https://www.uesp.net/wiki/Legends:Legends");
    ModifySidebar("add",   "sections",  "General",             "https://www.uesp.net/wiki/General:Main_Page");

    ModifySidebar("add",   "sections",  "Online",              "https://www.uesp.net/wiki/Online:Main_Page",
                                        "ESO Map",             "https://esomap.uesp.net");
    ModifySidebar("add",   "sections",  "Skyrim",              "https://www.uesp.net/wiki/Skyrim:Skyrim",
                                        "CC",                  "https://www.uesp.net/wiki/Skyrim:Creation Club",
                                        "SR Map",              "https://srmap.uesp.net",
                                        "Dawnguard",           "https://www.uesp.net/wiki/Skyrim:Dawnguard",
                                        "Hearthfire",          "https://www.uesp.net/wiki/Skyrim:Hearthfire",
                                        "Dragonborn",          "https://www.uesp.net/wiki/Skyrim:Dragonborn",
                                        "DB Map",              "https://dbmap.uesp.net");
    ModifySidebar("add",   "sections",  "Oblivion",            "https://www.uesp.net/wiki/Oblivion:Oblivion",
                                        "OB Map",              "https://obmap.uesp.net",
                                        "Shivering Isles",     "https://www.uesp.net/wiki/Shivering:Shivering_Isles",
                                        "SI Map",              "https://simap.uesp.net",
                                        "Official Plugins",    "https://www.uesp.net/wiki/Oblivion:Official_Plug-ins");
    ModifySidebar("add",   "sections",  "Morrowind",           "https://www.uesp.net/wiki/Morrowind:Morrowind",
                                        "Official Plugins",    "https://www.uesp.net/wiki/Morrowind:Official_Plug-ins");
//community
   ModifySidebar("clear", "community");
   ModifySidebar("add",    "community", "Javascript",                  "https://www.uesp.net/wiki/UESPWiki:Javascript",
                                        "AN",                  "https://www.uesp.net/wiki/UESPWiki:Administrator_Noticeboard",
                                        "CP",                  "https://www.uesp.net/wiki/UESPWiki:Community_Portal",
                                        "WM",                  "https://www.uesp.net/wiki/User:Kiz/WMessage",
                                        "RH TB",               "https://www.uesp.net/wiki/User:RobinHood70/Toolbox",
                                        "JWB",                 "https://www.uesp.net/wiki/User:Kiz/JWB");


//toolbox
   ModifySidebar("add",    "toolbox",    "My Subpages",           "https://www.uesp.net/wiki/User:Kiz/Subpages");

}
$(CustomizeModificationsOfSidebar);

// start watcher

mw.loader.using( 'mediawiki.util', function () {
	var showNotice = function () {
 
		// Stick a "Watchlist update!" notice after the notification count
		$( "#pt-notifications-notice" ).after(
        	$( "<li>" ).append( $( "<a>" )
        		.text( "Watchlist update!" )
        		.css( {
        			"background-color": "green",
        			"color": "white",
        			"border-radius": "2px",
        			"padding": "0.25em 0.45em 0.2em",
        			"cursor": "pointer",
        			"font-weight": "bold",
        			"transition": "background-color 0.5s"
        		} )
        		.attr( "href", "/wiki/Special:Watchlist" )
        		.mouseover( updateNotice )
        	)
        	.attr( "id", "watchlist-update-notice" )
        );
	};
	
	var updateNotice = function() {
		// Lighten the background color so the user knows we're updating
		$( "#watchlist-update-notice a" ).css( "background-color", "#7bff7b" );
		
		// Update the notice
		$.getJSON(
    		mw.util.wikiScript( 'api' ),
    		{
    			format: "json",
    			action: "query",
    			list: "watchlist",
    			wlshow: "unread",
    			wllimit: 1 // Because we're checking if there are *any* entries
    		} ).done(function( data ) {
    			if( !data.query ) return;
    			if( data.query.watchlist.length ) {
 
    				// There are new watchlist diffs to read, so show notice
    				if( !$( "#watchlist-update-notice" ).length ) {
    					
    					// That is, if it isn't shown already
    					showNotice();
    				} else {
    					
    					// There's already a notice, so change background
    					$( "#watchlist-update-notice a" ).css( "background-color", "green" );
    				}
    			} else {
    				
    				// No new watchlist diffs to read, so hide notice
    				$( "#watchlist-update-notice" ).remove();
    			}
    		}
    	);
	};
 
    $( document ).ready( function () { 
	    updateNotice();
	    window.setInterval( updateNotice, 120000 );
    } );
} );

// end watcher

// WikEd Config

$(function(){
  	var e = document.getElementById('wikEdConsoleWrapper');
  	e && e.parentNode.insertBefore(e,e.parentNode.firstChild);
});


// End WikEd Config

// testing

/**
 * @source https://www.mediawiki.org/wiki/Snippets/Open_specific_links_in_new_window
 * @version 2018-09-15
 */
$( function () {
	$( '#mw-content-text' ).on( 'click', '.external', function () {
		var otherWindow = window.open();
		otherWindow.opener = null;
		otherWindow.location = this;
		return false;
	} );
} );

// end testing

// </nowiki></pre>