From aeb1c8839dac47a8cc364c4ca992fa79b9343f39 Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Mon, 24 Jul 2023 12:17:46 -0600 Subject: [PATCH] chore: improve lint setup - update eslint config to closely mirror the ones from ferdium-app - add .eslintignore - opt in to eslint `reportUnusedDisableDirectives` config option - remove `trailingComma: all` from `prettier` config which is default in `prettier` v3 - autofix or disable a lot of lint issues throughout codebase - add `volta` configuration to `package.json` to autoload correct `node` and `pnpm` versions - upgrade all `eslint` and `prettier` related dependencies to latest - update lint:fix npm script - reformat touched files with prettier --- .eslintignore | 4 + .eslintrc.js | 19 +- .prettierrc.js | 1 - package.json | 13 +- pnpm-lock.yaml | 267 ++++++++++++----------- recipes/basecamp/webview.js | 6 +- recipes/chatwork/webview.js | 6 +- recipes/dialpad/webview.js | 16 +- recipes/element/webview.js | 13 +- recipes/freshdesk/webview.js | 9 +- recipes/googlecalendar/webview-unsafe.js | 6 +- recipes/grape/index.js | 62 ++++-- recipes/hipchat/index.js | 76 +++++-- recipes/idobata/webview.js | 2 +- recipes/kiwiirc/webview.js | 23 +- recipes/messenger/webview.js | 28 ++- recipes/pleroma/index.js | 36 +-- recipes/pleroma/webview.js | 2 + recipes/schildichat/webview.js | 13 +- recipes/skype/webview.js | 47 ++-- recipes/snapchat/webview.js | 2 +- recipes/tiktok/webview.js | 15 +- recipes/whatsapp/webview-unsafe.js | 43 ++-- recipes/whatsapp/webview.js | 62 +++--- recipes/workplace/webview.js | 10 +- recipes/zalo/webview.js | 43 ++-- scripts/create.js | 15 +- scripts/package.js | 17 +- 28 files changed, 504 insertions(+), 352 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..269424ff1 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +.devcontainer +.github +.husky +node_modules diff --git a/.eslintrc.js b/.eslintrc.js index 25e75f300..7c1f72585 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,8 +11,23 @@ module.exports = { jquery: true, }, extends: ['eslint:recommended', 'plugin:unicorn/recommended'], + reportUnusedDisableDirectives: true, rules: { - // eslint-plugin-unicorn + // eslint + 'array-callback-return': 1, + 'consistent-return': 1, + 'no-await-in-loop': 1, + 'no-return-assign': 1, + 'no-console': [ + 1, + { + allow: ['warn', 'error'], + }, + ], + 'no-param-reassign': 1, + 'prefer-destructuring': 0, + // eslint-plugin-unicorn + 'unicorn/filename-case': 0, 'unicorn/no-null': 0, 'unicorn/no-useless-undefined': 0, 'unicorn/prefer-module': 0, @@ -31,5 +46,7 @@ module.exports = { 'unicorn/consistent-destructuring': 0, 'unicorn/no-array-reduce': 0, 'unicorn/no-nested-ternary': 0, + 'unicorn/prefer-top-level-await': 0, + 'unicorn/prefer-string-replace-all': 0, }, }; diff --git a/.prettierrc.js b/.prettierrc.js index 6a0a09497..dd8e1aa20 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,5 +1,4 @@ module.exports = { singleQuote: true, arrowParens: 'avoid', - trailingComma: 'all', }; diff --git a/package.json b/package.json index 0f7be5f7f..d310ebdb3 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,11 @@ "doc": "docs" }, "engines": { + "node": "18.15.0", + "pnpm": "8.6.2" + }, + "volta": { + "node": "18.15.0", "pnpm": "8.6.2" }, "scripts": { @@ -13,7 +18,7 @@ "package": "node scripts/package.js", "create": "node scripts/create.js", "lint": "eslint \"{recipes,scripts}/**/*.{js,jsx,ts,tsx}\"", - "lint:fix": "eslint --fix \"{recipes,scripts}/**/*.{js,jsx,ts,tsx}\"", + "lint:fix": "pnpm lint --fix", "reformat-files": "prettier --ignore-path .eslintignore --write --require-pragma \"**/*.{js,json,scss}\"", "contributors": "all-contributors" }, @@ -34,14 +39,14 @@ "devDependencies": { "@types/targz": "1.0.1", "all-contributors-cli": "6.26.0", - "eslint": "8.39.0", - "eslint-plugin-unicorn": "42.0.0", + "eslint": "8.45.0", + "eslint-plugin-unicorn": "48.0.0", "fs-extra": "11.1.1", "husky": "8.0.3", "image-size": "1.0.2", "is-ci": "3.0.1", "open": "8.4.1", - "prettier": "2.8.8", + "prettier": "3.0.0", "simple-git": "3.19.0", "targz": "1.0.1" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e37d28af3..0b6473162 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,11 +15,11 @@ importers: specifier: 6.26.0 version: 6.26.0 eslint: - specifier: 8.39.0 - version: 8.39.0 + specifier: 8.45.0 + version: 8.45.0 eslint-plugin-unicorn: - specifier: 42.0.0 - version: 42.0.0(eslint@8.39.0) + specifier: 48.0.0 + version: 48.0.0(eslint@8.45.0) fs-extra: specifier: 11.1.1 version: 11.1.1 @@ -36,8 +36,8 @@ importers: specifier: 8.4.1 version: 8.4.1 prettier: - specifier: 2.8.8 - version: 2.8.8 + specifier: 3.0.0 + version: 3.0.0 simple-git: specifier: 3.19.0 version: 3.19.0 @@ -75,6 +75,8 @@ importers: recipes/azure-devops: {} + recipes/bard: {} + recipes/basecamp: {} recipes/bigbluebutton: {} @@ -93,6 +95,8 @@ importers: recipes/brax.me: {} + recipes/bring: {} + recipes/buffer: {} recipes/bugzilla: {} @@ -359,6 +363,8 @@ importers: recipes/mewe: {} + recipes/miro: {} + recipes/mirotalk-bro: {} recipes/mirotalk-c2c: {} @@ -429,6 +435,8 @@ importers: recipes/paymo: {} + recipes/perplexity: {} + recipes/pinterest: {} recipes/pipefy: {} @@ -437,6 +445,8 @@ importers: recipes/pixelfed: {} + recipes/pixieset: {} + recipes/plan: {} recipes/planitpoker: {} @@ -503,6 +513,8 @@ importers: recipes/simplenote: {} + recipes/skiff-mail: {} + recipes/skype: {} recipes/slack: {} @@ -653,23 +665,28 @@ importers: packages: - /@babel/code-frame@7.16.7: - resolution: {integrity: sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg==} + /@aashutoshrathi/word-wrap@1.2.6: + resolution: {integrity: sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==} + engines: {node: '>=0.10.0'} + dev: true + + /@babel/code-frame@7.22.5: + resolution: {integrity: sha512-Xmwn266vad+6DAqEB2A6V/CcZVp62BbwVmcOJc2RPuwih1kw02TjQvWVWlcKGbBPd+8/0V5DEkOcizRGYsspYQ==} engines: {node: '>=6.9.0'} dependencies: - '@babel/highlight': 7.17.12 + '@babel/highlight': 7.22.5 dev: true - /@babel/helper-validator-identifier@7.16.7: - resolution: {integrity: sha512-hsEnFemeiW4D08A5gUAZxLBTXpZ39P+a+DGDsHw1yxqyQ/jzFEnxf5uTEGp+3bzAbNOxU1paTgYS4ECU/IgfDw==} + /@babel/helper-validator-identifier@7.22.5: + resolution: {integrity: sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==} engines: {node: '>=6.9.0'} dev: true - /@babel/highlight@7.17.12: - resolution: {integrity: sha512-7yykMVF3hfZY2jsHZEEgLc+3x4o1O+fYyULu11GynEUQNwB6lua+IIQn1FiJxNucd5UlyJryrwsOh8PL9Sn8Qg==} + /@babel/highlight@7.22.5: + resolution: {integrity: sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw==} engines: {node: '>=6.9.0'} dependencies: - '@babel/helper-validator-identifier': 7.16.7 + '@babel/helper-validator-identifier': 7.22.5 chalk: 2.4.2 js-tokens: 4.0.0 dev: true @@ -681,28 +698,28 @@ packages: regenerator-runtime: 0.13.11 dev: true - /@eslint-community/eslint-utils@4.4.0(eslint@8.39.0): + /@eslint-community/eslint-utils@4.4.0(eslint@8.45.0): resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || >=8.0.0 dependencies: - eslint: 8.39.0 + eslint: 8.45.0 eslint-visitor-keys: 3.4.1 dev: true - /@eslint-community/regexpp@4.5.1: - resolution: {integrity: sha512-Z5ba73P98O1KUYCCJTUeVpja9RcGoMdncZ6T49FCUl2lN38JtCJ+3WgIDBv0AuY4WChU5PmtJmOCTlN6FZTFKQ==} + /@eslint-community/regexpp@4.6.1: + resolution: {integrity: sha512-O7x6dMstWLn2ktjcoiNLDkAGG2EjveHL+Vvc+n0fXumkJYAcSqcVYKtwDU+hDZ0uDUsnUagSYaZrOLAYE8un1A==} engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} dev: true - /@eslint/eslintrc@2.0.3: - resolution: {integrity: sha512-+5gy6OQfk+xx3q0d6jGZZC3f3KzAkXc/IanVxd1is/VIIziRqqt3ongQz0FiTUXqTk0c7aDB3OaFuKnuSoJicQ==} + /@eslint/eslintrc@2.1.0: + resolution: {integrity: sha512-Lj7DECXqIVCqnqjjHMPna4vn6GJcMgul/wuS0je9OZ9gsL0zzDpKPVtcG1HaDVc+9y+qgXneTeUMbCqXJNpH1A==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: ajv: 6.12.6 debug: 4.3.4 - espree: 9.5.2 + espree: 9.6.1 globals: 13.20.0 ignore: 5.2.4 import-fresh: 3.3.0 @@ -713,13 +730,13 @@ packages: - supports-color dev: true - /@eslint/js@8.39.0: - resolution: {integrity: sha512-kf9RB0Fg7NZfap83B3QOqOGg9QmD9yBudqQXzzOtn3i4y7ZUXe5ONeW34Gwi+TxhH4mvj72R1Zc300KUMa9Bng==} + /@eslint/js@8.44.0: + resolution: {integrity: sha512-Ag+9YM4ocKQx9AarydN0KY2j0ErMHNIocPDrVo8zAE44xLTjEtz81OdR68/cydGtk6m6jDb5Za3r2useMzYmSw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@humanwhocodes/config-array@0.11.8: - resolution: {integrity: sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==} + /@humanwhocodes/config-array@0.11.10: + resolution: {integrity: sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==} engines: {node: '>=10.10.0'} dependencies: '@humanwhocodes/object-schema': 1.2.1 @@ -798,16 +815,16 @@ packages: '@types/tar-fs': 2.0.1 dev: true - /acorn-jsx@5.3.2(acorn@8.8.2): + /acorn-jsx@5.3.2(acorn@8.10.0): resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: acorn: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: - acorn: 8.8.2 + acorn: 8.10.0 dev: true - /acorn@8.8.2: - resolution: {integrity: sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==} + /acorn@8.10.0: + resolution: {integrity: sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==} engines: {node: '>=0.4.0'} hasBin: true dev: true @@ -949,8 +966,9 @@ packages: resolution: {integrity: sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==} dev: true - /ci-info@3.3.2: - resolution: {integrity: sha512-xmDt/QIAdeZ9+nfdPsaBCpMvHNLFiLdjj59qjqn+6iPe6YmHGQ35sBnQ8uslRBXFmXkiZQOJRjvQeoGppoTjjg==} + /ci-info@3.8.0: + resolution: {integrity: sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==} + engines: {node: '>=8'} dev: true /clean-regexp@1.0.0: @@ -1081,67 +1099,53 @@ packages: engines: {node: '>=10'} dev: true - /eslint-plugin-unicorn@42.0.0(eslint@8.39.0): - resolution: {integrity: sha512-ixBsbhgWuxVaNlPTT8AyfJMlhyC5flCJFjyK3oKE8TRrwBnaHvUbuIkCM1lqg8ryYrFStL/T557zfKzX4GKSlg==} - engines: {node: '>=12'} + /eslint-plugin-unicorn@48.0.0(eslint@8.45.0): + resolution: {integrity: sha512-8fk/v3p1ro34JSVDBEmtOq6EEQRpMR0iTir79q69KnXFZ6DJyPkT3RAi+ZoTqhQMdDSpGh8BGR68ne1sP5cnAA==} + engines: {node: '>=16'} peerDependencies: - eslint: '>=8.8.0' + eslint: '>=8.44.0' dependencies: - '@babel/helper-validator-identifier': 7.16.7 - ci-info: 3.3.2 + '@babel/helper-validator-identifier': 7.22.5 + '@eslint-community/eslint-utils': 4.4.0(eslint@8.45.0) + ci-info: 3.8.0 clean-regexp: 1.0.0 - eslint: 8.39.0 - eslint-utils: 3.0.0(eslint@8.39.0) - esquery: 1.4.0 + eslint: 8.45.0 + esquery: 1.5.0 indent-string: 4.0.0 - is-builtin-module: 3.1.0 + is-builtin-module: 3.2.1 + jsesc: 3.0.2 lodash: 4.17.21 pluralize: 8.0.0 read-pkg-up: 7.0.1 - regexp-tree: 0.1.24 - safe-regex: 2.1.1 - semver: 7.3.7 + regexp-tree: 0.1.27 + regjsparser: 0.10.0 + semver: 7.5.4 strip-indent: 3.0.0 dev: true - /eslint-scope@7.2.0: - resolution: {integrity: sha512-DYj5deGlHBfMt15J7rdtyKNq/Nqlv5KfU4iodrQ019XESsRnwXH9KAE0y3cwtUHDo2ob7CypAnCqefh6vioWRw==} + /eslint-scope@7.2.1: + resolution: {integrity: sha512-CvefSOsDdaYYvxChovdrPo/ZGt8d5lrJWleAc1diXRKhHGiTYEI26cvo8Kle/wGnsizoCJjK73FMg1/IkIwiNA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: esrecurse: 4.3.0 estraverse: 5.3.0 dev: true - /eslint-utils@3.0.0(eslint@8.39.0): - resolution: {integrity: sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==} - engines: {node: ^10.0.0 || ^12.0.0 || >= 14.0.0} - peerDependencies: - eslint: '>=5' - dependencies: - eslint: 8.39.0 - eslint-visitor-keys: 2.1.0 - dev: true - - /eslint-visitor-keys@2.1.0: - resolution: {integrity: sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==} - engines: {node: '>=10'} - dev: true - /eslint-visitor-keys@3.4.1: resolution: {integrity: sha512-pZnmmLwYzf+kWaM/Qgrvpen51upAktaaiI01nsJD/Yr3lMOdNtq0cxkrrg16w64VtisN6okbs7Q8AfGqj4c9fA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /eslint@8.39.0: - resolution: {integrity: sha512-mwiok6cy7KTW7rBpo05k6+p4YVZByLNjAZ/ACB9DRCu4YDRwjXI01tWHp6KAUWelsBetTxKK/2sHB0vdS8Z2Og==} + /eslint@8.45.0: + resolution: {integrity: sha512-pd8KSxiQpdYRfYa9Wufvdoct3ZPQQuVuU5O6scNgMuOMYuxvH0IGaYK0wUFjo4UYYQQCUndlXiMbnxopwvvTiw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} hasBin: true dependencies: - '@eslint-community/eslint-utils': 4.4.0(eslint@8.39.0) - '@eslint-community/regexpp': 4.5.1 - '@eslint/eslintrc': 2.0.3 - '@eslint/js': 8.39.0 - '@humanwhocodes/config-array': 0.11.8 + '@eslint-community/eslint-utils': 4.4.0(eslint@8.45.0) + '@eslint-community/regexpp': 4.6.1 + '@eslint/eslintrc': 2.1.0 + '@eslint/js': 8.44.0 + '@humanwhocodes/config-array': 0.11.10 '@humanwhocodes/module-importer': 1.0.1 '@nodelib/fs.walk': 1.2.8 ajv: 6.12.6 @@ -1150,9 +1154,9 @@ packages: debug: 4.3.4 doctrine: 3.0.0 escape-string-regexp: 4.0.0 - eslint-scope: 7.2.0 + eslint-scope: 7.2.1 eslint-visitor-keys: 3.4.1 - espree: 9.5.2 + espree: 9.6.1 esquery: 1.5.0 esutils: 2.0.3 fast-deep-equal: 3.1.3 @@ -1160,43 +1164,33 @@ packages: find-up: 5.0.0 glob-parent: 6.0.2 globals: 13.20.0 - grapheme-splitter: 1.0.4 + graphemer: 1.4.0 ignore: 5.2.4 - import-fresh: 3.3.0 imurmurhash: 0.1.4 is-glob: 4.0.3 is-path-inside: 3.0.3 - js-sdsl: 4.4.0 js-yaml: 4.1.0 json-stable-stringify-without-jsonify: 1.0.1 levn: 0.4.1 lodash.merge: 4.6.2 minimatch: 3.1.2 natural-compare: 1.4.0 - optionator: 0.9.1 + optionator: 0.9.3 strip-ansi: 6.0.1 - strip-json-comments: 3.1.1 text-table: 0.2.0 transitivePeerDependencies: - supports-color dev: true - /espree@9.5.2: - resolution: {integrity: sha512-7OASN1Wma5fum5SrNhFMAMJxOUAbhyfQ8dQ//PJaJbNw0URTPWqIghHWt1MmAANKhHZIYOHruW4Kw4ruUWOdGw==} + /espree@9.6.1: + resolution: {integrity: sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - acorn: 8.8.2 - acorn-jsx: 5.3.2(acorn@8.8.2) + acorn: 8.10.0 + acorn-jsx: 5.3.2(acorn@8.10.0) eslint-visitor-keys: 3.4.1 dev: true - /esquery@1.4.0: - resolution: {integrity: sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==} - engines: {node: '>=0.10'} - dependencies: - estraverse: 5.3.0 - dev: true - /esquery@1.5.0: resolution: {integrity: sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==} engines: {node: '>=0.10'} @@ -1345,8 +1339,8 @@ packages: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} dev: true - /grapheme-splitter@1.0.4: - resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==} + /graphemer@1.4.0: + resolution: {integrity: sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==} dev: true /has-flag@3.0.0: @@ -1448,8 +1442,8 @@ packages: resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==} dev: true - /is-builtin-module@3.1.0: - resolution: {integrity: sha512-OV7JjAgOTfAFJmHZLvpSTb4qi0nIILDV1gWPYDnDJUTNFM5aGlRAhk4QcT8i7TuAleeEV5Fdkqn3t4mS+Q11fg==} + /is-builtin-module@3.2.1: + resolution: {integrity: sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==} engines: {node: '>=6'} dependencies: builtin-modules: 3.3.0 @@ -1459,11 +1453,11 @@ packages: resolution: {integrity: sha512-ZYvCgrefwqoQ6yTyYUbQu64HsITZ3NfKX1lzaEYdkTDcfKzzCI/wthRRYKkdjHKFVgNiXKAKm65Zo1pk2as/QQ==} hasBin: true dependencies: - ci-info: 3.3.2 + ci-info: 3.8.0 dev: true - /is-core-module@2.9.0: - resolution: {integrity: sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==} + /is-core-module@2.12.1: + resolution: {integrity: sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==} dependencies: has: 1.0.3 dev: true @@ -1511,10 +1505,6 @@ packages: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} dev: true - /js-sdsl@4.4.0: - resolution: {integrity: sha512-FfVSdx6pJ41Oa+CF7RDaFmTnCaFhua+SNYQX74riGOpl96x+2jQCqEfQ2bnXu/5DPCqlRuiqyvTJM0Qjz26IVg==} - dev: true - /js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} dev: true @@ -1526,6 +1516,17 @@ packages: argparse: 2.0.1 dev: true + /jsesc@0.5.0: + resolution: {integrity: sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==} + hasBin: true + dev: true + + /jsesc@3.0.2: + resolution: {integrity: sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==} + engines: {node: '>=6'} + hasBin: true + dev: true + /json-fixer@1.6.15: resolution: {integrity: sha512-TuDuZ5KrgyjoCIppdPXBMqiGfota55+odM+j2cQ5rt/XKyKmqGB3Whz1F8SN8+60yYGy/Nu5lbRZ+rx8kBIvBw==} engines: {node: '>=10'} @@ -1651,8 +1652,8 @@ packages: resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} dependencies: hosted-git-info: 2.8.9 - resolve: 1.22.1 - semver: 5.7.1 + resolve: 1.22.2 + semver: 5.7.2 validate-npm-package-license: 3.0.4 dev: true @@ -1678,16 +1679,16 @@ packages: is-wsl: 2.2.0 dev: true - /optionator@0.9.1: - resolution: {integrity: sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==} + /optionator@0.9.3: + resolution: {integrity: sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==} engines: {node: '>= 0.8.0'} dependencies: + '@aashutoshrathi/word-wrap': 1.2.6 deep-is: 0.1.4 fast-levenshtein: 2.0.6 levn: 0.4.1 prelude-ls: 1.2.1 type-check: 0.4.0 - word-wrap: 1.2.3 dev: true /os-tmpdir@1.0.2: @@ -1739,7 +1740,7 @@ packages: resolution: {integrity: sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==} engines: {node: '>=8'} dependencies: - '@babel/code-frame': 7.16.7 + '@babel/code-frame': 7.22.5 error-ex: 1.3.2 json-parse-even-better-errors: 2.3.1 lines-and-columns: 1.2.4 @@ -1789,6 +1790,14 @@ packages: resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==} engines: {node: '>=10.13.0'} hasBin: true + requiresBuild: true + dev: true + optional: true + + /prettier@3.0.0: + resolution: {integrity: sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==} + engines: {node: '>=14'} + hasBin: true dev: true /process-nextick-args@2.0.1: @@ -1852,9 +1861,16 @@ packages: resolution: {integrity: sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==} dev: true - /regexp-tree@0.1.24: - resolution: {integrity: sha512-s2aEVuLhvnVJW6s/iPgEGK6R+/xngd2jNQ+xy4bXNDKxZKJH6jpPHY6kVeVv1IeLCHgswRj+Kl3ELaDjG6V1iw==} + /regexp-tree@0.1.27: + resolution: {integrity: sha512-iETxpjK6YoRWJG5o6hXLwvjYAoW+FEZn9os0PD/b6AP6xQwsa/Y7lCVgIixBbUPMfhu+i2LtdeAqVTgGlQarfA==} + hasBin: true + dev: true + + /regjsparser@0.10.0: + resolution: {integrity: sha512-qx+xQGZVsy55CH0a1hiVwHmqjLryfh7wQyF5HO07XJ9f7dQMY/gPQHhlyDkIzJKC+x2fUCpCcUODUUUFrm7SHA==} hasBin: true + dependencies: + jsesc: 0.5.0 dev: true /require-directory@2.1.1: @@ -1871,11 +1887,11 @@ packages: engines: {node: '>=4'} dev: true - /resolve@1.22.1: - resolution: {integrity: sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==} + /resolve@1.22.2: + resolution: {integrity: sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==} hasBin: true dependencies: - is-core-module: 2.9.0 + is-core-module: 2.12.1 path-parse: 1.0.7 supports-preserve-symlinks-flag: 1.0.0 dev: true @@ -1926,23 +1942,17 @@ packages: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} dev: true - /safe-regex@2.1.1: - resolution: {integrity: sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==} - dependencies: - regexp-tree: 0.1.24 - dev: true - /safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} dev: true - /semver@5.7.1: - resolution: {integrity: sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==} + /semver@5.7.2: + resolution: {integrity: sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==} hasBin: true dev: true - /semver@7.3.7: - resolution: {integrity: sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==} + /semver@7.5.4: + resolution: {integrity: sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==} engines: {node: '>=10'} hasBin: true dependencies: @@ -1979,11 +1989,11 @@ packages: - supports-color dev: true - /spdx-correct@3.1.1: - resolution: {integrity: sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==} + /spdx-correct@3.2.0: + resolution: {integrity: sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==} dependencies: spdx-expression-parse: 3.0.1 - spdx-license-ids: 3.0.11 + spdx-license-ids: 3.0.13 dev: true /spdx-exceptions@2.3.0: @@ -1994,11 +2004,11 @@ packages: resolution: {integrity: sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==} dependencies: spdx-exceptions: 2.3.0 - spdx-license-ids: 3.0.11 + spdx-license-ids: 3.0.13 dev: true - /spdx-license-ids@3.0.11: - resolution: {integrity: sha512-Ctl2BrFiM0X3MANYgj3CkygxhRmr9mi6xhejbdO960nF6EDJApTYpn0BQnDKlnNBULKiCN1n3w9EBkHK8ZWg+g==} + /spdx-license-ids@3.0.13: + resolution: {integrity: sha512-XkD+zwiqXHikFZm4AX/7JSCXA98U5Db4AFd5XUg/+9UNtnH75+Z9KxtpYiJZx36mUDVOwH83pl7yvCer6ewM3w==} dev: true /string-width@4.2.3: @@ -2077,7 +2087,7 @@ packages: dev: true /targz@1.0.1: - resolution: {integrity: sha1-j3alI2lM3t+7XWCkB2/27uzFOY8=} + resolution: {integrity: sha512-6q4tP9U55mZnRuMTBqnqc3nwYQY3kv+QthCFZuMk+Tn1qYUnMPmL/JZ/mzgXINzFpSqfU+242IFmFU9VPvqaQw==} dependencies: tar-fs: 1.16.3 dev: true @@ -2154,7 +2164,7 @@ packages: /validate-npm-package-license@3.0.4: resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==} dependencies: - spdx-correct: 3.1.1 + spdx-correct: 3.2.0 spdx-expression-parse: 3.0.1 dev: true @@ -2181,11 +2191,6 @@ packages: isexe: 2.0.0 dev: true - /word-wrap@1.2.3: - resolution: {integrity: sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==} - engines: {node: '>=0.10.0'} - dev: true - /wrap-ansi@6.2.0: resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==} engines: {node: '>=8'} diff --git a/recipes/basecamp/webview.js b/recipes/basecamp/webview.js index 7d1375150..f0c90b560 100644 --- a/recipes/basecamp/webview.js +++ b/recipes/basecamp/webview.js @@ -16,10 +16,10 @@ module.exports = Ferdium => { const modal = document.createElement('div'); const waitFor = (condition, callback) => { - if (!condition()) { - window.setTimeout(waitFor.bind(null, condition, callback), 100); - } else { + if (condition()) { callback(); + } else { + window.setTimeout(waitFor.bind(null, condition, callback), 100); } }; function showModal(text) { diff --git a/recipes/chatwork/webview.js b/recipes/chatwork/webview.js index 6b961ed2c..d120a329f 100644 --- a/recipes/chatwork/webview.js +++ b/recipes/chatwork/webview.js @@ -16,18 +16,18 @@ module.exports = Ferdium => { if (count > 0) { if ( - !room + room .querySelector('img.sc-gqjmRU') .getAttribute('src') .includes('avatar') ) { + directCount++; + } else { if (unreadBadgeHasMention) { directCount++; } else { indirectCount++; } - } else { - directCount++; } } }); diff --git a/recipes/dialpad/webview.js b/recipes/dialpad/webview.js index 75b53d6e9..45d4b7e85 100644 --- a/recipes/dialpad/webview.js +++ b/recipes/dialpad/webview.js @@ -1,14 +1,22 @@ const _path = _interopRequireDefault(require('path')); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} -module.exports = (Ferdium) => { +module.exports = Ferdium => { const getMessages = () => { var unreadCount = 0; - $.each($('[data-qa-has-unreads]'), (idx, item) => unreadCount += Ferdium.safeParseInt(item.attributes["data-qa-has-unreads"].value)); + $.each( + $('[data-qa-has-unreads]'), + (idx, item) => + (unreadCount += Ferdium.safeParseInt( + item.attributes['data-qa-has-unreads'].value, + )), + ); Ferdium.setBadge(unreadCount); - } + }; Ferdium.loop(getMessages); diff --git a/recipes/element/webview.js b/recipes/element/webview.js index f88baac93..8f4c43803 100644 --- a/recipes/element/webview.js +++ b/recipes/element/webview.js @@ -1,11 +1,12 @@ module.exports = Ferdium => { function getMessages() { - const matches = document.querySelector('title').textContent - .match('(?<=\\[)\\d+(?=])'); - const directCount = Ferdium.safeParseInt(matches !== null ? matches[0] : 0); - const indirectCount = document.querySelector('.mx_SpaceTreeLevel') - .querySelectorAll('.mx_NotificationBadge_dot') - .length; + const matches = document + .querySelector('title') + .textContent.match('(?<=\\[)\\d+(?=])'); + const directCount = Ferdium.safeParseInt(matches === null ? 0 : matches[0]); + const indirectCount = document + .querySelector('.mx_SpaceTreeLevel') + .querySelectorAll('.mx_NotificationBadge_dot').length; Ferdium.setBadge(directCount, indirectCount); } diff --git a/recipes/freshdesk/webview.js b/recipes/freshdesk/webview.js index 3e0a201a5..d3c18a554 100644 --- a/recipes/freshdesk/webview.js +++ b/recipes/freshdesk/webview.js @@ -1,14 +1,15 @@ module.exports = Ferdium => { const getMessages = () => { - $.get('/api/_/tickets?filter=unresolved', (data) => { + $.get('/api/_/tickets?filter=unresolved', data => { Ferdium.setBadge(data.tickets.length); }); }; Ferdium.loop(getMessages); -/* block popups (prevents freshconnect from opening in a new window) */ - window.open = (function(url, name) { + /* block popups (prevents freshconnect from opening in a new window) */ + window.open = function (url, name) { + // eslint-disable-next-line no-console console.log(`blocked window.open(${url}, ${name})`); - }); + }; }; diff --git a/recipes/googlecalendar/webview-unsafe.js b/recipes/googlecalendar/webview-unsafe.js index 784060012..0f4833e04 100644 --- a/recipes/googlecalendar/webview-unsafe.js +++ b/recipes/googlecalendar/webview-unsafe.js @@ -2,10 +2,10 @@ let modal; let updates = 0; const waitFor = (condition, callback) => { - if (!condition()) { - window.setTimeout(waitFor.bind(null, condition, callback), 100); - } else { + if (condition()) { callback(); + } else { + window.setTimeout(waitFor.bind(null, condition, callback), 100); } }; diff --git a/recipes/grape/index.js b/recipes/grape/index.js index 593f0261e..1e2a187c0 100644 --- a/recipes/grape/index.js +++ b/recipes/grape/index.js @@ -1,18 +1,48 @@ -function _asyncToGenerator(fn) { return function () { const gen = Reflect.apply(fn, this, arguments); return new Promise((resolve, reject) => { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then((value) => { step('next', value); }, (error) => { step('throw', error); }); } } return step('next'); }); }; } - -module.exports = Ferdium => class Grape extends Ferdium { - validateUrl(url) { - return _asyncToGenerator(function* () { - try { - const resp = yield window.fetch(url, { - method: 'GET', - }); - return resp.status === 200; - } catch (error) { - console.error(error); +function _asyncToGenerator(fn) { + return function () { + const gen = Reflect.apply(fn, this, arguments); + return new Promise((resolve, reject) => { + function step(key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + if (info.done) { + resolve(value); + } else { + // eslint-disable-next-line consistent-return + return Promise.resolve(value).then( + value => { + step('next', value); + }, + error => { + step('throw', error); + }, + ); + } } + return step('next'); + }); + }; +} + +module.exports = Ferdium => + class Grape extends Ferdium { + validateUrl(url) { + return _asyncToGenerator(function* () { + try { + const resp = yield window.fetch(url, { + method: 'GET', + }); + return resp.status === 200; + } catch (error) { + console.error(error); + } - return false; - })(); - } -}; + return false; + })(); + } + }; diff --git a/recipes/hipchat/index.js b/recipes/hipchat/index.js index ce3256b9f..e786bcbbc 100644 --- a/recipes/hipchat/index.js +++ b/recipes/hipchat/index.js @@ -1,27 +1,57 @@ -function _asyncToGenerator(fn) { return function () { const gen = Reflect.apply(fn, this, arguments); return new Promise((resolve, reject) => { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then((value) => { step('next', value); }, (error) => { step('throw', error); }); } } return step('next'); }); }; } +function _asyncToGenerator(fn) { + return function () { + const gen = Reflect.apply(fn, this, arguments); + return new Promise((resolve, reject) => { + function step(key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + if (info.done) { + resolve(value); + } else { + // eslint-disable-next-line consistent-return + return Promise.resolve(value).then( + value => { + step('next', value); + }, + error => { + step('throw', error); + }, + ); + } + } + return step('next'); + }); + }; +} -module.exports = Ferdium => class HipChat extends Ferdium { - validateUrl(url) { - return _asyncToGenerator(function* () { - try { - const resp = yield window.fetch(`${url}/api/features`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }); - const data = yield resp.json(); +module.exports = Ferdium => + class HipChat extends Ferdium { + validateUrl(url) { + return _asyncToGenerator(function* () { + try { + const resp = yield window.fetch(`${url}/api/features`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }); + const data = yield resp.json(); - return Object.hasOwnProperty.call(data, 'features'); - } catch (error) { - console.error(error); - } + return Object.hasOwnProperty.call(data, 'features'); + } catch (error) { + console.error(error); + } - return false; - })(); - } + return false; + })(); + } - buildUrl(url) { - return `${url}/chat`; - } -}; + buildUrl(url) { + return `${url}/chat`; + } + }; diff --git a/recipes/idobata/webview.js b/recipes/idobata/webview.js index b6cbbe79d..6d633a298 100644 --- a/recipes/idobata/webview.js +++ b/recipes/idobata/webview.js @@ -1,7 +1,7 @@ module.exports = Ferdium => { const getMessages = () => { const title = document.querySelector('title').textContent.match(/\d+/); - const count = title !== null ? title[0] : 0; + const count = title === null ? 0 : title[0]; Ferdium.setBadge(count); }; diff --git a/recipes/kiwiirc/webview.js b/recipes/kiwiirc/webview.js index 0c362f09b..c97acbf28 100644 --- a/recipes/kiwiirc/webview.js +++ b/recipes/kiwiirc/webview.js @@ -8,21 +8,26 @@ module.exports = Ferdium => { const getMessages = function getMessages() { // eslint-disable-next-line no-undef const unreadChannelsCount = kiwi.state.networks.reduce((count, network) => { + // eslint-disable-next-line no-param-reassign return (count += network.buffers.filter(buffer => { return !buffer.name.startsWith('*') && buffer.flags.unread !== 0; }).length); }, 0); // eslint-disable-next-line no-undef - const mentionedChannelsCount = kiwi.state.networks.reduce((count, network) => { - return (count += network.buffers.filter(buffer => { - return ( - !buffer.name.startsWith('*') && - buffer.flags.unread !== 0 && - buffer.flags.highlight - ); - }).length); - }, 0); + const mentionedChannelsCount = kiwi.state.networks.reduce( + (count, network) => { + // eslint-disable-next-line no-param-reassign + return (count += network.buffers.filter(buffer => { + return ( + !buffer.name.startsWith('*') && + buffer.flags.unread !== 0 && + buffer.flags.highlight + ); + }).length); + }, + 0, + ); // set Ferdium badges Ferdium.setBadge(mentionedChannelsCount, unreadChannelsCount); diff --git a/recipes/messenger/webview.js b/recipes/messenger/webview.js index 7fc8ed640..c62123ed4 100644 --- a/recipes/messenger/webview.js +++ b/recipes/messenger/webview.js @@ -2,9 +2,9 @@ function hideInstallMessage() { const installMessage = document.querySelector('.usczdcwk'); if (installMessage) { installMessage.style.display = - installMessage.style.display != 'none' - ? 'none' - : installMessage.style.display; + installMessage.style.display === 'none' + ? installMessage.style.display + : 'none'; } } @@ -17,7 +17,9 @@ module.exports = Ferdium => { * try the counting with the new UI */ for (let href of ['/', '/requests/', '/marketplace/']) { - const elem = document.querySelector(`a[href^='${href}t/'][role='link'][tabindex='0']`).ariaLabel; + const elem = document.querySelector( + `a[href^='${href}t/'][role='link'][tabindex='0']`, + ).ariaLabel; if (elem) { newMessengerUI = true; const match = elem.match(/(\d+)/g); @@ -31,18 +33,26 @@ module.exports = Ferdium => { * do the old counting if the interface is not the last one */ if (!newMessengerUI) { - count = [...document.querySelectorAll('.bp9cbjyn.j83agx80.owycx6da:not(.btwxx1t3)')] + count = [ + ...document.querySelectorAll( + '.bp9cbjyn.j83agx80.owycx6da:not(.btwxx1t3)', + ), + ] .map(elem => { - const hasPing = !!elem.querySelector('.pq6dq46d.is6700om.qu0x051f.esr5mh6w.e9989ue4.r7d6kgcz.s45kfl79.emlxlaya.bkmhp75w.spb7xbtv.cyypbtt7.fwizqjfa'); - const isMuted = !!elem.querySelector('.a8c37x1j.ms05siws.l3qrxjdp.b7h9ocf4.trssfv1o'); + const hasPing = !!elem.querySelector( + '.pq6dq46d.is6700om.qu0x051f.esr5mh6w.e9989ue4.r7d6kgcz.s45kfl79.emlxlaya.bkmhp75w.spb7xbtv.cyypbtt7.fwizqjfa', + ); + const isMuted = !!elem.querySelector( + '.a8c37x1j.ms05siws.l3qrxjdp.b7h9ocf4.trssfv1o', + ); return hasPing && !isMuted; }) .reduce((prev, curr) => prev + curr, 0); /* - * add count of message requests on top of notification counter - */ + * add count of message requests on top of notification counter + */ const messageRequestsElement = document.querySelector('._5nxf'); if (messageRequestsElement) { count += Ferdium.safeParseInt(messageRequestsElement.textContent); diff --git a/recipes/pleroma/index.js b/recipes/pleroma/index.js index 67a0e190c..205005983 100644 --- a/recipes/pleroma/index.js +++ b/recipes/pleroma/index.js @@ -1,19 +1,21 @@ -module.exports = Ferdium => class Pleroma extends Ferdium { - async validateUrl(url) { - try { - const resp = await window.fetch(`${url}/api/v1/instance`, { - Accept: 'application/json', - }); - const data = await resp.json(); - const version = data.version; - return typeof (version) === 'string' && version.includes('Pleroma'); - } catch (error) { - console.log('Pleroma server validation error', error); +module.exports = Ferdium => + class Pleroma extends Ferdium { + async validateUrl(url) { + try { + const resp = await window.fetch(`${url}/api/v1/instance`, { + Accept: 'application/json', + }); + const data = await resp.json(); + const version = data.version; + return typeof version === 'string' && version.includes('Pleroma'); + } catch (error) { + // eslint-disable-next-line no-console + console.log('Pleroma server validation error', error); + } + return false; } - return false; - } - buildUrl(url) { - return `${url}/main/friends`; - } -}; + buildUrl(url) { + return `${url}/main/friends`; + } + }; diff --git a/recipes/pleroma/webview.js b/recipes/pleroma/webview.js index 41516f6e6..703a53fab 100644 --- a/recipes/pleroma/webview.js +++ b/recipes/pleroma/webview.js @@ -16,6 +16,7 @@ const getInstanceConfig = async () => { const pleromaFeConfig = frontendConfig.pleroma_fe || {}; return { ...staticConfig, ...pleromaFeConfig }; } catch (error) { + // eslint-disable-next-line no-console console.log('Failed to load dynamic frontend configuration', error); return staticConfig; } @@ -162,6 +163,7 @@ module.exports = Ferdium => { }); }, error => { + // eslint-disable-next-line no-console console.log('Failed to load instance logo', error); Ferdium.loop(getMessages); }, diff --git a/recipes/schildichat/webview.js b/recipes/schildichat/webview.js index bd7eef874..d465ab601 100644 --- a/recipes/schildichat/webview.js +++ b/recipes/schildichat/webview.js @@ -1,12 +1,13 @@ module.exports = Ferdium => { function getMessages() { - const directMatches = document.querySelector('title').textContent - .match('(?<=\\[)\\d+(?=])'); + const directMatches = document + .querySelector('title') + .textContent.match('(?<=\\[)\\d+(?=])'); Ferdium.setBadge( - Ferdium.safeParseInt(directMatches !== null ? directMatches[0] : 0), - document.querySelector('.mx_SpaceTreeLevel') - .querySelectorAll('.mx_NotificationBadge_dot') - .length + Ferdium.safeParseInt(directMatches === null ? 0 : directMatches[0]), + document + .querySelector('.mx_SpaceTreeLevel') + .querySelectorAll('.mx_NotificationBadge_dot').length, ); } diff --git a/recipes/skype/webview.js b/recipes/skype/webview.js index db97d9869..6cd40f53f 100644 --- a/recipes/skype/webview.js +++ b/recipes/skype/webview.js @@ -1,6 +1,8 @@ const _path = _interopRequireDefault(require('path')); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} module.exports = (Ferdium, settings) => { const getMessages = () => { @@ -11,10 +13,13 @@ module.exports = (Ferdium, settings) => { const children = container.children; if (children.length === 3) { + // eslint-disable-next-line unicorn/prefer-at const elementContainer = children[children.length - 1]; if (elementContainer) { - const element = elementContainer.querySelector('[data-text-as-pseudo-element]'); + const element = elementContainer.querySelector( + '[data-text-as-pseudo-element]', + ); if (element && element.dataset) { count = Ferdium.safeParseInt(element.dataset.textAsPseudoElement); } @@ -31,21 +36,27 @@ module.exports = (Ferdium, settings) => { Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); // TODO: See how this can be moved into the main ferdium app and sent as an ipc message for opening with a new window or same Ferdium recipe's webview based on user's preferences - document.addEventListener('click', event => { - const link = event.target.closest('a[href^="http"]'); - const button = event.target.closest('button[title^="http"]'); - - if (link || button) { - const url = link ? link.getAttribute('href') : button.getAttribute('title'); - - event.preventDefault(); - event.stopPropagation(); - - if (settings.trapLinkClicks === true) { - window.location.href = url; - } else { - Ferdium.openNewWindow(url); + document.addEventListener( + 'click', + event => { + const link = event.target.closest('a[href^="http"]'); + const button = event.target.closest('button[title^="http"]'); + + if (link || button) { + const url = link + ? link.getAttribute('href') + : button.getAttribute('title'); + + event.preventDefault(); + event.stopPropagation(); + + if (settings.trapLinkClicks === true) { + window.location.href = url; + } else { + Ferdium.openNewWindow(url); + } } - } - }, true); + }, + true, + ); }; diff --git a/recipes/snapchat/webview.js b/recipes/snapchat/webview.js index 78a24557b..15877c7be 100644 --- a/recipes/snapchat/webview.js +++ b/recipes/snapchat/webview.js @@ -7,7 +7,7 @@ function _interopRequireDefault(obj) { module.exports = Ferdium => { const getMessages = () => { const title = document.querySelector('title').textContent.match(/\d+/); - const count = title !== null ? title[0] : 0; + const count = title === null ? 0 : title[0]; Ferdium.setBadge(count); }; diff --git a/recipes/tiktok/webview.js b/recipes/tiktok/webview.js index 6f78019f2..93fb165f4 100644 --- a/recipes/tiktok/webview.js +++ b/recipes/tiktok/webview.js @@ -6,11 +6,18 @@ function _interopRequireDefault(obj) { module.exports = Ferdium => { const getMessages = () => { - const selNotifications = document.querySelector("div.tiktok-1b4xcc5-DivHeaderInboxContainer.e18kkhh40 > sup"); - const selDM = document.querySelector("div.tiktok-1ibfxbr-DivMessageIconContainer.e1nx07zo0 > sup"); + const selNotifications = document.querySelector( + 'div.tiktok-1b4xcc5-DivHeaderInboxContainer.e18kkhh40 > sup', + ); + const selDM = document.querySelector( + 'div.tiktok-1ibfxbr-DivMessageIconContainer.e1nx07zo0 > sup', + ); - const countNotifications = (selNotifications != null) ? Ferdium.safeParseInt(selNotifications.outerText) : 0; - const countDM = (selDM != null) ? Ferdium.safeParseInt(selDM.outerText) : 0; + const countNotifications = + selNotifications == null + ? 0 + : Ferdium.safeParseInt(selNotifications.outerText); + const countDM = selDM == null ? 0 : Ferdium.safeParseInt(selDM.outerText); const count = countNotifications + countDM; diff --git a/recipes/whatsapp/webview-unsafe.js b/recipes/whatsapp/webview-unsafe.js index b6b365b70..e5c5f08a7 100644 --- a/recipes/whatsapp/webview-unsafe.js +++ b/recipes/whatsapp/webview-unsafe.js @@ -10,33 +10,32 @@ window.pushStateBehavior = PUSHSTATE_THROTTLE; window.pushStateCount = 0; function pushStateThrottled() { - if (window.pushStateCount < PUSHSTATE_THROTTLE_THRESHOLD) - { - window.shPushState.apply(window.history, arguments); - window.pushStateCount++; - - if (window.pushStateCount == PUSHSTATE_THROTTLE_THRESHOLD) - setTimeout(() => { - window.pushStateCount = 0; - }, - 5000); - } - else - { - console.log("Pushstate temporarily blocked!"); - } + if (window.pushStateCount < PUSHSTATE_THROTTLE_THRESHOLD) { + window.shPushState.apply(window.history, arguments); + window.pushStateCount++; + + if (window.pushStateCount == PUSHSTATE_THROTTLE_THRESHOLD) + setTimeout(() => { + window.pushStateCount = 0; + }, 5000); + } else { + // eslint-disable-next-line no-console + console.log('Pushstate temporarily blocked!'); + } } function pushStateOneShot() { - window.shPushState.apply(window.history, arguments); + window.shPushState.apply(window.history, arguments); - window.history.pushState = function() {}; + window.history.pushState = function () {}; - console.log("Pushstate Disabled!"); + // eslint-disable-next-line no-console + console.log('Pushstate Disabled!'); } -if (window.pushStateBehavior != PUSHSTATE_NORMAL) -{ - window.history.pushState = - window.pushStateBehavior == PUSHSTATE_THROTTLE ? pushStateThrottled : pushStateOneShot; +if (window.pushStateBehavior != PUSHSTATE_NORMAL) { + window.history.pushState = + window.pushStateBehavior == PUSHSTATE_THROTTLE + ? pushStateThrottled + : pushStateOneShot; } diff --git a/recipes/whatsapp/webview.js b/recipes/whatsapp/webview.js index e2496bed3..abf1b6235 100644 --- a/recipes/whatsapp/webview.js +++ b/recipes/whatsapp/webview.js @@ -1,42 +1,21 @@ const _path = _interopRequireDefault(require('path')); function _interopRequireDefault(obj) { - return obj && obj.__esModule ? obj : {default: obj}; + return obj && obj.__esModule ? obj : { default: obj }; } module.exports = Ferdium => { - let dbCache + let dbCache; const getMessages = () => { - if(!dbCache) { - const dbsPromise = indexedDB.databases() - dbsPromise.then((databases) => { - for(let index in databases) { - //Wait for model-storage db to be available before calling indexedDB.open(). This is to make sure whatsapp created the model-storage DB - if(databases[index].name === "model-storage") { - const request = window.indexedDB.open("model-storage"); - request.onsuccess = () => { - dbCache = request.result; - //This will be called when db.delete is triggered, we need to close and set dbCache to null to trigger lookup again - dbCache.onversionchange = () => { - dbCache.close() - dbCache = null - }; - } - request.addEventListener('error', () => { - console.error("Opening model-storage database failed:", event); - }) - } - } - }) - } else { + if (dbCache) { let unreadCount = 0; let unreadMutedCount = 0; const txn = dbCache.transaction('chat', 'readonly'); const store = txn.objectStore('chat'); const query = store.getAll(); - query.onsuccess = (event) => { + query.onsuccess = event => { for (const chat of event.target.result) { if (chat.unreadCount > 0) { if (chat.muteExpiration > 0 || chat.isAutoMuted) { @@ -50,11 +29,32 @@ module.exports = Ferdium => { Ferdium.setBadge(unreadCount, unreadMutedCount); }; - query.addEventListener('error', (event) => { - console.error("Loading data from database failed:", event); - }) + query.addEventListener('error', event => { + console.error('Loading data from database failed:', event); + }); + } else { + const dbsPromise = indexedDB.databases(); + dbsPromise.then(databases => { + for (let index in databases) { + //Wait for model-storage db to be available before calling indexedDB.open(). This is to make sure whatsapp created the model-storage DB + if (databases[index].name === 'model-storage') { + const request = window.indexedDB.open('model-storage'); + request.onsuccess = () => { + dbCache = request.result; + //This will be called when db.delete is triggered, we need to close and set dbCache to null to trigger lookup again + dbCache.onversionchange = () => { + dbCache.close(); + dbCache = null; + }; + }; + request.addEventListener('error', () => { + console.error('Opening model-storage database failed:', event); + }); + } + } + }); } - } + }; // inject webview hacking script Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); @@ -74,14 +74,12 @@ module.exports = Ferdium => { Ferdium.releaseServiceWorkers(); }); - Ferdium.handleDarkMode((isEnabled) => { - + Ferdium.handleDarkMode(isEnabled => { if (isEnabled) { document.body.classList.add('dark'); } else { document.body.classList.remove('dark'); } - }); Ferdium.loop(loopFunc); diff --git a/recipes/workplace/webview.js b/recipes/workplace/webview.js index 8ee283b16..23bafcb6c 100644 --- a/recipes/workplace/webview.js +++ b/recipes/workplace/webview.js @@ -16,16 +16,16 @@ module.exports = Ferdium => { } if (chatsElement) { - if (!chatsElement.hasAttribute('aria-current')) { + if (chatsElement.hasAttribute('aria-current')) { + direct = document.querySelectorAll( + '[data-pagelet="WorkGalahadChannel"] .uiList [role="gridcell"] [role="button"] .oxk9n0fw', + ).length; + } else { const chatMessages = chatsElement.querySelector('span'); if (chatMessages) { direct = Ferdium.safeParseInt(chatMessages.textContent); } - } else { - direct = document.querySelectorAll( - '[data-pagelet="WorkGalahadChannel"] .uiList [role="gridcell"] [role="button"] .oxk9n0fw', - ).length; } } diff --git a/recipes/zalo/webview.js b/recipes/zalo/webview.js index 8e4c3cdea..5a627e25d 100644 --- a/recipes/zalo/webview.js +++ b/recipes/zalo/webview.js @@ -5,46 +5,59 @@ module.exports = Ferdium => { const unreadRed = document.querySelector('.unread-red'); if (unreadRed !== null) { switch (unreadRed.classList[1]) { - case 'fa-num1': + case 'fa-num1': { count = 1; break; - case 'fa-num2': + } + case 'fa-num2': { count = 2; break; - case 'fa-num3': + } + case 'fa-num3': { count = 3; break; - case 'fa-num4': + } + case 'fa-num4': { count = 4; break; - case 'fa-num5': + } + case 'fa-num5': { count = 5; break; + } default: { // fa-num5plus - const convUnread = document.querySelectorAll('.conv-unread:not(.func-unread__muted)'); - if (convUnread.length === 0) - count = 6; // 5+ + const convUnread = document.querySelectorAll( + '.conv-unread:not(.func-unread__muted)', + ); + if (convUnread.length === 0) count = 6; // 5+ else for (const convUnreadItem of convUnread) { switch (convUnreadItem.classList[1]) { - case 'fa-1_24_Line': + case 'fa-1_24_Line': { count = count + 1; break; - case 'fa-2_24_Line': + } + case 'fa-2_24_Line': { count = count + 2; break; - case 'fa-3_24_Line': + } + case 'fa-3_24_Line': { count = count + 3; break; - case 'fa-4_24_Line': + } + case 'fa-4_24_Line': { count = count + 4; break; - case 'fa-5_24_Line': + } + case 'fa-5_24_Line': { count = count + 5; break; - default: // fa-5plus_24_Line + } + default: { + // fa-5plus_24_Line count = count + 6; + } } } } @@ -53,4 +66,4 @@ module.exports = Ferdium => { Ferdium.setBadge(count); }; Ferdium.loop(getMessages); -}; \ No newline at end of file +}; diff --git a/scripts/create.js b/scripts/create.js index 199a23b36..7d3abea6a 100644 --- a/scripts/create.js +++ b/scripts/create.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /** * Create a new recipe for your service */ @@ -20,17 +21,13 @@ pnpm create WhatsApp FerdiumDev const recipeName = process.argv[2]; const recipe = recipeName.toLowerCase().replace(/\s/g, '-'); const folderName = process.argv[3] || 'Ferdium'; -const filesThatNeedTextReplace = [ - 'package.json', - 'index.js', - 'webview.js', -]; +const filesThatNeedTextReplace = ['package.json', 'index.js', 'webview.js']; -const toPascalCase = (str) => { +const toPascalCase = str => { const words = str .replace(/[^a-z]/g, '') .split(/\W/) - .map((word) => { + .map(word => { if (word.length === 0) { return word; } @@ -38,7 +35,7 @@ const toPascalCase = (str) => { return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); }); return words.join(''); -} +}; const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only containing a-z, for usage as the JavaScript class name (async () => { @@ -76,10 +73,12 @@ const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only cont // Replace placeholders with the recipe-specific values for (const file of filesThatNeedTextReplace) { const filePath = path.join(newRecipeFolder, file); + // eslint-disable-next-line no-await-in-loop let contents = await fs.readFile(filePath, 'utf8'); contents = contents.replace(/SERVICE/g, recipe); contents = contents.replace(/SNAME/g, recipeName); contents = contents.replace(/SPASCAL/g, pascalCasedName); + // eslint-disable-next-line no-await-in-loop await fs.writeFile(filePath, contents); } console.log('[Info] Prepared new recipe'); diff --git a/scripts/package.js b/scripts/package.js index e1e3d5c35..387e62de2 100644 --- a/scripts/package.js +++ b/scripts/package.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /** * Package all recipes */ @@ -70,6 +71,7 @@ const compress = (src, dest) => // Check that each mandatory file exists for (let file of mandatoryFiles) { const filePath = path.join(recipeSrc, file); + // eslint-disable-next-line no-await-in-loop if (!(await fs.pathExists(filePath))) { console.log( `⚠️ Couldn't package "${recipe}": Folder doesn't contain a "${file}".`, @@ -95,6 +97,7 @@ const compress = (src, dest) => // Check that user.js does not exist const userJs = path.join(recipeSrc, 'user.js'); + // eslint-disable-next-line no-await-in-loop if (await fs.pathExists(userJs)) { console.log( `⚠️ Couldn't package "${recipe}": Folder contains a "user.js".`, @@ -105,6 +108,7 @@ const compress = (src, dest) => // Read package.json const packageJson = path.join(recipeSrc, 'package.json'); + // eslint-disable-next-line no-await-in-loop const config = await fs.readJson(packageJson); // Make sure it contains all required fields @@ -227,6 +231,7 @@ const compress = (src, dest) => const relativeRepoSrc = path.relative(repoRoot, recipeSrc); // Check for changes in recipe's directory, and if changes are present, then the changes should contain a version bump + // eslint-disable-next-line no-await-in-loop await git.diffSummary(relativeRepoSrc, (err, result) => { if (err) { configErrors.push( @@ -239,11 +244,7 @@ const compress = (src, dest) => result.deletions !== 0) ) { const pkgJsonRelative = path.relative(repoRoot, packageJson); - if (!result.files.some(({ file }) => file === pkgJsonRelative)) { - configErrors.push( - `Found changes in '${relativeRepoSrc}' without the corresponding version bump in '${pkgJsonRelative}'`, - ); - } else { + if (result.files.some(({ file }) => file === pkgJsonRelative)) { git.diff(pkgJsonRelative, (_diffErr, diffResult) => { if (diffResult && !pkgVersionChangedMatcher.test(diffResult)) { configErrors.push( @@ -251,6 +252,10 @@ const compress = (src, dest) => ); } }); + } else { + configErrors.push( + `Found changes in '${relativeRepoSrc}' without the corresponding version bump in '${pkgJsonRelative}'`, + ); } } }); @@ -291,7 +296,7 @@ const compress = (src, dest) => recipeList = recipeList.sort((a, b) => { let textA = a.id.toLowerCase(); let textB = b.id.toLowerCase(); - return textA < textB ? -1 : (textA > textB ? 1 : 0); + return textA < textB ? -1 : textA > textB ? 1 : 0; }); await fs.writeJson(allJson, recipeList, { spaces: 2,