User:BaneDiaries/global.js

// Adding button to header with useful links; // @author: BaneDiaries // status: in-development; $(function { $('.page-header__contribution-buttons').append(""+ ""+ " Useful "+ ""+ ""+ ""+ " "+ ""+ ""+ "Protect Article"+ "AJAX Refresh</li>"+ "Stub</a></li>"+ "Delete</a></li>"+ "Merge</a></li>"+ "</ul>"+ "  ");			// Protection 			$('a#num1').click(function { var protectiontime = prompt('Expiry:'); if(protectiontime) { new mw.Api.post({           action: 'protect',            title: mw.config.get('wgPageName'),            reason: '',            expiry: protectiontime,            protections: 'edit=sysop',            token: mw.user.tokens.get('editToken')        }).done(function(d) {            if(d.error) {                new BannerNotification('Error while protecting article: ' + d.error.code, 'error').show;            } else {                new BannerNotification('Successfully protected article', 'success').show;            }        }).fail(function {            new BannerNotification('Error while protecting article', 'error').show;        }); } });		// AJAX refresh		$('#num2').on("click", function refreshArticle { var temp = $(' '); temp.load(window.location.href + ' #mw-content-text', function {			var $newContent = temp.children('#mw-content-text');			if (newContent.length) {				$('#mw-content-text').replaceWith(newContent);				// re-set mw.util.$content for any scripts that may use it				mw.util.content = newContent;			}		}); temp.remove; alert("Content refreshed!"); });	$('.DiscordIntegratorModule').remove; // Removing discord integrator from rail }); /* // Notes section. Thanks to the guy from stack overflow who made this possible:| $('#WikiaRail').append('<section class=\"chat-module rail-module\"><h2 class=\"headernote\">Notes: <ul id=\"notes\" class=\"actualnotes\"></ul><input type=\"text\" id=\"txtNote\" placeholder=\"Add Note\"> <div class=\"entry-button wds-is-secondary wds-button wds-is-squished\" id=\"btnSave\">Save <div class=\"entry-button wds-is-secondary wds-button wds-is-squished\" id=\"btnClear\">Clear! '); var list = document.getElementById("notes"); // Loop through localStorage for (var i = 0; i < localStorage.length; i++){ // Make sure that we only read the notes from local storage if(localStorage.key(i).indexOf("note") !== -1){ // For each item, create a new  element var item = document.createElement("li"); item.className = " itemCSS"; // Populate the  with the contents of the current // localStorage item's value item.textContent = localStorage.getItem(localStorage.key(i)); // Append the  to the page's <ul> list.appendChild(item); }  }   var btn = document.getElementById("btnSave"); var note = document.getElementById("txtNote"); var btnclean = document.getElementById("btnClear"); var noteCount = 1; btn.addEventListener("click", function{    var noteVal = note.value;     if(noteVal.trim !== ""){       localStorage.setItem("note" + noteCount, noteVal);       var lstItem = document.createElement("li");       lstItem.textContent = noteVal;       noteCount++;     }    btnclean.addEventListener("click", function{ localStorage.clear; }  }); $('.headernote').css({ 'margin': '0 !important', 'text-align': 'center', 'font-size': '25px !important', 'font-style': 'italic', 'font-family': 'Raleway' }); $('.actualnotes li').css({ 'background': 'purple', 'padding': '10px', 'margin': '5px', 'font-family': 'Raleway', 'text-align': 'center', 'font-size': '17px', 'font-style': 'italic', 'border': '1px solid' }); $('#txtNote').css({ 'background': 'transparent', 'border': 'none', 'text-align': 'center', 'margin-left': '20%', 'float': 'center', 'color': 'white', 'font-style': 'italic' }); $('#btnClear').css({ 'float': 'right' }); });

// Adding module to rail explaining relationship merge // Author @Original Authority // last-modified: 09/07/17 $(function {   if(window.location.href.indexOf("/Relationships") > -1) {		var fullurl = window.location.pathname;	var removewiki = fullurl.replace('/wiki/',);	var removerelationships = removewiki.replace('/Relationships',);	var finaloutput = removerelationships.replace ('_', ' ');		$('#WikiaRail').prepend('<section class=\"chat-module rail-module\"><h2 class=\"headernote\">Relationships <p style="font-weight: bold; text-align: center;">Listed on this article are all of the relationships regarding ' + finaloutput + ' that do not warrant their own article. As such, they have been merged into one article as decided through the relationship merge</a> project.'); } });

