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)]);

window.abuseLog_autoRefresh = false; window.abuseLog_autoRefreshInterval = 5; window.abuseLog_entries = 12; window.abuseLog_showRCFirst = true; window.abuseLog_checkIfPagesExist = true;

// 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 = {        "autoRefreshInterval": window.abuseLog_autoRefreshInterval || 60,        "entries": window.abuseLog_entries || 10,        "checkIfPagesExist": (typeof window.abuseLog_checkIfPagesExist !== "undefined") ? window.abuseLog_checkIfPagesExist : false,        "autoRefresh": (typeof window.abuseLog_autoRefresh !== "undefined") ? window.abuseLog_autoRefresh : false,        "showRCFirst": (typeof window.abuseLog_showRCFirst !== "undefined") ? window.abuseLog_showRCFirst : false,        "urgencyIntervals" : window.abuseLog_urgencyIntervals || [2, 12, 24]    };    config.urgencyIntervals.sort(function(a, b) { return a - b });    var itemsSince = null;    var itemIds = [];    var refreshTimer = null;    var loadLock = false;    var abToggles = " " + "" + "Auto-refresh " + " " +       "" + "Check if pages exist " + " ";   var abInputsTable = "  "; var abTools = " " + " " + " " + " " + " ";   var abHints = " " + " " +       "" + " | " +       "Abuse Filter | " + "Abuse Log" + " " +       " " +        " ";    var abFieldset = " Abuse Log Options " + abToggles + abInputsTable + abTools + abHints + " "; 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) {                callback(response);            } else {                $("#abLog-error").text(error).show;            }        }); }   var pageExistsCache = {}; function pageExists(name) { if (!config.checkIfPagesExist) { return true; } if (typeof pageExistsCache[name] !== "undefined") { return pageExistsCache[name]; } $.getJSON(mw.util.wikiScript('api'), {           "action": "query",            "format": "json",            "titles": name        }).done(function(response) {            if (!response.error) {                for (var i in response.query.pages) {                    var item = response.query.pages[i];                    if (item.title == name) {                        console.log(item.missing !== "");                        pageExistsCache[name] = item.missing !== "";                        return;                    }                }            }        }); return pageExistsCache[name]; }   function urgencyClass(timeDiff) { for (var i in config.urgencyIntervals) { var interval = config.urgencyIntervals[i] * 3600 * 1000; var urgencyLevel = Number(i) + 1; if (timeDiff <= interval) { return "abUrgency" + urgencyLevel; }       }        return "abNonUrgent"; }   function refreshData{ $('#abLog-list').empty; $('#abLog-error').hide; itemIds = []; itemsSince = null; loadData; }   function loadCompleted { if ($("#abInput-autoRefresh:checked").length && !refreshTimer) { refreshTimer = window.setTimeout(loadData, config.autoRefreshInterval * 1000); }       $("#ab-lastRefreshed").text("Updated at " + (new Date).toLocaleTimeString); $("#ab-forceRefresh").prop("disabled", false); $("#abLoader").hide; }   function loadData { if (loadLock) { return; } else { loadLock = true; } refreshTimer = null; $("#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; } if (config.user) { itemQuery.afluser = config.user; } if (config.filterId) { itemQuery.aflfitler = config.filterId; } if (config.title) { itemQuery.afltitle = config.title; } callAPI(itemQuery, function(response) {           if (response.query.abuselog.length > 0) {                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 now = new Date,                        then = new Date(item.timestamp),                        date = then.toLocaleDateString,                        time = then.toLocaleTimeString;                    // Set time limit for next requests                    itemsSince = item.timestamp;                    var timeStr = "<span class='" + urgencyClass(now.getTime - then.getTime) + "'>" + date + ", " + time + " "; var userLink = "" + item.user + "</a>"; 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); }           } else { $("#abLog-list").append("<li>No results</li>"); }           loadCompleted; 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; }   });    $("#jumpToRC").click(function { $("#mw-content-text")[0].scrollIntoView(true); });   $("#abInput-checkPagesExist").change(function  { config.checkIfPagesExist = (this.checked === true); });   $("#ab-clearInputs").click(function { config.user = null; config.filterId = null; config.title = null; $("#abInput-userText").text(""); $("#abInput-filterIdText").text(""); $("#abInput-titleText").text(""); $("#abInput-user").prop("value", ""); $("#abInput-filterId").prop("value", ""); $("#abInput-title").prop("value", ""); $("#abInput-autoRefreshInterval").prop("value", ""); $("#abInput-numEntries").prop("value", ""); });   $("#ab-updateInputs").click(function { var newRefreshInterval = Number(parseInt($("#abInput-autoRefreshInterval").val, 10)); var newEntries = Number(parseInt($("#abInput-numEntries").val, 10)); var user = $("#abInput-user").val; var filterId = $("#abInput-filterId").val; var title = $("#abInput-title").val; newRefreshInterval = (typeof newRefreshInterval == "number") ? newRefreshInterval : config.autoRefreshInterval; newEntries = (typeof newEntries == "number") ? newEntries : config.entries; newRefreshInterval = !isNaN(newRefreshInterval) ? newRefreshInterval : config.autoRefreshInterval; newEntries = !isNaN(newEntries) ? newEntries : config.entries; config.autoRefreshInterval = (newRefreshInterval >= 5) ? newRefreshInterval : 5; config.entries = clamp(newEntries, 1, 500); config.user = user || null; config.filterId = filterId || null; config.title = title || null; $("#abInput-autoRefreshIntervalText").text("(" + config.autoRefreshInterval + " seconds)"); $("#abInput-numEntriesText").text("(" + config.entries + ")"); $("#abInput-userText").text(config.user ? "(" + config.user + ")" : ""); $("#abInput-filterIdText").text(config.filterId ? "(" + config.filterId + ")" : ""); $("#abInput-titleText").text(config.title ? "(" + config.title + ")" : ""); });   $("#abInput-autoRefresh").change(function { if (this.checked) { if (!refreshTimer) { refreshTimer = window.setTimeout(loadData, config.autoRefreshInterval * 1000); }       } else { if (refreshTimer) { window.clearTimeout(refreshTimer); refreshTimer = null; }       }    });    $("#ab-forceRefresh").click(refreshData);    $("#abInput-autoRefresh").prop("checked", config.autoRefresh);    $("#abInput-checkPagesExist").prop("checked", config.checkIfPagesExist);    if (config.showRCFirst) { window.location.hash = "#mw-content-text"; }    loadData; });