User:Fumple/common.js

/* Made by FunPL with slight help from google */ /* Audio players */

/*Initialize all load buttons*/

/*Load/Unload*/ var unloadedtext = "Load audio "; var loadels = document.getElementsByClassName("load-music"); [].forEach.call(loadels, function (el) {el.innerHTML=unloadedtext+el.id+unloadedtext2;});

/*Load/Unload all*/ var loadalltext = "Load all audio tracks "; var unloadalltext = "Unload all audio tracks "; var allels = document.getElementsByClassName("loadall-music"); var allels2 = document.getElementsByClassName("unloadall-music"); [].forEach.call(allels, function (el) {el.innerHTML=loadalltext;}); [].forEach.call(allels2, function (el) {el.innerHTML=unloadalltext;});

function loadaudio(text){ try{ var api = new mediaWiki.Api; if(text.innerHTML == unloadedtext+text.id+unloadedtext2){ text.innerHTML = "Wait "; var id = resolveID(text.id); console.log(text.id); console.log(id); new mw.Api.get({               action: 'parse',                text: ""+id+"",                title: mw.config.values.wgPageName,            }).done(function (data) {                const wikitext = data.parse.text['*'];                if (wikitext)                    text.innerHTML = "Unload audio "+" "+wikitext;            }); }       else{ text.innerHTML = unloadedtext+text.id+unloadedtext2; }   }catch(error){ text.innerText = "Error "; console.error(error); } }

function loadall{ try{ [].forEach.call(loadels, function (el) {load(el)}); }catch(error){ console.error(error); } }

function unloadall{ try{ [].forEach.call(loadels, function (el) {unload(el)}); }catch(error){ console.error(error); } }

function load(text){ try{ var api = new mediaWiki.Api; if(text.innerHTML == unloadedtext+text.id+unloadedtext2){ text.innerHTML = "Wait "; var id = resolveID(text.id); console.log(text.id); console.log(id); new mw.Api.get({               action: 'parse',                text: ""+id+"",                title: mw.config.values.wgPageName,            }).done(function (data) {                const wikitext = data.parse.text['*'];                if (wikitext)                    text.innerHTML = "Unload audio "+" "+wikitext;            }); }   }catch(error){ text.innerText = "Error "; console.error(error); } }

function unload(text){ try{ if(text.innerHTML != unloadedtext+text.id+unloadedtext2){ text.innerHTML = unloadedtext+text.id+unloadedtext2; }   }catch(error){ text.innerText = "Error "; console.error(error); } } function resolveID(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); };