blob: 7382f3da0edf5b93cd23156e59f16b5e5ef7265e (
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
|
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 {
// eslint-disable-next-line no-console
console.log('Pushstate temporarily blocked!');
}
}
function pushStateOneShot() {
window.shPushState.apply(window.history, arguments);
window.history.pushState = function () {};
// eslint-disable-next-line no-console
console.log('Pushstate Disabled!');
}
if (window.pushStateBehavior != PUSHSTATE_NORMAL) {
window.history.pushState =
window.pushStateBehavior == PUSHSTATE_THROTTLE
? pushStateThrottled
: pushStateOneShot;
}
|