User:Fumple/common.js

//Page-specific script //Define vars var mwSkin = mw.config.get("skin") var pageTypes = {}; pageTypes.globalJS = 'MediaWiki:Common.js/' + mw.config.get("wgPageName") + ".js"; pageTypes.globalCSS = 'MediaWiki:Common.css/' + mw.config.get("wgPageName") + ".css"; pageTypes.skinJS = 'MediaWiki:' + mwSkin + '.js/' + mw.config.get("wgPageName") + ".js"; pageTypes.skinCSS = 'MediaWiki:' + mwSkin + '.css/' + mw.config.get("wgPageName") + ".css"; pageTypes.userJS = 'User:' + mw.config.get("wgUserName") + '/common.js/' + mw.config.get("wgPageName") + ".js"; pageTypes.userCSS = 'User:' + mw.config.get("wgUserName") + '/common.css/' + mw.config.get("wgPageName") + ".css"; pageTypes.userSkinJS = 'User:' + mw.config.get("wgUserName") + '/' + mwSkin + '.js/' + mw.config.get("wgPageName") + ".js"; pageTypes.userSkinCSS = 'User:' + mw.config.get("wgUserName") + '/' + mwSkin + '.css/' + mw.config.get("wgPageName") + ".css";

function userCheckPage(type, exist) { if (exist == null) { new mw.Api.get({           action: 'parse',            page: type,            prop: ""        }).done(function (data) {            userCheckPage(type, true)        }).fail(function (data) {            userCheckPage(type, false)        }); }   else if (exist) { $("#p-namespaces ul").append(' ' + getTypeByValue(type) + ' '); userCheckNextPage(type) }   else if (!exist) { $("#p-namespaces ul").append(' ' + getTypeByValue(type) + ' '); userCheckNextPage(type) } }

function userCheckNextPage(type) { switch (type) { case pageTypes.globalJS: userCheckPage(pageTypes.globalCSS); break; case pageTypes.globalCSS: userCheckPage(pageTypes.skinJS); break; case pageTypes.skinJS: userCheckPage(pageTypes.skinCSS); break; case pageTypes.skinCSS: if (mw.config.get("wgUserName") != null) { userCheckPage(pageTypes.userJS); }           break; case pageTypes.userJS: if (mw.config.get("wgUserName") != null) { userCheckPage(pageTypes.userCSS); }           break; case pageTypes.userCSS: if (mw.config.get("wgUserName") != null) { userCheckPage(pageTypes.userSkinJS); }           break; case pageTypes.userSkinJS: if (mw.config.get("wgUserName") != null) { userCheckPage(pageTypes.userSkinCSS); }           break; } }

function pageEnc(string) { return encodeURIComponent(string); }

function getTypeByValue(value) { return Object.keys(pageTypes).find(function (key) { return pageTypes[key] === value }); }

//Check page specific files onApiReady(function {    userCheckPage(pageTypes.globalJS); });

function onApiReady(callback) { if (mw.Api != null) { setTimeout(callback, 0); } else { setTimeout(onApiReady.bind(null, callback), 0); } }

//PRETTY VISIBLE NOTICES /* */

//Check notices var user = mw.config.get("wgUserName"); if (user != null) { waitForApi; }

function showNotice{ console.log("Ready to show") new mw.Api.get({       "action": "parse",        "format": "json",        "page": "MediaWiki:Notice/"+user,        "prop": "text"    }).done(function (data) {        console.log("Got notice")        //Create        var el = document.createElement("div");        var el2 = document.createElement("div");        var el2center = document.createElement("div");        var el2button = document.createElement("div");        //el        el.style.position = "absolute";        el.style.top = "0";        el.style.left = "0";        el.style.height = "100%";        el.style.width = "100%";        el.style.background = "#000";        el.style.opacity = "0.5";        //el2        el2.style.position = "absolute";        el2.style.top = "0";        el2.style.left = "0";        el2.style.height = "100%";        el2.style.width = "100%";        el2.style.display = "flex";        el2.style.alignItems = "center"; el2.style.justifyContent = "center"; //el2center el2center.style.width = "40%"; el2center.style.fontFamily = '"Lucida Sans Unicode", "Lucida Grande", sans-serif'; el2center.style.padding = "20px"; el2center.style.background = "#DDDDDD"; //el2button el2button.style.padding = "10px"; el2button.style.background = "#0000FF"; el2button.style.cursor = "pointer"; el2button.style.color = "#DDDDDD"; el2button.style.width = "min-content"; el2button.style.border = "2px solid #DDDDDD"; el2button.style.marginLeft = "auto"; el2button.innerText = "Dismiss"; el2button.onclick = function(e){ e.target.innerText = "Please wait"; new mw.Api.get({               "action": "query",                "format": "json",                "meta": "tokens"            }).done(function(data){                var token = data.query.tokens.csrftoken;                new mw.Api.post({ "action": "edit", "format": "json", "title": "User:FunPL/Notice", "text": "Notice seen. (AUTO EDIT) ~", "summary": "Notice seen. Auto edit.", "minor": 1, "watchlist": "unwatch", "token": token }).done(function(data){ el.remove; el2.remove; document.body.style.overflowY = ""; }).fail(function(data){ e.target.innerText = "Error!"; setTimeout(function{                       el.remove;                        el2.remove;                        document.body.style.overflowY = "";                    }, 2000) })           }).fail(function(data){                e.target.innerText = "Error!";                setTimeout(function{ el.remove; el2.remove; document.body.style.overflowY = ""; }, 2000)           })        }

el2center.innerHTML = " Notice "; el2center.innerHTML += data.parse.text["*"]; el2center.innerHTML += " "; el2.appendChild(el2center); el2center.appendChild(el2button); document.body.appendChild(el); document.body.appendChild(el2); window.scrollTo(0, 0); document.body.style.overflowY = "hidden" }) } function waitForApi{   if(typeof mw.Api !== "undefined"){        new mw.Api.get({ "action": "parse", "format": "json", "page": "User:"+user+"/Notice", "prop": "text|wikitext" }).done(function(data){ if(data.parse.wikitext["*"] == ""){ showNotice; }           else{ console.log("Not showing notice. Seen") }       }).fail(function(data){ showNotice; })   }    else{        setTimeout(waitForApi, 250);    } }

/* */

/* Dark mode */