aboutsummaryrefslogtreecommitdiffstats
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
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)
-rw-r--r--recipes/whatsapp/package.json2
-rw-r--r--recipes/whatsapp/webview-unsafe.js42
-rw-r--r--recipes/whatsapp/webview.js3
3 files changed, 46 insertions, 1 deletions
diff --git a/recipes/whatsapp/package.json b/recipes/whatsapp/package.json
index 5c70df9..3693582 100644
--- a/recipes/whatsapp/package.json
+++ b/recipes/whatsapp/package.json
@@ -1,7 +1,7 @@
1{ 1{
2 "id": "whatsapp", 2 "id": "whatsapp",
3 "name": "WhatsApp", 3 "name": "WhatsApp",
4 "version": "3.4.1", 4 "version": "3.4.2",
5 "license": "MIT", 5 "license": "MIT",
6 "config": { 6 "config": {
7 "serviceURL": "https://web.whatsapp.com", 7 "serviceURL": "https://web.whatsapp.com",
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}
diff --git a/recipes/whatsapp/webview.js b/recipes/whatsapp/webview.js
index 3586e14..180be79 100644
--- a/recipes/whatsapp/webview.js
+++ b/recipes/whatsapp/webview.js
@@ -36,6 +36,9 @@ module.exports = Ferdium => {
36 Ferdium.setBadge(count, indirectCount); 36 Ferdium.setBadge(count, indirectCount);
37 }; 37 };
38 38
39 // inject webview hacking script
40 Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js'));
41
39 const getActiveDialogTitle = () => { 42 const getActiveDialogTitle = () => {
40 const element = document.querySelector('header .emoji-texttt'); 43 const element = document.querySelector('header .emoji-texttt');
41 44