MediaWiki:Mobile.js

/* Any JavaScript here will be loaded for users using the mobile site */

/* a bug prevents Mobile.css from loading, this fixes it */ mw.loader.using('mobile.site.styles')

// Made by FunPL with slight help from google

// Utility functions

window.resolveID=function(id){ var replaced = id.replaceAll(".26","&"); replaced = replaced.replaceAll(".21","!"); replaced = replaced.replaceAll(".28","(");   replaced = replaced.replaceAll(".29",")"); replaced = replaced.replaceAll(".CF.89","ω"); replaced = replaced.replaceAll(".7E","~"); replaced = replaced.replaceAll(".27","'"); replaced = replaced.replaceAll(".40","@"); replaced = replaced.replaceAll(".23","#"); replaced = replaced.replaceAll(".24","$"); replaced = replaced.replaceAll(".25","%"); return replaced; }; String.prototype.replaceAll = function(search, replacement) { var target = this; return target.split(search).join(replacement); };

var firstParse = true;

window.parseApi=function(parsetext, fn) { if (firstParse) { setTimeout(parseApi, 1000, parsetext, fn) setTimeout(function {           firstParse = false        }, 900) return }   new mw.Api.get({        action: 'parse',        text: parsetext,        title: mw.config.values.wgPageName,    }).done(function(data) {        const wikitext = data.parse.text['*'];        if (wikitext) {            fn(wikitext);        } else {            fn("")        }    }); };

window.parseApiAdd=function(parsetext, add, fn) { if (firstParse) { setTimeout(parseApiAdd, 1000, parsetext, add, fn) setTimeout(function {           firstParse = false        }, 900) return }   new mw.Api.get({        action: 'parse',        text: parsetext,        title: mw.config.values.wgPageName,    }).done(function(data) {        const wikitext = data.parse.text['*'];        if (wikitext) {            fn(wikitext, add);        } else {            fn("", null)        }    }); };

// Audio players

// Initialize all load buttons

// Load/Unload var unloadedtext = "Load "; var loadels = document.getElementsByClassName("load-media"); var loadmediadata = {}; [].forEach.call(loadels, function(el) {   var nr = 0;    if(el.children[nr] == null){        el.innerHTML = "Error! Please report this"    }    if(el.children[nr].nodeName != "P"){        nr = 1;        if(el.children[nr] == null){            el.innerHTML = "Error! Please report this"        }    }    el.id = el.id + '|' + el.children[nr].children[1].innerHTML;    var loadname = el.children[nr].children[0].innerHTML;    if(loadname == ""){        loadname = "media"    }    loadmediadata[el.id] = loadname;    el.innerHTML = unloadedtext + el.id + unloadedtext2 + loadname + " ";    el.classList.add("load-media-group-"+loadname) });

// Load/Unload all var loadalltext = "Load all "; var unloadalltext = "Unload all "; var allels = document.getElementsByClassName("loadall-media"); var allels2 = document.getElementsByClassName("unloadall-media"); [].forEach.call(allels, function(el) {   var group = el.parentElement.classList[0].split("-")[3]    if(group == ""){        group = "media";    }    el.innerHTML = loadalltext + group + " files "; }); [].forEach.call(allels2, function(el) {   var group = el.parentElement.classList[0].split("-")[3]    if(group == ""){        group = "media";    }    el.innerHTML = unloadalltext + group + " files "; });

window.loadmedia=function(text) { try { var loadname = loadmediadata[text.id]; if (text.innerHTML == unloadedtext + text.id + unloadedtext2 + loadname + " ") { text.innerHTML = "Wait "; var id = resolveID(text.id); console.log(text.id); console.log(id); parseApi("" + id + "", function(wikitext) {               text.innerHTML = "Unload "+loadname+" " + " " + wikitext;            }); } else { text.innerHTML = unloadedtext + text.id + unloadedtext2 + loadname + " "; }   } catch (error) { text.innerHTML = "Error "; console.error(error); } }; window.loadallmedia=function(allel) { try { if(allel.parentElement.parentElement.classList[0] != "loadall-media-group-"){ var group = allel.parentElement.parentElement.classList[0].split("-")[3]; var thisloadels = document.getElementsByClassName("load-media-group-"+group) }       else{ var thisloadels = loadels; }       [].forEach.call(thisloadels, function(el) {            loadforce(el)        }); } catch (error) { console.error(error); } };

