User:Blupo/wikia.js

var wordmarks = [ "https://vignette.wikia.nocookie.net/swordburst2/images/8/89/Wiki-wordmark.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/a/ab/Wiki-wordmark-arcadia1.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/0/00/Wiki-wordmark-arcadia2.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/3/3b/Wiki-wordmark-pvp1.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/1/1f/Wiki-wordmark-pvp2.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/5/59/Wiki-wordmark-pvp3.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/d/db/Wiki-wordmark-virhst1.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/1/1d/Wiki-wordmark-virhst2.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/a/ad/Wiki-wordmark-virhst3.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/0/08/Wiki-wordmark-virhst4.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/5/58/Wiki-wordmark-virhst5.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/9/9e/Wiki-wordmark-virhst6.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/0/0f/Wiki-wordmark-redveil1.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/b/ba/Wiki-wordmark-redveil2.png/revision/latest", "https://vignette.wikia.nocookie.net/swordburst2/images/a/a6/Wiki-wordmark-redveil3.png/revision/latest", ];

$(".wds-community-header__wordmark img").attr("src", wordmarks[Math.floor(Math.random * wordmarks.length)]);

// credit to the authors of AbuseLogRC // a lot of the code for this is taken from AbuseLogRC.js because I'm lazy, I'll change it later (function {    "use strict";    if (window.abuseLogActive) {        console.log("AbuseLog: Already running");        return;    }    window.abuseLogActive = true;    var mwData = mw.config.get([ "wgCanonicalSpecialPageName", "wgUserGroups" ]);   var userGroups = mwData.wgUserGroups.join(" ");    if (mwData.wgCanonicalSpecialPageName != "Recentchanges") { return }    var config = {        "refreshInterval": 5,        "entries": 10,        "checkIfPagesExist": false,    };    var itemsSince = null;    var itemIds = [];    var refreshTimer = null;    var loadLock = false;    var abToggles = " " +        "" +        "Auto-refresh " +        " " +        "" +        "Check if pages exist " +        " ";    var abInputs = " " +        "Refresh interval (5 seconds): " +        "" + " " +       "Number of entries (10): " + "" + " ";   var abButtons = " " + " " + "" + " ";   var abFieldset = " Abuse Log Options " + abToggles + abInputs + abButtons + " "; var container = " " + abFieldset + " Abuse Log  "; $('#mw-content-text').before(container); function sentenceCase(string) { return string.charAt(0).toUpperCase + string.slice(1); }   function clamp(num, min, max) { return num <= min ? min : num >= max ? max : num; }   function callAPI(data, callback) { data.format = 'json'; // add the format to the given data query data.action = 'query'; $.getJSON(mw.util.wikiScript('api'), data) .done(function(response) {               if (response.error) {                    $('#abLog-error')                        .text(error)                        .show;                } else {                    callback(response);                }            }) .error(function(xhr, error) {               $('#abLog-error')                    .text(error)                    .show;            }); }   var pageExistsCache = {}; function pageExists(name) { if (!config.checkIfPagesExist) { return true; } if (pageExistsCache[name]) { return pageExistsCache[name]; } $.getJSON(mw.util.wikiScript('api'), {           "action": "query",            "format": "json",            "titles": name        }).done(function(response) {            if (!response.error) {                var pageExists = false;                for (var i in response.query.pages) {                    var item = reponse.query.pages[i];                    if (item.title == name) {                        pageExists = item.missing ? true : false;                        break;                    }                }                pageExistsCache[name] = pageExists;                return pageExists;            }        }); }   function refreshData{ $('#abLog-list').empty; $('#abLog-error').hide; itemIds = []; itemsSince = null; loadData; }   function loadComplete { $("#abOption-autoRefreshLabel").text("Auto-refresh (updated at " + (new Date).toLocaleTimeString + ")"); }   function loadData { if (loadLock) { return; } else { loadLock = true; } $("#abLoader").show; $("#ab-forceRefresh").prop("disabled", true); var isSysop = /sysop/.test(userGroups); var itemQuery = { "afllimit": config.entries, "afldir": "older", "action": "query", "list": "abuselog", "aflprop": "ids|user|title|action|result|filter|timestamp|hidden" };       if (itemsSince) { itemQuery.itemend = itemsSince; } callAPI(itemQuery, function(response) {           for (var i in response.query.abuselog) {                var item = response.query.abuselog[i];                // Remove duplicates which may occur during autorefresh                if ($.inArray(item.id, itemIds) > -1) { continue; }                if (itemIds.length >= config.entries) { refreshData; }                itemIds.push(item.id);                // Time                // query timestamps are UTC in ISO format                var then = new Date(item.timestamp),                    date = then.toLocaleDateString,                    time = then.toLocaleTimeString;                // Set time limit for next requests                itemsSince = item.timestamp;                var timeStr = date + ", " + time;                var userLink = "" + item.user + ""; var userTools = " (" +                   "wall</a> | " +                    "contribs</a> | " +                    "block</a>)" + " ";               var filter = "filter " + item.filter_id + "</a>"; var pageLink = "" + item.title + "</a>"; var filterTools = " (" +                   "details</a> | " +                    "examine</a>" +                    ") "; var entry = "<li id='abLog-entry'>" + timeStr + ": " + userLink + " " + userTools + " triggered " + filter + ", performing the action \"" + item.action + "\" on " + pageLink + ". Actions taken: " + (item.result ? sentenceCase(item.result) : "none") + "; Filter description: " + item.filter + (isSysop ? filterTools : "") + "</li>"; $("#abLog-list").append(entry); }           $("#abOption-autoRefreshLabel").text("Auto-refresh (updated at " + (new Date).toLocaleTimeString + ")"); $("#ab-forceRefresh").prop("disabled", false); $("#abLoader").hide; loadLock = false; });   }    callAPI({ meta: 'siteinfo', siprop: 'extensions', action: 'query' }, function(response) { var o = response.query.extensions, found = false;

if ($.isArray(o)) { for ( var i = 0; i < o.length && !found; ++i ) { found = o[i].name === 'Abuse Filter'; }       }        if (found) { console.log("AbuseLog: Abuse Filter is enabled"); } else { console.log("AbuseLog: Abuse Filter is not enabled"); return; }   });    $("#abOption-autoRefresh").change(function  { // todo });   $("#abOption-checkPagesExist").change(function  { config.checkIfPagesExist = (this.checked === true); });   $("#ab-forceRefresh").click(function { var newRefreshInterval = Number(parseInt($("#abOption-refreshInterval").val, 10)); var newEntries = Number(parseInt($("#abOption-numEntries").val, 10)); newRefreshInterval = (typeof newRefreshInterval == "number") ? newRefreshInterval : config.refreshInterval; newEntries = (typeof newEntries == "number") ? newEntries : config.entries; newRefreshInterval = !isNaN(newRefreshInterval) ? newRefreshInterval : config.refreshInterval; newEntries = !isNaN(newEntries) ? newEntries : config.entries; config.refreshInterval = (newRefreshInterval >= 5) ? newRefreshInterval : 5; config.entries = clamp(newEntries, 1, 500); $("#abOption-refreshIntervalLabel").text("Refresh interval (" + config.refreshInterval + " seconds): "); $("#abOption-numEntriesLabel").text("Number of entries (" + config.entries + "): "); refreshData; });   loadData; });