Skip to content

Commit 6df087e

Browse files
committed
chore: support older browsers that don't have Object.hasOwn
1 parent eaa8978 commit 6df087e

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
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.56.1 (2024-01-21)
4+
1. Add support for older browsers
5+
36
## Version 0.56.0 (2023-10-22)
47
### Plugins
58
1. Added a few more Constants

src/base/leaderboard/goto.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { debug } from '../../utils/debug.js';
44
import onPage from '../../utils/onPage.js';
55
import VarStore from '../../utils/VarStore.js';
66
import changePage from '../vanilla/pageSelect.js';
7+
import hasOwn from '../../utils/hasOwn.js';
78

89
function set(type, value, replace = true) {
910
if (history.state &&
10-
Object.hasOwn(history.state, type) &&
11+
hasOwn(history.state, type) &&
1112
history.state[type] === value) return;
1213
const func = replace && !userLast() ? history.replaceState : history.pushState;
1314
const o = {};

src/base/library/craft/disenchant.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import onPage from '../../../utils/onPage.js';
99
import * as hover from '../../../utils/hover.js';
1010
import each from '../../../utils/each.js';
1111
import { captureError } from '../../../utils/sentry.js';
12+
import hasOwn from '../../../utils/hasOwn.js';
1213

1314
const setting = settings.register({
1415
name: 'Disable Smart Disenchanting',
@@ -180,8 +181,7 @@ onPage('Crafting', function disenchantWrapper() {
180181
global('collection').filter((card) => cardFilter(card, shiny, priority, deltarune))
181182
.forEach(({ id, name, shiny: isShiny, rarity, quantity }) => {
182183
if (priority) {
183-
// eslint-disable-next-line no-prototype-builtins
184-
if (!cards.hasOwnProperty(id)) {
184+
if (!hasOwn(cards, id)) {
185185
const max = cardHelper.max(rarity);
186186
if (!max) return;
187187
cards[id] = {

src/base/library/deck/storage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as hover from '../../../utils/hover.js';
66
import style from '../../../utils/style.js';
77
import * as deckLoader from '../../../utils/loadDeck.js';
88
import compound from '../../../utils/compoundEvent.js';
9+
import hasOwn from '../../../utils/hasOwn.js';
910

1011
const setting = settings.register({
1112
name: 'Disable Deck Storage',
@@ -69,7 +70,7 @@ onPage('Decks', function deckStorage() {
6970
const key = getKey(id);
7071
const deck = JSON.parse(localStorage.getItem(key));
7172
if (!deck) return;
72-
if (!Object.hasOwn(deck, 'cards')) {
73+
if (!hasOwn(deck, 'cards')) {
7374
localStorage.setItem(key, JSON.stringify({
7475
cards: deck,
7576
artifacts: [],

src/utils/global.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { debug } from './debug.js';
2+
import hasOwn from './hasOwn.js';
23

34
export function global(...key) {
45
const {
56
throws = true,
67
} = typeof key[key.length - 1] === 'object' ? key.pop() : {};
7-
const found = key.find((e) => Object.hasOwn(window, e));
8+
const found = key.find((e) => hasOwn(window, e));
89
if (found === undefined) {
910
const msg = `[${key.join(',')}] does not exist`;
1011
if (throws) throw new Error(msg);
@@ -16,7 +17,7 @@ export function global(...key) {
1617
export function globalSet(key, value, {
1718
throws = true,
1819
} = {}) {
19-
if (!Object.hasOwn(window, key)) {
20+
if (!hasOwn(window, key)) {
2021
const msg = `[${key}] does not exist`;
2122
if (throws) throw new Error(msg);
2223
return debug(msg);

src/utils/hasOwn.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const internal = typeof Object.hasOwn === 'function';
2+
3+
export default function hasOwn(object, property) {
4+
if (internal) {
5+
return Object.hasOwn(object, property);
6+
}
7+
return Object.prototype.hasOwnProperty.call(object, property);
8+
}

0 commit comments

Comments
 (0)