window.unloadallmedia=function(allel) { try { if(allel.parentElement.parentElement.classList[0] != "loadall-media-group-"){ var group = allel.parentElement.parentElement.classList[0].split("-")[3]; var thisloadels = document.getElementsByClassName("load-media-group-"+group) }       else{ var thisloadels = loadels; }       [].forEach.call(thisloadels, function(el) {            unloadforce(el)        }); } catch (error) { console.error(error); } };

window.loadforce=function(text) { try { var loadname = loadmediadata[text.id]; if (text.innerHTML == unloadedtext + text.id + unloadedtext2 + loadname + " ") { text.innerHTML = "Wait "; var id = resolveID(text.id); console.log(text.id); console.log(id); parseApi("" + id + "", function(wikitext) {               text.innerHTML = "Unload "+loadname+" " + " " + wikitext;            }); }   } catch (error) { text.innerHTML = "Error "; console.error(error); } };

window.unloadforce=function(text) { try { var loadname = loadmediadata[text.id]; if (text.innerHTML != unloadedtext + text.id + unloadedtext2 + loadname + " ") { text.innerHTML = unloadedtext + text.id + unloadedtext2 + loadname + " "; }   } catch (error) { text.innerHTML = "Error "; console.error(error); } };

// ================================================================================ // Interactive Music Code // ================================================================================

// Set an onclick handler for opening the filters tab

$(".i-menu-filter").click(function{	if($(this).next.css("display") == "none"){		$(this).next.css("display", "block")		$(this).css("background", "#aaaaaa")	}	else{		$(this).next.css("display", "none")		$(this).css("background", "")	} })

// Set an onclick handler for checking boxes

$(".i-checkbox").click(function{	if($(this).children.css("opacity") == "0"){		$(this).children.css("opacity", "1")		if($(this).hasClass("i-category")){			icheckboxes;		}	}	else{		$(this).children.css("opacity", "0")		if($(this).hasClass("i-category")){			icheckboxes;		}	} })

// Handle refreshing the music list based on selected filters

function icheckboxes{ var allclass = []; var classStatus = {}; $(".i-checkbox.i-category").each(function{       var classes = $(this)[0].classList;        for(var i = 0, len = classes.length;i<len;i++){            var curr = classes[i];            if(curr.startsWith("i-category-")){                if(allclass.indexOf(curr) == -1){                    allclass[allclass.length] = curr;                    classStatus[curr] = $(this).children.css("opacity");                }            }        }    }) var select = "." + allclass.join(", ."); $(select).each(function{       if($(this).hasClass("i-checkbox")){            return;        }        var classes = $(this)[0].classList;        var status = 1;        for(var i = 0, len = classes.length;i<len;i++){            var curr = classes[i];            if(curr.startsWith("i-category-")){                if(classStatus[curr] == 0){                    status = 0;                }            }        }        if(status == 1){            status = ""        }        else{            status = "none"        }        $(this).css("display", status)    }) }

// ================================================================================ // Page specific JS/CSS // ================================================================================

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

function checkPage(type, exist) { if (exist == null) { new mw.Api.get({           action: 'parse',            page: type,            prop: ""        }).done(function (data) {            checkPage(type, true)        }).fail(function (data) {            checkPage(type, false)        }); }   else if (exist) { if (getTypeByValue(type).endsWith("JS")) { mw.loader.load('/w/index.php?title=' + pageEnc(type) + '&action=raw&ctype=text/javascript'); }       else { mw.loader.load('/w/index.php?title=' + pageEnc(type) + '&action=raw&ctype=text/css', 'text/css'); }       checkNextPage(type) }   else if (!exist) { checkNextPage(type) } }

function checkNextPage(type) { switch (type) { case pageTypes.globalJS: checkPage(pageTypes.globalCSS); break; case pageTypes.globalCSS: checkPage(pageTypes.skinJS); break; case pageTypes.skinJS: checkPage(pageTypes.skinCSS); break; case pageTypes.skinCSS: if (mw.config.get("wgUserName") != null) { checkPage(pageTypes.userJS); }           break; case pageTypes.userJS: if (mw.config.get("wgUserName") != null) { checkPage(pageTypes.userCSS); }           break; case pageTypes.userCSS: if (mw.config.get("wgUserName") != null) { checkPage(pageTypes.userSkinJS); }           break; case pageTypes.userSkinJS: if (mw.config.get("wgUserName") != null) { checkPage(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 {    checkPage(pageTypes.globalJS); });

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