Skip to content

Commit 94ab445

Browse files
committed
fix: disable april fools setting automatically
1 parent 17e234e commit 94ab445

File tree

5 files changed

+42
-53
lines changed

5 files changed

+42
-53
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# UnderScript Changelog
22

3+
## Version 0.62.2 (2025-04-09)
4+
1. Fixed April Fools setting being too aggressive
5+
36
## Version 0.62.1 (2025-04-04)
47
1. Fixed plugins breaking when providing custom settings
58

src/base/underscript/updates.js

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import axios from 'axios';
21
import luxon from 'luxon';
32
import * as settings from '../../utils/settings/index.js';
43
import style from '../../utils/style.js';
@@ -10,7 +9,7 @@ import * as menu from '../../utils/menu.js';
109
import semver from '../../utils/version.js';
1110
import { buttonCSS, scriptVersion } from '../../utils/1.variables.js';
1211
import css from '../../utils/css.js';
13-
import { captureError } from '../../utils/sentry.js';
12+
import { createParser } from '../../utils/updater/index.js';
1413

1514
// Check for script updates
1615
wrap(() => {
@@ -30,21 +29,19 @@ wrap(() => {
3029
font-size: 17px;
3130
}
3231
`);
33-
const baseURL = 'https://unpkg.com/';
32+
const checker = window.checker = createParser({ updateURL: 'UCProjects/UnderScript' });
3433
const MINUTE = 60 * 1000;
3534
const HOUR = 60 * MINUTE;
3635
const CHECKING = 'underscript.update.checking';
3736
const LAST = 'underscript.update.last';
3837
const DEBUG = 'underscript.debug.update';
3938
const LATEST = 'underscript.update.latest';
40-
const base = axios.create({ baseURL });
4139
const latest = { // TODO: can I get away with storing this in sessionStorage?
42-
set({ version, unpkg }) {
43-
if (!version || !unpkg) return;
40+
set({ version, ...data }) {
41+
if (!version) return;
4442
localStorage.setItem(LATEST, JSON.stringify({
43+
...data,
4544
version,
46-
unpkg,
47-
time: Date.now(),
4845
}));
4946
},
5047
del() {
@@ -61,21 +58,22 @@ wrap(() => {
6158
let toast;
6259
let updateToast;
6360
let autoTimeout;
64-
function check() {
65-
if (sessionStorage.getItem(CHECKING)) return Promise.resolve();
61+
async function check() {
62+
if (sessionStorage.getItem(CHECKING)) return undefined;
6663
sessionStorage.setItem(CHECKING, true);
67-
return base.get(`underscript@latest/package.json`).then((response) => {
68-
sessionStorage.removeItem(CHECKING);
69-
localStorage.setItem(LAST, Date.now());
70-
return response;
71-
}).catch((error) => {
72-
captureError(error);
73-
sessionStorage.removeItem(CHECKING);
64+
try {
65+
const data = checker.getUpdateData();
66+
return {
67+
version: await checker.getVersion(data),
68+
url: await checker.getDownload(data),
69+
};
70+
} catch (error) {
7471
debugToast(error);
75-
if (toast) {
76-
toast.setText('Failed to connect to server.');
77-
}
78-
});
72+
toast?.setText('Failed to retrieve update.');
73+
return undefined;
74+
} finally {
75+
sessionStorage.setItem(CHECKING, false);
76+
}
7977
}
8078
function noUpdateFound() {
8179
const ref = toast;
@@ -87,7 +85,6 @@ wrap(() => {
8785
function isNewer(data) {
8886
const version = scriptVersion;
8987
if (version === 'L' && !localStorage.getItem(DEBUG)) return false;
90-
if (data.time && data.time < GM_info.script.lastModified) return false; // Check if stored version is newer than script date
9188
if (version.includes('-')) return semver(data.version, version); // Allow test scripts to update to release
9289
return data.version !== version; // Always assume that the marked version is better
9390
}
@@ -98,36 +95,18 @@ wrap(() => {
9895
}
9996
latest.set(data);
10097
if (updateToast) updateToast.close('stale');
101-
const path = `underscript@${data.version}/${data.unpkg}`;
10298
updateToast = BasicToast({
10399
title: '[UnderScript] Update Available!',
104100
text: `Version ${data.version}.`,
105101
className: 'dismissable',
106102
buttons: [{
107-
text: 'Update (github)',
108-
className: 'dismiss',
109-
css: buttonCSS,
110-
}, {
111-
text: 'Update (unpkg)',
112-
className: 'dismiss',
113-
css: buttonCSS,
114-
onclick(e) {
115-
location.href = `${baseURL}/${path}`;
116-
updateToast.close('update');
117-
},
118-
}, {
119-
text: 'Update (jsdelivr)',
103+
text: 'Update',
120104
className: 'dismiss',
121105
css: buttonCSS,
122-
onclick: (e) => {
123-
location.href = `https://cdn.jsdelivr.net/npm/${path}`;
124-
updateToast.close('update');
106+
onclick() {
107+
location.href = data.url || `https://github.com/UCProjects/UnderScript/releases/download/${data.version}/undercards.user.js`;
125108
},
126109
}],
127-
onClose(reason) {
128-
if (reason !== 'dismissed') return;
129-
location.href = `https://github.com/UCProjects/UnderScript/releases/download/${data.version}/undercards.user.js`;
130-
},
131110
});
132111
return true;
133112
}

