diff --git a/package-lock.json b/package-lock.json index ec30e0da..cd6e42d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "name": "@repeek/browser-extension", "dependencies": { "@material-ui/core": "^3.9.1", + "array-shuffle": "^3.0.0", "camelcase-keys": "^4.2.0", "copy-text-to-clipboard": "^1.0.4", "country-list": "^2.1.0", @@ -15,7 +16,6 @@ "dom-chef": "^5.1.0", "js-cookie": "^2.2.1", "ky": "^0.11.1", - "lodash": "^4.17.10", "lucide-react": "^0.314.0", "mem": "^4.0.0", "p-memoize": "^1.0.0", @@ -2544,13 +2544,6 @@ "node": ">= 0.10.0" } }, - "node_modules/archiver-utils/node_modules/lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true, - "license": "MIT" - }, "node_modules/archiver/node_modules/async": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz", @@ -2568,13 +2561,6 @@ "dev": true, "license": "MIT" }, - "node_modules/archiver/node_modules/lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true, - "license": "MIT" - }, "node_modules/are-we-there-yet": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz", @@ -2697,6 +2683,17 @@ "dev": true, "license": "MIT" }, + "node_modules/array-shuffle": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/array-shuffle/-/array-shuffle-3.0.0.tgz", + "integrity": "sha512-rogEGxHOQPhslOhpg12LJkB+bbAl484/s2AJq0BxtzQDQfKl76fS2u9zWgg3p3b9ENcuvE7K8A7l5ddiPjCRnw==", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/array-unique": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz", @@ -6237,13 +6234,6 @@ "node": ">=0.10.0" } }, - "node_modules/eslint-plugin-no-unsafe-innerhtml/node_modules/lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true, - "license": "MIT" - }, "node_modules/eslint-plugin-no-unsafe-innerhtml/node_modules/onetime": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", @@ -6999,13 +6989,6 @@ "lodash": "^4.14.0" } }, - "node_modules/firefox-profile/node_modules/lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true, - "license": "MIT" - }, "node_modules/firefox-profile/node_modules/uuid": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", @@ -9983,10 +9966,9 @@ } }, "node_modules/lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", - "license": "MIT" + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash.camelcase": { "version": "4.3.0", @@ -12934,12 +12916,6 @@ "react-dom": "^0.14.0 || ^15.0.0 || ^16.0.0" } }, - "node_modules/react-sortable-hoc/node_modules/lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "license": "MIT" - }, "node_modules/react-transition-group": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-2.9.0.tgz", @@ -18346,13 +18322,6 @@ "engines": { "node": ">= 0.10.0" } - }, - "node_modules/zip-stream/node_modules/lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true, - "license": "MIT" } } } diff --git a/package.json b/package.json index c2c9a192..155ea7a1 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ }, "dependencies": { "@material-ui/core": "^3.9.1", + "array-shuffle": "^3.0.0", "camelcase-keys": "^4.2.0", "copy-text-to-clipboard": "^1.0.4", "country-list": "^2.1.0", @@ -29,7 +30,6 @@ "dom-chef": "^5.1.0", "js-cookie": "^2.2.1", "ky": "^0.11.1", - "lodash": "^4.17.10", "lucide-react": "^0.314.0", "mem": "^4.0.0", "p-memoize": "^1.0.0", diff --git a/src/content/features/add-player-profile-matches-demo.js b/src/content/features/add-player-profile-matches-demo.js index 82e1a209..4b02afa4 100644 --- a/src/content/features/add-player-profile-matches-demo.js +++ b/src/content/features/add-player-profile-matches-demo.js @@ -1,5 +1,4 @@ import React from 'dom-chef' -import get from 'lodash/get' import select from 'select-dom' import createButton from '../components/button' import { @@ -67,9 +66,15 @@ export default async (statsContentElement) => { text: 'Watch Demo', onClick: async (e) => { e.stopPropagation() + const match = await getMatch(matchId) + + if (!match) { + return + } + const demoUrl = - get(match, 'externalMatches[0].stats.demoFileUrl') || + match.externalMatches?.[0]?.stats?.demoFileUrl || match.demoUrl || match.demoUrLs[0] diff --git a/src/content/features/add-player-profile-matches-elo.js b/src/content/features/add-player-profile-matches-elo.js index 5762ab43..1c593035 100644 --- a/src/content/features/add-player-profile-matches-elo.js +++ b/src/content/features/add-player-profile-matches-elo.js @@ -1,6 +1,6 @@ import React from 'dom-chef' -import random from 'lodash/random' import select from 'select-dom' +import { randomNumber } from '../../shared/utils' import { hasFeatureAttribute, setFeatureAttribute, @@ -108,7 +108,7 @@ export default async (statsContentElement) => { opacity: selfIsFreeMember && 0.33, }} > - {selfIsFreeMember ? random(1000, 3000) : newElo} + {selfIsFreeMember ? randomNumber(1000, 3000) : newElo} ) diff --git a/src/content/features/add-sidebar-matches-elo.js b/src/content/features/add-sidebar-matches-elo.js index 633ab2d4..ab6c5977 100644 --- a/src/content/features/add-sidebar-matches-elo.js +++ b/src/content/features/add-sidebar-matches-elo.js @@ -1,7 +1,7 @@ import React from 'dom-chef' -import random from 'lodash/random' import select from 'select-dom' import { IS_FACEIT_BETA } from '../../shared/faceit-beta' +import { randomNumber } from '../../shared/utils' import { hasFeatureAttribute, setFeatureAttribute, @@ -96,7 +96,7 @@ export default async () => { opacity: selfIsFreeMember && 0.33, }} > - {selfIsFreeMember ? random(1000, 3000) : newElo} + {selfIsFreeMember ? randomNumber(1000, 3000) : newElo} , matchTypeElement, diff --git a/src/content/features/click-match-room-veto-maps.js b/src/content/features/click-match-room-veto-maps.js index 309d255a..f8924934 100644 --- a/src/content/features/click-match-room-veto-maps.js +++ b/src/content/features/click-match-room-veto-maps.js @@ -1,4 +1,4 @@ -import shuffle from 'lodash/shuffle' +import arrayShuffle from 'array-shuffle' import select from 'select-dom' import storage from '../../shared/storage' import { @@ -43,7 +43,9 @@ export default async (parentElement) => { let autoVetoItems = matchRoomAutoVetoMapItems.map((m) => maps.csgo[m] || m) if (shuffleMaps) { - const shuffledItems = shuffle(autoVetoItems.splice(0, shuffleMapsAmount)) + const shuffledItems = arrayShuffle( + autoVetoItems.splice(0, shuffleMapsAmount), + ) autoVetoItems.unshift(...shuffledItems) } diff --git a/src/content/helpers/elo.js b/src/content/helpers/elo.js index 58efb725..c691c9f2 100644 --- a/src/content/helpers/elo.js +++ b/src/content/helpers/elo.js @@ -1,5 +1,3 @@ -import isNumber from 'lodash/isNumber' -import round from 'lodash/round' import mem from 'mem' import { getMatchmakingQueue } from './faceit-api' @@ -11,8 +9,8 @@ export function estimateRatingChange(elo1, elo2, K = 50) { const eloDiff = elo2 - elo1 const percentage = 1 / (1 + 10 ** (eloDiff / 400)) - const gain = round(K * (1 - percentage)) - const loss = round(K * (0 - percentage)) + const gain = Math.round(K * (1 - percentage)) + const loss = Math.round(K * (0 - percentage)) return { gain: gain || 1, @@ -90,7 +88,9 @@ export async function getEloChangesByMatches(matches) { const previousElo = previousMatch.elo && normalizeElo(previousMatch.elo) const newElo = match.elo && normalizeElo(match.elo) const eloDiff = - isNumber(previousElo) && isNumber(newElo) ? newElo - previousElo : null + typeof previousElo === 'number' && typeof newElo === 'number' + ? newElo - previousElo + : null if ( !eloDiff || diff --git a/src/content/helpers/match-room.js b/src/content/helpers/match-room.js index 4602087d..df74ec4a 100644 --- a/src/content/helpers/match-room.js +++ b/src/content/helpers/match-room.js @@ -1,5 +1,3 @@ -import head from 'lodash/head' -import isEmpty from 'lodash/isEmpty' import mem from 'mem' import select from 'select-dom' import { getCurrentPath } from './location' @@ -91,7 +89,7 @@ export function mapPlayersToPartyColors( let partyColor if (isPremade) { - partyColor = isEmpty(acc) ? pickColor() : head(acc).partyColor + partyColor = acc.length === 0 ? pickColor() : acc[0].partyColor } else if (curr.activeTeamId || !isTeamV1Element) { let partyMember if (isTeamV1Element) { diff --git a/src/content/helpers/user-settings.js b/src/content/helpers/user-settings.js index beff1943..64d30a60 100644 --- a/src/content/helpers/user-settings.js +++ b/src/content/helpers/user-settings.js @@ -1,4 +1,3 @@ -import throttle from 'lodash/throttle' import browser from 'webextension-polyfill' import storage from '../../shared/storage' @@ -19,7 +18,7 @@ export const runFeatureIf = async (option, feature, parent) => { } } -export const notifyIf = throttle(async (option, message) => { +export const notifyIf = async (option, message) => { const options = await storage.getAll() if (!options.notifyDisabled && options[option]) { @@ -28,4 +27,4 @@ export const notifyIf = throttle(async (option, message) => { ...message, }) } -}, 500) +} diff --git a/src/popup/sections/help.js b/src/popup/sections/help.js index 20437c0e..05d5edf0 100644 --- a/src/popup/sections/help.js +++ b/src/popup/sections/help.js @@ -1,5 +1,4 @@ import { detect } from 'detect-browser' -import capitalize from 'lodash/capitalize' import React from 'react' import browser from 'webextension-polyfill' import ListItemLink from '../components/list-item-link' @@ -17,7 +16,9 @@ export default () => ( subreddit={encodeURI( `submit?selftext=true&text=\n\n\n---\n\nVersion: ${ browser.runtime.getManifest().version - }\nBrowser: ${capitalize(userBrowser.name)} (${userBrowser.version})`, + }\nBrowser: ${userBrowser.name[0].toUpperCase()}${userBrowser.name.slice( + 1, + )} (${userBrowser.version})`, )} /> diff --git a/src/shared/utils.js b/src/shared/utils.js new file mode 100644 index 00000000..32b6151e --- /dev/null +++ b/src/shared/utils.js @@ -0,0 +1,3 @@ +export function randomNumber(min, max) { + return Math.floor(Math.random() * (max - min + 1) + min) +}