forked from Ephenia/Pokeclicker-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptfixerupper.user.js
76 lines (69 loc) · 2.87 KB
/
scriptfixerupper.user.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// ==UserScript==
// @name [Pokeclicker] Script Fixer Upper
// @namespace Pokeclicker Scripts
// @author Ephenia
// @description A script solely for clearing out localStorage without saves being affected. Meant to be a user friendly solution for this and or for users who aren't as tech literate.
// @copyright https://github.com/Ephenia
// @license GPL-3.0 License
// @version 1.4
// @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues
// @downloadURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/scriptfixerupper.user.js
// @updateURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/scriptfixerupper.user.js
// @match https://www.pokeclicker.com/
// @icon https://www.google.com/s2/favicons?domain=pokeclicker.com
// @grant none
// @run-at document-idle
// ==/UserScript==
function initFixerUpper() {
function clearLocalStorage() {
for (let i = 0; i < localStorage.length; i++){
const key = localStorage.key(i);
if (!key.includes('save') && !key.includes('player') && !key.includes('settings')) {
setTimeout(() => {
localStorage.removeItem(key);
}, 25)
}
setTimeout(() => {
location.reload();
}, (localStorage.length * 25) + 25)
}
}
const isDesktop = navigator.userAgent.includes('desktop');
if (!isDesktop) {
const warning = "Attempt to fix and reset script settings? This should clear out localStorage in relation to scripts and their dependencies, but should NOT affect any of your save data. You should back up your saves before doing so, just to be safe. Press OK to proceed!\r\n\r\nNote: This process may take a few seconds to complete and the page should reload when complete.";
if (confirm(warning) == true) {
clearLocalStorage();
}
} else {
//we'll add logic for Desktop client here later for how we want to handle it
}
}
function loadScript(){
var oldInit = Preload.hideSplashScreen
Preload.hideSplashScreen = function(){
var result = oldInit.apply(this, arguments)
setTimeout(() => {
initFixerUpper()
}, 3000)
return result
}
}
var scriptName = 'scriptfixerupper'
if (document.getElementById('scriptHandler') != undefined){
var scriptElement = document.createElement('div')
scriptElement.id = scriptName
document.getElementById('scriptHandler').appendChild(scriptElement)
if (localStorage.getItem(scriptName) != null){
if (localStorage.getItem(scriptName) == 'true'){
loadScript()
}
}
else{
localStorage.setItem(scriptName, 'true')
loadScript()
}
}
else{
loadScript();
}