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