-
Notifications
You must be signed in to change notification settings - Fork 2
/
ultraviner-refresh.user.js
221 lines (186 loc) · 9.96 KB
/
ultraviner-refresh.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// ==UserScript==
// @name Ultraviner Auto-Refresh RFY, AFA & AI
// @namespace http://tampermonkey.net/
// @version 2024-08-21
// @description Auto-refresh RFY, AFA & AI
// @author Runew0lf
// @match https://www.amazon.co.uk/vine/vine-items?ultraviner*
// @match https://www.amazon.com/vine/vine-items?ultraviner*
// @updateURL https://github.com/runew0lf/Ultraviner-Auto-Refresh-RFY/raw/main/ultraviner-refresh.user.js
// @downloadURL https://github.com/runew0lf/Ultraviner-Auto-Refresh-RFY/raw/main/ultraviner-refresh.user.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Default values for settings
const defaultSettings = {
minSeconds: 30,
maxSeconds: 50,
startHour: 3, // 3am
endHour: 17, // 5pm
useHourRestriction: true,
refreshRFY: true,
refreshAFA: true,
refreshAI: true,
refreshSearch: true
};
function loadSettings() {
const settings = JSON.parse(localStorage.getItem('ultravinerSettings')) || defaultSettings;
return settings;
}
function saveSettings(settings) {
localStorage.setItem('ultravinerSettings', JSON.stringify(settings));
}
let settings = loadSettings();
let { minSeconds, maxSeconds, startHour, endHour, useHourRestriction, refreshRFY, refreshAFA, refreshAI, refreshSearch } = settings;
let intervals = {};
function getRandomInterval() {
return Math.random() * (maxSeconds - minSeconds) + minSeconds;
}
function refreshQueue(queueType) {
const thisHour = new Date().getHours();
if (!useHourRestriction || (thisHour >= startHour && thisHour <= endHour)) {
const refreshButton = document.querySelector(`[data-queue-type="${queueType}"] [data-icon="arrows-rotate"]`);
if (refreshButton) {
refreshButton.dispatchEvent(new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
}));
} else {
console.log(`Refresh button for ${queueType} not found. Will try again on next refresh.`);
}
}
}
function startRefreshing(queueType) {
stopRefreshing(queueType); // Stop any existing interval
refreshQueue(queueType); // Refresh immediately
scheduleNextRefresh(queueType); // Schedule the next refresh
}
function scheduleNextRefresh(queueType) {
const interval = getRandomInterval() * 1000;
intervals[queueType] = setTimeout(() => {
refreshQueue(queueType);
scheduleNextRefresh(queueType); // Schedule the next refresh after this one
}, interval);
}
function stopRefreshing(queueType) {
clearTimeout(intervals[queueType]);
}
function applySettings() {
stopRefreshing('RFY');
stopRefreshing('AFA');
stopRefreshing('AI');
stopRefreshing('Search');
startAllRefreshes();
}
function startAllRefreshes() {
if (refreshRFY) startRefreshing('RFY');
if (refreshAFA) startRefreshing('AFA');
if (refreshAI) startRefreshing('AI');
if (refreshSearch) startRefreshing('Search');
}
function createModal() {
const modalHtml = `
<div id="settingsModal" style="display:none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: white; padding: 20px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5); z-index: 1001;">
<h2>Settings</h2>
<label for="minSeconds">Min Seconds:</label>
<input type="number" id="minSeconds" value="${minSeconds}" min="1"><br><br>
<label for="maxSeconds">Max Seconds:</label>
<input type="number" id="maxSeconds" value="${maxSeconds}" min="1"><br><br>
<label for="startHour">Start Hour:</label>
<input type="number" id="startHour" value="${startHour}" min="0" max="23"><br><br>
<label for="endHour">End Hour:</label>
<input type="number" id="endHour" value="${endHour}" min="0" max="23"><br><br>
<label for="useHourRestriction">Use Hour Restriction:</label>
<input type="checkbox" id="useHourRestriction" ${useHourRestriction ? 'checked' : ''}><br><br>
<label for="refreshRFY">Refresh RFY:</label>
<input type="checkbox" id="refreshRFY" ${refreshRFY ? 'checked' : ''}><br><br>
<label for="refreshAFA">Refresh AFA:</label>
<input type="checkbox" id="refreshAFA" ${refreshAFA ? 'checked' : ''}><br><br>
<label for="refreshAI">Refresh AI:</label>
<input type="checkbox" id="refreshAI" ${refreshAI ? 'checked' : ''}><br><br>
<label for="refreshSearch">Refresh Search:</label>
<input type="checkbox" id="refreshSearch" ${refreshSearch ? 'checked' : ''}><br><br>
<button id="saveSettings">Save</button>
<button id="closeModal">Close</button>
</div>
<div id="modalBackdrop" style="display:none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 1000;"></div>
`;
document.body.insertAdjacentHTML('beforeend', modalHtml);
document.getElementById('saveSettings').addEventListener('click', () => {
const newMinSeconds = parseFloat(document.getElementById('minSeconds').value);
const newMaxSeconds = parseFloat(document.getElementById('maxSeconds').value);
const newStartHour = parseInt(document.getElementById('startHour').value, 10);
const newEndHour = parseInt(document.getElementById('endHour').value, 10);
const newUseHourRestriction = document.getElementById('useHourRestriction').checked;
const newRefreshRFY = document.getElementById('refreshRFY').checked;
const newRefreshAFA = document.getElementById('refreshAFA').checked;
const newRefreshAI = document.getElementById('refreshAI').checked;
const newRefreshSearch = document.getElementById('refreshSearch').checked;
if (isNaN(newMinSeconds) || isNaN(newMaxSeconds) || newMinSeconds < 1 || newMaxSeconds < newMinSeconds) {
alert("Invalid input for seconds. Please enter valid numbers where minimum is less than maximum.");
} else if (isNaN(newStartHour) || isNaN(newEndHour) || newStartHour < 0 || newStartHour > 23 || newEndHour < 0 || newEndHour > 23 || newStartHour > newEndHour) {
alert("Invalid input for hours. Please enter valid numbers between 0 and 23, and ensure start hour is less than or equal to end hour.");
} else {
minSeconds = newMinSeconds;
maxSeconds = newMaxSeconds;
startHour = newStartHour;
endHour = newEndHour;
useHourRestriction = newUseHourRestriction;
refreshRFY = newRefreshRFY;
refreshAFA = newRefreshAFA;
refreshAI = newRefreshAI;
refreshSearch = newRefreshSearch;
settings = { minSeconds, maxSeconds, startHour, endHour, useHourRestriction, refreshRFY, refreshAFA, refreshAI, refreshSearch };
saveSettings(settings);
applySettings();
alert(`Settings updated:\nminSeconds = ${minSeconds}\nmaxSeconds = ${maxSeconds}\nstartHour = ${startHour}\nendHour = ${endHour}\nuseHourRestriction = ${useHourRestriction}\nrefreshRFY = ${refreshRFY}\nrefreshAFA = ${refreshAFA}\nrefreshAI = ${refreshAI}`);
closeModal();
}
});
document.getElementById('closeModal').addEventListener('click', closeModal);
function closeModal() {
document.getElementById('settingsModal').style.display = 'none';
document.getElementById('modalBackdrop').style.display = 'none';
}
function openModal() {
document.getElementById('settingsModal').style.display = 'block';
document.getElementById('modalBackdrop').style.display = 'block';
}
return openModal;
}
function createSettingsButton(openModal) {
let executed = false;
const settingsButton = document.createElement('button');
settingsButton.textContent = '🔄';
settingsButton.style.backgroundColor = 'transparent';
settingsButton.style.border = 'none';
settingsButton.style.color = 'white';
settingsButton.style.cursor = 'pointer';
settingsButton.style.fontSize = '1.5rem';
settingsButton.addEventListener('click', openModal);
const targetNode = document;
const config = { attributes: false, childList: true, subtree: true };
const callback = (mutationList, observer) => {
for (const mutation of mutationList) {
if (mutation.type === "childList" && mutation.target.className.indexOf("queue-items") >= 0 && document.querySelector("[class*='add-queue']") && !executed) {
const divider = document.querySelector("[class*='divider'][class*='vertical']");
const clonedDivider = divider.cloneNode(true);
document.querySelector("[class*='add-queue']").insertAdjacentElement("afterend", settingsButton);
document.querySelector("[class*='add-queue']").insertAdjacentElement("afterend", clonedDivider);
executed = true;
setTimeout(() => {
executed = false;
}, 1000);
}
}
};
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
}
const openModal = createModal();
createSettingsButton(openModal);
startAllRefreshes(); // Start refreshing immediately on script load
})();