From efec7e7c6bdd3953bae1936b9ecb2d98b2dac842 Mon Sep 17 00:00:00 2001 From: Fernando Figueiredo Date: Sun, 3 Jul 2022 12:02:06 -0300 Subject: Workaround for Whatsapp Web UI lag (#94) --- recipes/whatsapp/package.json | 2 +- recipes/whatsapp/webview-unsafe.js | 42 ++++++++++++++++++++++++++++++++++++++ recipes/whatsapp/webview.js | 3 +++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 recipes/whatsapp/webview-unsafe.js 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 @@ { "id": "whatsapp", "name": "WhatsApp", - "version": "3.4.1", + "version": "3.4.2", "license": "MIT", "config": { "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 @@ +const PUSHSTATE_NORMAL = 0; +const PUSHSTATE_THROTTLE = 1; +const PUSHSTATE_DISABLE = 2; + +const PUSHSTATE_THROTTLE_THRESHOLD = 1; + +window.shPushState = window.history.pushState; +//window.pushStateBehavior = PUSHSTATE_NORMAL; +window.pushStateBehavior = PUSHSTATE_THROTTLE; +window.pushStateCount = 0; + +function pushStateThrottled() { + if (window.pushStateCount < PUSHSTATE_THROTTLE_THRESHOLD) + { + window.shPushState.apply(window.history, arguments); + window.pushStateCount++; + + if (window.pushStateCount == PUSHSTATE_THROTTLE_THRESHOLD) + setTimeout(() => { + window.pushStateCount = 0; + }, + 5000); + } + else + { + console.log("Pushstate temporarily blocked!"); + } +} + +function pushStateOneShot() { + window.shPushState.apply(window.history, arguments); + + window.history.pushState = function() {}; + + console.log("Pushstate Disabled!"); +} + +if (window.pushStateBehavior != PUSHSTATE_NORMAL) +{ + window.history.pushState = + window.pushStateBehavior == PUSHSTATE_THROTTLE ? pushStateThrottled : pushStateOneShot; +} 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 => { Ferdium.setBadge(count, indirectCount); }; + // inject webview hacking script + Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); + const getActiveDialogTitle = () => { const element = document.querySelector('header .emoji-texttt'); -- cgit v1.2.3-70-g09d2