User:ASMCHK/common.js

/* jshint esversion: 5, esnext: false, forin: true, immed: true, indent: 4, latedef: true, newcap: true, noarg: true, undef: true, unused: true, browser: true, jquery: true, onevar: true, eqeqeq: true, multistr: true, maxerr: 999999, forin: false, -W082, -W084 /* global mw, URLSearchParams */ mw.loader.using(["mediawiki.api"]).then(function {    "use strict";    var playSounds = [{        sound: "File:Ambient Caves.mp3",        pages: ["Gunpowder Mines"]    }];    var conf = mw.config.get([ "wgPageName", "wgNamespaceNumber", "wgAction" ]);

function play(soundfile) { fetch("https://hypixel-skyblock.fandom.com/api.php?" + new URLSearchParams({ action: 'query', format: 'json', prop: 'imageinfo', iiprop: 'url', titles: soundfile })).then(function (response) {           return response.json;        }).then(function (data) {            var url = data.query.pages[Object.keys(data.query.pages)[0]].imageinfo[0].url;            var myAudio = new Audio(url);            myAudio.addEventListener("canplaythrough", function  { myAudio.play; });       });    }

function selectMusic { // Music Selection for (var i in playSounds) { for (var j in playSounds[i].pages) { if (conf.wgPageName === playSounds[i].pages[j]) return playSounds[i].sound; }       }        return false; }

if (conf.wgNamespaceNumber !== 0 || conf.wgAction !== "view") return; var music = selectMusic; console.log("Selected music: " + muisc); if (music) { play(music); } });