diff --git a/geofs-alarms.user.js b/geofs-alarms.user.js index c2957d4..c5af85b 100644 --- a/geofs-alarms.user.js +++ b/geofs-alarms.user.js @@ -2,57 +2,36 @@ // @name GeoFS-Alarms // @icon https://www.geo-fs.com/favicon.ico // @namespace https://github.com/Daviduss01/geofs-alarms -// @version 0.1.6 +// @version 0.1.7 // @description Adds cockpit alarm sounds to GeoFS online flight simulator -// @author PEK-97, Supreme1707, Winston_Sung, Daviduss01 +// @author Daviduss01, PEK-97, python-coding-404, Supreme1707, Winston_Sung // @match https://*.geo-fs.com/geofs.php* -// @grant GM.getResourceUrl -// @resource stall https://github.com/Daviduss01/geofs-alarms/raw/master/stall.ogg -// @resource bankangle https://github.com/Daviduss01/geofs-alarms/raw/master/bankangle.ogg -// @resource overspeed https://github.com/Daviduss01/geofs-alarms/raw/master/overspeed.ogg -// @resource terain_pull_up https://github.com/Daviduss01/geofs-alarms/raw/master/terain_pull_up.mp3 -// @resource sinkrate_pull_up https://github.com/Daviduss01/geofs-alarms/raw/master/sinkrate_pull_up.mp3 // ==/UserScript== (function () { 'use strict'; // Load the audio clips - let stickShake; - GM.getResourceUrl("stall").then( - (data) => { - stickShake = new Audio(data); - stickShake.loop = true; - } - ); - let bankangleClacker; - GM.getResourceUrl("bankangle").then( - (data) => { - bankangleClacker = new Audio(data); - bankangleClacker.loop = true; - } - ); - let overspeedClacker; - GM.getResourceUrl("overspeed").then( - (data) => { - overspeedClacker = new Audio(data); - overspeedClacker.loop = true; - } - ); - let terainPullUpClacker; - GM.getResourceUrl("terain_pull_up").then( - (data) => { - terainPullUpClacker = new Audio(data); - terainPullUpClacker.loop = true; - } - ); - let sinkratePullUpClacker; - GM.getResourceUrl("sinkrate_pull_up").then( - (data) => { - sinkratePullUpClacker = new Audio(data); - sinkratePullUpClacker.loop = true; - } - ); + + let terainPullUpClacker = new Audio("https://github.com/Daviduss01/geofs-alarms/raw/master/terain_pull_up.mp3"); + terainPullUpClacker.type = "audio/mpeg"; + terainPullUpClacker.loop = true; + + let bankangleClacker = new Audio("https://github.com/Daviduss01/geofs-alarms/raw/master/bankangle.ogg"); + bankangleClacker.type = "audio/ogg"; + bankangleClacker.loop = true; + + let overspeedClacker = new Audio("https://github.com/Daviduss01/geofs-alarms/raw/master/overspeed.ogg"); + overspeedClacker.type = "audio/ogg"; + overspeedClacker.loop = true; + + let sinkratePullUpClacker = new Audio("https://github.com/Daviduss01/geofs-alarms/raw/master/sinkrate_pull_up.mp3"); + sinkratePullUpClacker.type = "audio/mpeg"; + sinkratePullUpClacker.loop = true; + + let stickShake = new Audio("https://github.com/Daviduss01/geofs-alarms/raw/master/stall.ogg"); + stickShake.type = "audio/ogg"; + stickShake.loop = true; // Wait until flight sim is fully loaded let itv = setInterval( @@ -66,13 +45,42 @@ ); function main() { + let prevAudioOn = false; + + // Monkey-patch the togglePause method + // This is required as setAnimationValue won't be called during togglePause, + // making the audio unexpectedly playing continuously. + unsafeWindow.geofs.togglePause = function () { + let cached_togglePause = unsafeWindow.geofs.togglePause; + + return function () { + let result = cached_togglePause.apply(this, arguments); + + if (unsafeWindow.geofs.pause) { + prevAudioOn = false; + + terainPullUpClacker.pause(); + terainPullUpClacker.currentTime = 0; + bankangleClacker.pause(); + bankangleClacker.currentTime = 0; + overspeedClacker.pause(); + overspeedClacker.currentTime = 0; + sinkratePullUpClacker.pause(); + sinkratePullUpClacker.currentTime = 0; + stickShake.pause(); + stickShake.currentTime = 0; + } + + return result; + }; + } (); + // Monkey-patch the setAnimationValue method // - Altitude too low // - Overbanked angle // - Overspeed // - Sinkrate // - Stalling - let prevAudioOn = false; let prevAltTooLow = false; let prevOverbankedAng = false; let prevOversped = false;