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 "; new mw.Api.get({               action: 'parse',                text: "autoplay",                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 "; new mw.Api.get({               action: 'parse',                text: ""+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); } }