src/base/vanilla/aprilFools.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,38 @@ import eventManager from '../../utils/eventManager.js';
22
import * as settings from '../../utils/settings/index.js';
33
import { isApril, IMAGES } from '../../utils/isApril.js';
44

5+
const year = `${new Date().getFullYear()}`;
56
const aprilFools = settings.register({
67
name: 'Disable April Fools Jokes',
78
key: 'underscript.disable.fishday',
89
note: 'Disables *almost* everything.',
9-
hidden: () => !isApril(),
10+
data: { extraValue: year },
11+
hidden: () => !isApril() || isSoftDisabled(),
1012
onChange() {
1113
toggleFish($('body'));
1214
},
1315
});
16+
function isSoftDisabled() {
17+
return localStorage.getItem(aprilFools.key) === year;
18+
}
1419

1520
const basePath = 'images';
1621

1722
function toggleFish($el) {
1823
const disabled = aprilFools.value();
1924
const search = disabled ? IMAGES : basePath;
20-
const replace = disabled ? [IMAGES, basePath] : [basePath, IMAGES];
25+
const replace = disabled ? basePath : IMAGES;
2126

2227
$el.find(`img[src*="undercards.net/${search}/"],img[src^="/${search}/"],img[src^="${search}/"]`).each((_, img) => {
23-
img.src = img.src.replace(...replace);
24-
});
28+
img.src = img.src.replace(search, replace);
29+
}).on('error', () => aprilFools.set(year));
2530
$el.find(`[style*="url(\\"${search}/"]`).each((i, img) => {
26-
img.style.background = img.style.background.replace(...replace);
27-
});
31+
img.style.background = img.style.background.replace(search, replace);
32+
}).on('error', () => aprilFools.set(year));
2833
}
2934

30-
if (isApril()) {
35+
eventManager.on('undercards:season', () => {
36+
if (!isApril() || isSoftDisabled()) return;
3137
eventManager.on(':load', () => {
3238
toggleFish($('body'));
3339
});
@@ -44,4 +50,4 @@ if (isApril()) {
4450
eventManager.on('Home:Refresh', () => {
4551
toggleFish($('table.spectateTable'));
4652
});
47-
}
53+
});

src/utils/season.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ eventManager.on('translation:loaded', () => {
2222

2323
season = Number(seasonKey.substring(startsWith.length, seasonKey.indexOf('-', startsWith.length)));
2424
sessionStorage.setItem('undercards.season', season);
25+
eventManager.singleton.emit('undercards:season', season);
2526
});

src/utils/settings/types/boolean.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export default class extends Setting {
55
super(name);
66
}
77

8-
value(val) {
8+
value(val, { extraValue } = {}) {
99
if (typeof val === 'boolean') return val;
10-
return ['1', 'true', 1].includes(val);
10+
return ['1', 'true', 1, `${extraValue}`].includes(val);
1111
}
1212

1313
element(value, update, {

0 commit comments

Comments
 (0)