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 = 30; window.abuseLog_entries = 10; window.abuseLog_showRCFirst = false; 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

// todo: i18n, use MW messages (function {    "use strict";    if (window.abuseLogActive) {        console.log("AbuseLog: Already running");        return;    }    window.abuseLogActive = true;    var mwData = mw.config.get([ "wgCanonicalSpecialPageName", "wgUserGroups", "wgUserLanguage" ]);   var userGroups = mwData.wgUserGroups.join(" ");    if (!/user/.test(userGroups)) { return }    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,        "urgencyIntervals" : window.abuseLog_urgencyIntervals || [2, 12, 24]    };    config.urgencyIntervals.sort(function(a, b) { return a - b });    var isSysop = /sysop/.test(userGroups);    var itemsSince = null;    var itemIds = [];    var refreshTimer = null;    var loadLock = false;    var abInputsTable = " " +        " " + " " + " " + " ";   var abTools = " " + " " +       " Turn " + (config.autoRefresh ? "off" : "on") + " auto-refresh | " + " " + (config.checkIfPagesExist ? "Don't check" : "Check") + " if pages exist " + " " +       "" + " | " +       "Abuse Filter | " + "Abuse Log" + " " +       " " +        " ";    var abFieldset = " Abuse Log Options " + abInputsTable + abTools + " "; 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; }   mw.loader.using(["mediawiki.api", "mediawiki.jqueryMsg"], function {        var Api = new mw.Api;        function apiQuery(data) {            data.action = "query";            data.format = "json";            return Api.get(data);        }        // https://www.mediawiki.org/wiki/Manual:Messages_API#Getting_the_messages_to_the_client        function loadMessages(messages) {            return apiQuery({ meta: "allmessages", ammessages: messages.join("|"), amlang: config.wgUserLanguage, }).then(function(data) { $.each(data.query.allmessages, function(i, message) {                   if (message.missing !== "") {                        mw.messages.set(message.name, message["*"]);                        console.log(message.name, message["*"]);                    }                }); });       }        /*        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, id) {            var element = $(id);            if (!config.checkIfPagesExist) { return; }            if (typeof pageExistsCache[name] !== "undefined") {                element.addClass(pageExistsCache[name] ? "" : "new");               return;            }            apiQuery({ 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) { pageExistsCache[name] = item.missing !== ""; element.addClass(pageExistsCache[name] ? "" : "new"); return; }                   }                }            });        }        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 (config.autoRefresh && !refreshTimer) {                refreshTimer = window.setTimeout(loadData, config.autoRefreshInterval * 1000);            }            $("#ab-lastRefreshed").text("Updated at " + (new Date).toLocaleTimeString); $("#ab-forceRefresh").prop("disabled", false); $("#abLoader").hide; }       function localiseABAction(action) { return mw.msg("abusefilter-action=" + action); }       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", "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.aflfilter = config.filterId; } if (config.title) { itemQuery.afltitle = config.title; } apiQuery(itemQuery).done(function(response) {               if (!response.error) {                    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 results = item.result ? item.result.split(",") : ["noactions"]; results = results.map(localiseABAction); results[0] = sentenceCase(results[0]); var timeStr = "" + date + ", " + time + " "; var userLink = "" + item.user + "</a>"; var userTools = " (" +                               "" + mw.msg("wall-message-wall-shorten") + "</a>" + mw.msg("pipe-separator") +                                "" + mw.msg("contribslink") + "</a>" + mw.msg("pipe-separator") +                                "" + mw.msg("blocklink") + "</a>)" + " ";                           var filter = "" + mw.msg("abusefilter-log-detailedentry-local", item.filter_id) + "</a>"; var pageLink = "" + item.title + "</a>"; var filterTools = " (" +                               "" + mw.msg("abusefilter-log-detailslink") + "</a>" + mw.msg("pipe-separator") +                                "" + mw.msg("abusefilter-changeslist-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>"; if (isSysop) { entry = mw.msg("abusefilter-log-detailedentry-meta", timeStr, userLink + " " + userTools, filter, item.action, pageLink, results.join(", "), item.filter, filterTools); } else { //entry = mw.msg("abusefilter-log-entry", timeStr, userLink + " " + userTools, item.action, pageLink, item.result || "none", item.filter); }                           $("#abLog-list").append("<li id='abLog-entry'>" + entry + "</li>"); pageExists(item.title, "#entry-" + item.id); }                   } else { $("#abLog-list").append("<li>No results</li>"); }               }                loadCompleted; loadLock = false; });       }        apiQuery({ meta: "siteinfo", siprop: "extensions", }, 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 not enabled"); return; }       });        $("#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 + ")" : ""); });       $("#ab-checkIfPagesExistToggle").click(function { config.checkIfPagesExist = !config.checkIfPagesExist; $(this).text(config.checkIfPagesExist ? "Don't check" : "Check"); });       $("#ab-autoRefreshToggle").click(function  { config.autoRefresh = !config.autoRefresh; if (config.autoRefresh) { if (!refreshTimer) { refreshTimer = window.setTimeout(loadData, config.autoRefreshInterval * 1000); }           } else { if (refreshTimer) { window.clearTimeout(refreshTimer); refreshTimer = null; }           }            $(this).text(config.autoRefresh ? "off" : "on"); });       $("#ab-forceRefresh").click(refreshData);        loadMessages([ "abusefilter-log-entry", "abusefilter-log-detailedentry-meta", "abusefilter-action-block", "abusefilter-action-blockautopromote", "abusefilter-action-degroup", "abusefilter-action-disallow", "abusefilter-action-rangeblock", "abusefilter-action-tag", "abusefilter-action-throttle", "abusefilter-action-warn", "abusefilter-log-noactions", "abusefilter-log-detailedentry-local", "abusefilter-changeslist-examine", "abusefilter-log-detailslink", "wall-message-wall-shorten", "talkpagelinktext", "contribslink", "blocklink", "pipeseparator", ]).then(loadData);   }); });

