aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/whatsapp/webview-unsafe.js
diff options
context:
space:
mode:
authorLibravatar Fernando Figueiredo <fernando.fig@gmail.com>2022-07-03 12:02:06 -0300
committerLibravatar GitHub <noreply@github.com>2022-07-03 15:02:06 +0000
commitefec7e7c6bdd3953bae1936b9ecb2d98b2dac842 (patch)
tree3ada279dcc95a8ed3572b619cb86cf2b4332c8ef /recipes/whatsapp/webview-unsafe.js
parentUpgrade 'pnpm' to '7.4.1' (diff)
downloadferdium-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.js42
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 @@
1const PUSHSTATE_NORMAL = 0;
2const PUSHSTATE_THROTTLE = 1;
3const PUSHSTATE_DISABLE = 2;
4
5const PUSHSTATE_THROTTLE_THRESHOLD = 1;
6
7window.shPushState = window.history.pushState;
8//window.pushStateBehavior = PUSHSTATE_NORMAL;
9window.pushStateBehavior = PUSHSTATE_THROTTLE;
10window.pushStateCount = 0;
11
12function 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
30function pushStateOneShot() {
31 window.shPushState.apply(window.history, arguments);
32
33 window.history.pushState = function() {};
34
35 console.log("Pushstate Disabled!");
36}
37
38if (window.pushStateBehavior != PUSHSTATE_NORMAL)
39{
40 window.history.pushState =
41 window.pushStateBehavior == PUSHSTATE_THROTTLE ? pushStateThrottled : pushStateOneShot;
42}