/* Any JavaScript here will be loaded for all users on every page load. */

// ************************************************** // Experimental javascript countdown timer (Splarka) // Version 0.0.3s // ************************************************** // // Usage example: // //  Only January 01 2007 00:00:00 PST until New years. // //  Javascript disabled.

function updatetimer(i) { var now = new Date; var then = timers[i].eventdate; var diff = count=Math.floor((then.getTime-now.getTime)/1000);

// catch bad date strings if(isNaN(diff)) { timers[i].firstChild.nodeValue = '** ' + timers[i].eventdate + ' **' ; return; }

// determine plus/minus if(diff<0) { diff = -diff; var tpm = ' '; } else { var tpm = ' '; }

// calcuate the diff var left = (diff%60) + ' seconds'; diff=Math.floor(diff/60); if(diff > 0) left = (diff%60) + ' minutes ' + left; diff=Math.floor(diff/60); if(diff > 0) left = (diff%24) + ' hours ' + left; diff=Math.floor(diff/24); if(diff > 0) left = diff + ' days ' + left; timers[i].firstChild.nodeValue = tpm + left;

// a setInterval is more efficient, but calling setTimeout // makes errors break the script rather than infinitely recurse timeouts[i] = setTimeout('updatetimer(' + i + ')',1000); }

function checktimers { //hide 'nocountdown' and show 'countdown' var nocountdowns = getElementsByClassName(document, 'span', 'nocountdown'); for(var i in nocountdowns) nocountdowns[i].style.display = 'none'; var countdowns = getElementsByClassName(document, 'span', 'countdown'); for(var i in countdowns) countdowns[i].style.display = 'inline';

//set up global objects timers and timeouts. timers = getElementsByClassName(document, 'span', 'countdowndate'); //global timeouts = new Array; // generic holder for the timeouts, global if(timers.length === 0) return; for(var i in timers) { timers[i].eventdate = new Date(timers[i].firstChild.nodeValue); updatetimer(i); //start it up  } } addOnloadHook(checktimers);

// ************************************************** // - end -  Experimental javascript countdown timer // **************************************************

$(".openchat a").click(function {  window.open('/wiki/Special:Chat', 'wikiachat', 'width=600,height=600,menubar=no,status=no,location=no,toolbar=no,scrollbars=no,resizable=yes');   return false; });

/*   Replaces  with the name of the user browsing the page. Requires copying Template:USERNAME.

function UserNameReplace { if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || wgUserName == null) return; $("span.insertusername").text(wgUserName); } addOnloadHook(UserNameReplace);

//ListFiles//

addOnloadHook(UserNameReplace); /* Adds a spoiler alert to pages that have the category 'Spoilers' */ SpoilerAlert = { isSpoiler: function { return -1 !== wgCategories.indexOf('Spoilers'); } }; importScriptPage('SpoilerAlert/code.js', 'dev');

// Have categories added to images from upload description // Code written by @Original Authority based on code by @UltimateSupreme

if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload') { if (!$.getUrlVar('wpForReUpload')) jQuery(function ($) {       'use strict';        var $desc = $('#wpUploadDescription');        if ($desc.val) {            return; // If not empty then don't do anything (i.e. error message confirm page)        }         $desc.val( ''       );    }); } // end image upload form

// Spoiler Warning // @author: Original Authority // var day = new Date.getDay; // if (mw.config.get('wgAction') === 'edit' && day == 4) { //4 = Thursday // confirm('Please note that adding spoilers to articles today is against our wiki policies. Please wait until tomorrow and the episode has aired in the US to add spoiler to articles. Any instance of spoilers on articles will get you blocked. Thanks for your co-operation!'); // }

// end Spoiler warning

// AjaxRC window.ajaxPages = ["Special:WikiActivity","Special:Log","Special:RecentChanges"]; window.ajaxIndicator = 'http://images2.wikia.nocookie.net/__cb20100609110347/software/images/a/a9/Indicator.gif'; window.AjaxRCRefreshText = 'Auto Refresh'; window.AjaxRCRefreshHoverText = 'Silently refreshes the contents of this page every 60 seconds without requiring a full reload';

// removing the forum link to make way for discussions // @author Original Authority // last-modified: 13/11/16 // $(function { // var forum = $('.nav .nav-item:first-child .subnav-2-item')[5].innerHTML.trim// ; // if ( forum == 'Forum</a>') { // $('.nav .nav-item:first-child .subnav-2-item')[5].remove; // }; // }); // could be useful in removing other elements from the nav.