// CheckWarnings (function {    "use strict";    if (window.checkWarningsActive) {        return;    }    window.checkWarningsActive = true;    var config = mw.config.get([ "wgNamespaceNumber", "wgTitle" ]);   if (config.wgNamespaceNumber != 1200) { return; }    var warningsContainer = $(" ");    var warningsList = $("</ul>");    warningsContainer.append(warningsList);    $('#mw-content-text #Wall').before(warningsContainer);    var warningsCountWikiText = " " +    "\ncategory=User warning" +    "\nprefix=" + config.wgTitle +    "\nmode=count" +    " ";    var warningsListWikitext = " " +    "\ncategory=User warning" +    "\nprefix=" + config.wgTitle +    "\nmode=list" +    "\naddauthor=true" +    "\naddcreationdate=true" +    "\naddlastedit=false" +    "\nordermethod=created" +    " ";    $.getJSON(mw.util.wikiScript("api"), { action: "parse", contentmode: "wikitext", format: "json", text: warningsCountWikiText }).done(function(response) { if (!response.error) { var count = $(response.parse.text["*"]).text; var heading = " This user has received " + (count != 0 ? count : "no") + (count == 1 ? " warning." : " warnings.") + (count != 0 ? " The warnings are provided below:" : "") + " ";           warningsContainer.prepend(heading); if (count != 0) { $.getJSON(mw.util.wikiScript("api"), {                   action: "parse",                    contentmode: "wikitext",                    format: "json",                    text: warningsListWikitext                }).done(function(response) {                    if (!response.error) {                        warningsList.append(response.parse.text["*"]);                    }                }); }       }    }); });

// sketchfab (function {    function isBoolNum(val) {        return (val == 1) || (val == 0);    }    $(".sketchfab").each(function { var sketchfab = $(this); var sketchId = sketchfab.find("#sketch-id"); var width = sketchfab.find("#width"); var height = sketchfab.find("#height"); var transparent = sketchfab.find("#transparent"); var autostart = sketchfab.find("#autostart"); var autospin = sketchfab.find("#autospin"); if (!sketchId) { return; } if (!sketchId.text) { return; } sketchId = sketchId.text; width = width ? parseInt(width.text, "10") : "300" ; height = height ? parseInt(height.text, "10") : "300"; transparent = transparent ? transparent.text : "1"; autostart = autostart ? autostart.text : "0"; autospin = autospin ? autospin.text : "0"; transparent = isBoolNum(transparent) || "1"; autostart = isBoolNum(autostart) || "0"; autospin = isBoolNum(autospin) || "0"; var sketchfabEmbed = "<iframe " + "class='sketchfab-embed' " + "src='https://sketchfab.com/models/" + sketchId + "/embed?transparent=" + transparent + "&autostart=" + autostart + "&autospin" + autospin + "' " + "width='" + width + "' " + "height='" + height + "' " + "allowvr= allowfullscreen= mozallowfullscreen= webkitallowfullscreen= onmousewheel='' frameborder='0'" + "> ";       sketchfab.after(sketchfabEmbed); sketchfab.remove; }); });