-
Notifications
You must be signed in to change notification settings - Fork 1
/
volume-slider.min.js
9 lines (9 loc) · 1.42 KB
/
volume-slider.min.js
1
2
3
4
5
6
7
8
9
// volume slider, by chapel; for sugarcube 2
!function(){function e(e){"number"!=typeof e&&(e=+e),(Number.isNaN(e)||0>e)&&(e=0),e>1&&(e=1)
try{if(!SimpleAudio)throw Error("Cannot access audio API.")
"function"==typeof SimpleAudio.volume?SimpleAudio.volume(e):SimpleAudio.volume=e}catch(t){console.error(t.message,t),$.wiki("<<masteraudio volume "+e+">>")}finally{return e}}function t(){var t=settings.volume/a.rangeMax
a.current=t.toFixed(2),e(a.current)}var n={},a={current:100,rangeMax:100,step:1,setting:!0}
n.last=a.current,n.start=n.last/a.rangeMax,postdisplay["volume-task"]=function(t){delete postdisplay[t],e(n.start.toFixed(2))},$(document).on("input","input[name=volume]",function(){var t=$("input[name=volume]").val(),o=t/a.rangeMax
a.current=o.toFixed(2),e(a.current),n.last=t}),Macro.add("volume",{handler:function(){var e=$(document.createElement("span")),t=$(document.createElement("input")),o="macro-"+this.name
t.attr({id:"volume-control",type:"range",name:"volume",min:"0",max:a.rangeMax,step:a.step,value:n.last}),e.append(t).addClass(o).appendTo(this.output)}}),a.setting&&(Setting&&Setting.addRange&&"function"==typeof Setting.addRange?Setting.addRange("volume",{label:"Volume: ",min:0,max:a.rangeMax,step:a.step,"default":a.current,onInit:t,onChange:t}):console.error("This version of SugarCube does not include the `Settings.addRange()` method; please try updating to the latest version of SugarCube."))}()
// end volume slider