diff options
author | 2022-07-03 12:02:06 -0300 | |
---|---|---|
committer | 2022-07-03 15:02:06 +0000 | |
commit | efec7e7c6bdd3953bae1936b9ecb2d98b2dac842 (patch) | |
tree | 3ada279dcc95a8ed3572b619cb86cf2b4332c8ef /recipes/whatsapp/webview-unsafe.js | |
parent | Upgrade 'pnpm' to '7.4.1' (diff) | |
download | ferdium-recipes-efec7e7c6bdd3953bae1936b9ecb2d98b2dac842.tar.gz ferdium-recipes-efec7e7c6bdd3953bae1936b9ecb2d98b2dac842.tar.zst ferdium-recipes-efec7e7c6bdd3953bae1936b9ecb2d98b2dac842.zip |
Workaround for Whatsapp Web UI lag (#94)
Diffstat (limited to 'recipes/whatsapp/webview-unsafe.js')
-rw-r--r-- | recipes/whatsapp/webview-unsafe.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/recipes/whatsapp/webview-unsafe.js b/recipes/whatsapp/webview-unsafe.js new file mode 100644 index 0000000..726014f --- /dev/null +++ b/recipes/whatsapp/webview-unsafe.js | |||
@@ -0,0 +1,42 @@ | |||
1 | const PUSHSTATE_NORMAL = 0; | ||
2 | const PUSHSTATE_THROTTLE = 1; | ||
3 | const PUSHSTATE_DISABLE = 2; | ||
4 | |||
5 | const PUSHSTATE_THROTTLE_THRESHOLD = 1; | ||
6 | |||
7 | window.shPushState = window.history.pushState; | ||
8 | //window.pushStateBehavior = PUSHSTATE_NORMAL; | ||
9 | window.pushStateBehavior = PUSHSTATE_THROTTLE; | ||
10 | window.pushStateCount = 0; | ||
11 | |||
12 | function pushStateThrottled() { | ||
13 | if (window.pushStateCount < PUSHSTATE_THROTTLE_THRESHOLD) | ||
14 | { | ||
15 | window.shPushState.apply(window.history, arguments); | ||
16 | window.pushStateCount++; | ||
17 | |||
18 | if (window.pushStateCount == PUSHSTATE_THROTTLE_THRESHOLD) | ||
19 | setTimeout(() => { | ||
20 | window.pushStateCount = 0; | ||
21 | }, | ||
22 | 5000); | ||
23 | } | ||
24 | else | ||
25 | { | ||
26 | console.log("Pushstate temporarily blocked!"); | ||
27 | } | ||
28 | } | ||
29 | |||
30 | function pushStateOneShot() { | ||
31 | window.shPushState.apply(window.history, arguments); | ||
32 | |||
33 | window.history.pushState = function() {}; | ||
34 | |||
35 | console.log("Pushstate Disabled!"); | ||
36 | } | ||
37 | |||
38 | if (window.pushStateBehavior != PUSHSTATE_NORMAL) | ||
39 | { | ||
40 | window.history.pushState = | ||
41 | window.pushStateBehavior == PUSHSTATE_THROTTLE ? pushStateThrottled : pushStateOneShot; | ||
42 | } | ||