forked from fengshuo2004/geofs-alarms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeofs-alarms.user.js
67 lines (66 loc) · 2.31 KB
/
geofs-alarms.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// ==UserScript==
// @name GeoFS-Alarms
// @namespace https://github.com/fengshuo2004/geofs-alarms
// @version 0.1.2
// @description Adds cockpit alarm sounds to GeoFS online flight simulator
// @author PEK-97
// @match https://www.geo-fs.com/geofs.php*
// @grant GM.getResourceUrl
// @resource stall https://github.com/fengshuo2004/geofs-alarms/raw/master/stall.ogg
// @resource bankangle https://github.com/fengshuo2004/geofs-alarms/raw/master/bankangle.ogg
// @resource overspeed https://github.com/fengshuo2004/geofs-alarms/raw/master/overspeed.ogg
// ==/UserScript==
(function () {
'use strict';
// load the audio clips
let stickShake;
GM.getResourceUrl("stall").then(
(data)=>{
stickShake = new Audio(data);
stickShake.loop = true;
}
);
let overspeedClacker;
GM.getResourceUrl("overspeed").then(
(data) => {
overspeedClacker = new Audio(data);
overspeedClacker.loop = true;
}
);
// wait until flight sim is fully loaded
let itv = setInterval(
function(){
if(unsafeWindow.ui && unsafeWindow.flight){
main();
clearInterval(itv);
}
}
,500);
function main(){
// monkey-patch the stall.setVisibility method
let prevStalled = false;
unsafeWindow.ui.hud.stall.setVisOld = unsafeWindow.ui.hud.stall.setVisibility;
unsafeWindow.ui.hud.stall.setVisibility = function (a) {
if (a) {
stickShake.play();
} else if (prevStalled) {
stickShake.pause();
}
prevStalled = a;
this.setVisOld(a);
}
// monkey-patch the setAnimationValue method
let prevOversped = false;
unsafeWindow.flight.setAniValOld = unsafeWindow.flight.setAnimationValues;
unsafeWindow.flight.setAnimationValues = function(a) {
this.setAniValOld(a);
let hasOversped = unsafeWindow.geofs.animation.values.kias >= 350;
if (hasOversped && !prevOversped){
overspeedClacker.play();
} else if (!hasOversped && prevOversped){
overspeedClacker.pause();
}
prevOversped = hasOversped;
}
}
})();