Skip to content

Commit

Permalink
Version 0.1.7: Fix audio problems
Browse files Browse the repository at this point in the history
> It turns out that Tampermonkey resources didn't work.

Bug: fengshuo2004#1
Bug: fengshuo2004#3
Bug: fengshuo2004#4
Bug: fengshuo2004#5
  • Loading branch information
python-coding-404 authored and winstonsung committed Dec 16, 2024
1 parent 4f0332b commit 7c2c869
Showing 1 changed file with 52 additions and 44 deletions.
96 changes: 52 additions & 44 deletions geofs-alarms.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand Down

0 comments on commit 7c2c869

Please sign in to comment.