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"]    },    {        sound: "File:Sky of Trees.mp3",        pages: ["The Park"]    },    {        sound: "File:Abstract Ringing.mp3",        pages: ["Wilderness"]    },    {        sound: "File:Hallow Hallow.mp3",        pages: ["Spooky Festival"]    },    {        sound: "File:Let Them Eat Cake.mp3",        pages: ["Jerry's Workshop"]    },    {        sound: "File:Dwarven Mines.mp3",        pages: ["Dwarven Mines"]    },    {        sound: "File:Journey in the Sky.mp3",        pages: ["Spider's Den"]    },    {        sound: "File:Light From Afar.mp3",        pages: ["The Barn", "Mushroom Desert"]    },    {        sound: "File:Going Even Deeper.mp3",        pages: ["Crystal Hollows"]    },    {        sound: "File:Always Nether.mp3", pages: ["Crimson Isle"] },   {        sound: "File:Blockjitsu.mp3", pages: ["Dojo"] },   {        sound: "File:Magetown.mp3", pages: ["Scarleton"] },   {        sound: "File:Fires of Fishermen.mp3", pages: ["Blazing Volcano"] },   {        sound: "File:Forsaken Village.mp3", pages: ["Dragontail"] },   {        sound: "File:Blastin banter battle.mp3", pages: ["Defend Jerry's Workshop"] },   {        sound: "File:Mythic Warfare.mp3", pages: ["Ender Dragon"] },   {        sound: "File:Lava Kraken.mp3", pages: ["Kuudra"] },   {        sound: "File:The Watcher.mp3", pages: ["The Watcher"] },   {        sound: "File:Superior Judgement.mp3", pages: ["Bonzo"] },   {        sound: "File:Dungeon Drama.mp3", pages: ["Scarf", "The Professor", "Thorn", "Livid", "Sadan"] },   {        sound: "File:Necron Doom.mp3", pages: ["Maxor", "Storm", "Goldor", "Necron"] },   {        sound: "File:The Wither King.mp3", pages: ["The Wither King"] },   {        sound: "File:Dark and Seedy.mp3", pages: ["Dante"] }];   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.volume = 0.3;            myAudio.addEventListener("canplaythrough", function  { myAudio.play; /*               var tout = setTimeout(function {                	myAudio.volume += 0.025;                	if (myAudio.volume > 0.49)                		clearTimeout(tout);                }, 200); */           });        });    }

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

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