-
Notifications
You must be signed in to change notification settings - Fork 261
/
simpleweatherchanger.user.js
124 lines (110 loc) · 5.32 KB
/
simpleweatherchanger.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// ==UserScript==
// @name [Pokeclicker] Simple Weather Changer
// @namespace Pokeclicker Scripts
// @author KarmaAlex (Credit: Ephenia, Optimatum)
// @description Adds a button to select the weather for the current region, also freezes all weather
// @copyright https://github.com/Ephenia
// @license GPL-3.0 License
// @version 1.4.2
// @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues
// @downloadURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/custom/simpleweatherchanger.user.js
// @updateURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/custom/simpleweatherchanger.user.js
// @match https://www.pokeclicker.com/
// @icon https://www.google.com/s2/favicons?domain=pokeclicker.com
// @grant unsafeWindow
// @run-at document-idle
// ==/UserScript==
var weatherChangerWeather;
function initWeatherChange() {
// Load selected weather
weatherChangerWeather = parseInt(localStorage.getItem('weatherChangerWeather'));
if (isNaN(weatherChangerWeather)) {
weatherChangerWeather = -1;
}
// Make selectbox
const weatherSelect = document.createElement('select');
weatherSelect.innerHTML = '<option value="-1">Default Weather</option>\n' + GameHelper.enumSelectOption(WeatherType).map((w) => `<option value="${w.value}">${w.name}</option>`).join('\n');
weatherSelect.id = 'change-weather-select';
weatherSelect.value = weatherChangerWeather;
document.querySelector('#townMap button[data-bind*="DayCycle.color"').before(weatherSelect);
document.getElementById('change-weather-select').addEventListener('change', (event) => { changeWeather(event); });
addGlobalStyle('#change-weather-select { position: absolute; right: 100px; top: 10px; width: auto; height: 20px; font-size: 9px; }');
overrideGenerateWeather();
Weather.generateWeather(new Date());
}
function changeWeather(event) {
weatherChangerWeather = +event.target.value;
Weather.generateWeather(new Date());
localStorage.setItem('weatherChangerWeather', weatherChangerWeather);
}
function overrideGenerateWeather() {
const oldGenerateWeather = Weather.generateWeather;
Weather.generateWeather = function(...args) {
if (weatherChangerWeather >= 0) {
Weather.regionalWeather.forEach((weather) => weather(weatherChangerWeather));
} else {
return oldGenerateWeather.apply(this, args);
}
}
}
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
function loadEpheniaScript(scriptName, initFunction) {
const windowObject = !App.isUsingClient ? unsafeWindow : window;
// Inject handlers if they don't exist yet
if (windowObject.epheniaScriptInitializers === undefined) {
windowObject.epheniaScriptInitializers = {};
const oldInit = Preload.hideSplashScreen;
var hasInitialized = false;
// Initializes scripts once enough of the game has loaded
Preload.hideSplashScreen = function (...args) {
var result = oldInit.apply(this, args);
if (App.game && !hasInitialized) {
// Initialize all attached userscripts
Object.entries(windowObject.epheniaScriptInitializers).forEach(([scriptName, initFunction]) => {
try {
initFunction();
} catch (e) {
console.error(`Error while initializing '${scriptName}' userscript:\n${e}`);
Notifier.notify({
type: NotificationConstants.NotificationOption.warning,
title: scriptName,
message: `The '${scriptName}' userscript crashed while loading. Check for updates or disable the script, then restart the game.\n\nReport script issues to the script developer, not to the Pokéclicker team.`,
timeout: GameConstants.DAY,
});
}
});
hasInitialized = true;
}
return result;
}
}
// Prevent issues with duplicate script names
if (windowObject.epheniaScriptInitializers[scriptName] !== undefined) {
console.warn(`Duplicate '${scriptName}' userscripts found!`);
Notifier.notify({
type: NotificationConstants.NotificationOption.warning,
title: scriptName,
message: `Duplicate '${scriptName}' userscripts detected. This could cause unpredictable behavior and is not recommended.`,
timeout: GameConstants.DAY,
});
let number = 2;
while (windowObject.epheniaScriptInitializers[`${scriptName} ${number}`] !== undefined) {
number++;
}
scriptName = `${scriptName} ${number}`;
}
// Add initializer for this particular script
windowObject.epheniaScriptInitializers[scriptName] = initFunction;
}
if (!App.isUsingClient || localStorage.getItem('simpleweatherchanger') === 'true') {
loadEpheniaScript('simpleweatherchanger', initWeatherChange);
}