aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/whatsapp/webview-unsafe.js
blob: b6b365b703e05ab855099084765d9305c30209df (plain) (blame)
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
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;
}