Skip to content

Commit

Permalink
chore: support older browsers that don't have Object.hasOwn
Browse files Browse the repository at this point in the history
  • Loading branch information
feildmaster committed Jan 21, 2024
1 parent eaa8978 commit 6df087e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# UnderScript Changelog

## Version 0.56.1 (2024-01-21)
1. Add support for older browsers

## Version 0.56.0 (2023-10-22)
### Plugins
1. Added a few more Constants
Expand Down
3 changes: 2 additions & 1 deletion src/base/leaderboard/goto.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { debug } from '../../utils/debug.js';
import onPage from '../../utils/onPage.js';
import VarStore from '../../utils/VarStore.js';
import changePage from '../vanilla/pageSelect.js';
import hasOwn from '../../utils/hasOwn.js';

function set(type, value, replace = true) {
if (history.state &&
Object.hasOwn(history.state, type) &&
hasOwn(history.state, type) &&
history.state[type] === value) return;
const func = replace && !userLast() ? history.replaceState : history.pushState;
const o = {};
Expand Down
4 changes: 2 additions & 2 deletions src/base/library/craft/disenchant.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import onPage from '../../../utils/onPage.js';
import * as hover from '../../../utils/hover.js';
import each from '../../../utils/each.js';
import { captureError } from '../../../utils/sentry.js';
import hasOwn from '../../../utils/hasOwn.js';

const setting = settings.register({
name: 'Disable Smart Disenchanting',
Expand Down Expand Up @@ -180,8 +181,7 @@ onPage('Crafting', function disenchantWrapper() {
global('collection').filter((card) => cardFilter(card, shiny, priority, deltarune))
.forEach(({ id, name, shiny: isShiny, rarity, quantity }) => {
if (priority) {
// eslint-disable-next-line no-prototype-builtins
if (!cards.hasOwnProperty(id)) {
if (!hasOwn(cards, id)) {
const max = cardHelper.max(rarity);
if (!max) return;
cards[id] = {
Expand Down
3 changes: 2 additions & 1 deletion src/base/library/deck/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as hover from '../../../utils/hover.js';
import style from '../../../utils/style.js';
import * as deckLoader from '../../../utils/loadDeck.js';
import compound from '../../../utils/compoundEvent.js';
import hasOwn from '../../../utils/hasOwn.js';

const setting = settings.register({
name: 'Disable Deck Storage',
Expand Down Expand Up @@ -69,7 +70,7 @@ onPage('Decks', function deckStorage() {
const key = getKey(id);
const deck = JSON.parse(localStorage.getItem(key));
if (!deck) return;
if (!Object.hasOwn(deck, 'cards')) {
if (!hasOwn(deck, 'cards')) {
localStorage.setItem(key, JSON.stringify({
cards: deck,
artifacts: [],
Expand Down
5 changes: 3 additions & 2 deletions src/utils/global.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { debug } from './debug.js';
import hasOwn from './hasOwn.js';

export function global(...key) {
const {
throws = true,
} = typeof key[key.length - 1] === 'object' ? key.pop() : {};
const found = key.find((e) => Object.hasOwn(window, e));
const found = key.find((e) => hasOwn(window, e));
if (found === undefined) {
const msg = `[${key.join(',')}] does not exist`;
if (throws) throw new Error(msg);
Expand All @@ -16,7 +17,7 @@ export function global(...key) {
export function globalSet(key, value, {
throws = true,
} = {}) {
if (!Object.hasOwn(window, key)) {
if (!hasOwn(window, key)) {
const msg = `[${key}] does not exist`;
if (throws) throw new Error(msg);
return debug(msg);
Expand Down
8 changes: 8 additions & 0 deletions src/utils/hasOwn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const internal = typeof Object.hasOwn === 'function';

export default function hasOwn(object, property) {
if (internal) {
return Object.hasOwn(object, property);
}
return Object.prototype.hasOwnProperty.call(object, property);
}

0 comments on commit 6df087e

Please sign in to comment.