From c9ebc53dfb695e9661e345ad795ea7f1a32e6875 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sun, 9 Nov 2014 13:54:47 -0800 Subject: [PATCH] Allow setting initial values from url --- winamp.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/winamp.js b/winamp.js index c5469d04..20ccee8c 100755 --- a/winamp.js +++ b/winamp.js @@ -491,7 +491,27 @@ document.onkeyup = function(e){ } } +function anchorArgument(argument, defaultValue) { + args = []; + pairs = window.location.hash.slice(1).split("&"); + for (var i = 0, len = pairs.length; i < len; i++) { + pair = pairs[i]; + eq = pair.indexOf("="); + if(eq) { + key = pair.slice(0, eq); + value = pair.slice(eq + 1); + args[key] = value; + } + } + return args[argument] ? args[argument] : defaultValue; +} + +volume = anchorArgument('volume', 50); +balance = anchorArgument('volume', 0); +file = anchorArgument('m', 'https://mediacru.sh/download/Q2HAoRHE-JvD.mp3'); +fileName = anchorArgument('name', "1. DJ Mike Llama - Llama Whippin' Intro <0:05>"); + winamp = new Winamp(); -winamp.setVolume(50); -winamp.setBalance(0); -winamp.loadFile('https://mediacru.sh/download/Q2HAoRHE-JvD.mp3', "1. DJ Mike Llama - Llama Whippin' Intro <0:05>"); +winamp.setVolume(volume); +winamp.setBalance(balance); +winamp.loadFile(file, fileName);