From 8da9316f7329399613489879cd822925d62431d8 Mon Sep 17 00:00:00 2001 From: Jean Date: Fri, 15 Aug 2025 08:39:56 -0700 Subject: [PATCH] Updating extension to use MetamorPOV library --- README.md | 5 +- flake.lock | 16 +- flake.nix | 4 +- package-lock.json | 483 ++++++++++++----------------------------- package.json | 11 +- src/replace-words.js | 507 +------------------------------------------ 6 files changed, 165 insertions(+), 861 deletions(-) diff --git a/README.md b/README.md index d5e185c..26fca29 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MetamorPOV -When enabled for a website, this extension will look for markers (such as Y/n, pov/s, and vrb/do/present/) used to replace specific pronouns. If found, it will replace those markers with your pronouns. You can also choose what point-of-view you want to read in: first, second, or third-person perspective. +When enabled for a website, this extension will translate specific markers such as Y/n, pov/s, and vrb/present/do/ into your pronouns. You can also choose what point-of-view you want to read in: first, second, or third-person perspective. - Your choice of name - Your choice of pronouns, including neopronouns @@ -48,8 +48,7 @@ npm run test-chrome ## Copyright and License - Portions of MetamorPOV are derived from [InteractiveFics](https://github.com/interactivefics/interactive-fics), licensed under [MIT](third-party-licenses/LICENSE-InteractiveFics), copyrighted 2015–2023 by Mariam Maarouf. -- MetamorPOV supports verb conjugation with [RosaeNLG](https://rosaenlg.org/), licensed under [Apache-2.0](third-party-licenses/LICENSE-RosaeNLG), copyrighted 2019–2024 by Ludan Stoecklé, 2015 by Forbes Lindesay, and 2009–2014 by TJ Holowaychuk. -- MetamorPOV supports adaptive articles with [indefinite](https://github.com/tandrewnichols/indefinite), licensed under [MIT](third-party-licenses/LICENSE-indefinite), copyrighted 2015–2025 by Andrew Nichols. - MetamorPOV is themed with [Primary](https://primary-theme.github.io/), licensed under [GPL-3.0](third-party-licenses/LICENSE-Primary), copyrighted 2021–2024 by Cecilia May. - Icons, excepting the butterfly, are redistributed from [Luicide](https://lucide.dev), licensed under [ISC](third-party-licenses/LICENSE-Luicide), copyrighted 2022–2025 by Lucide Contributors. Luicide contains portions of Feather, licensed under [MIT](third-party-licenses/LICENSE-Feather), copyrighted 2013–2022 by Cole Bemis. +- Translation logic is provided by the [MetamorPOV library](https://git.viscogliosi-pate.com/metamorpov-library), licensed under [GPL-3.0-or-later](LICENSE) copyrighted 2025 by Jean Viscogliosi-Pate. - All other portions of MetamorPOV are licensed under [GPL-3.0-or-later](LICENSE), copyrighted 2024–2025 by Jean Viscogliosi-Pate. diff --git a/flake.lock b/flake.lock index 9750de2..42bc3b4 100644 --- a/flake.lock +++ b/flake.lock @@ -2,14 +2,18 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 0, - "narHash": "sha256-463SNPWmz46iLzJKRzO3Q2b0Aurff3U1n0nYItxq7jU=", - "path": "/nix/store/yw6kg4rb9v8s3ypjbpspig5r81m4lr5s-source", - "type": "path" + "lastModified": 1755175540, + "narHash": "sha256-V0j2S1r25QnbqBLzN2Rg/dKKil789bI3P3id7bDPVc4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a595dde4d0d31606e19dcec73db02279db59d201", + "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" } }, "root": { diff --git a/flake.nix b/flake.nix index c27db51..3459f15 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - # nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; systems.url = "github:nix-systems/default"; }; @@ -13,7 +13,7 @@ devShells = eachSystem (pkgs: { default = pkgs.mkShell { buildInputs = [ - pkgs.nodejs_22 + pkgs.nodejs_24 pkgs.firefox pkgs.chromium ]; diff --git a/package-lock.json b/package-lock.json index bb7bb69..72e1b73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,45 +1,42 @@ { "name": "metamorpov", - "version": "1.2.0", + "version": "2.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "metamorpov", - "version": "1.2.0", + "version": "2.0.0", "license": "GPL-3.0-or-later", "devDependencies": { "@rollup/plugin-commonjs": "28.0.2", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "15.3.0", - "english-verbs-gerunds": "3.3.1", - "english-verbs-helper": "3.3.1", - "english-verbs-irregular": "3.3.1", - "indefinite": "^2.5.1", + "metamorpov": "^1.0.0", "rollup": "^4.27.3", - "web-ext": "^8.3.0", + "web-ext": "^8.9.0", "webextension-polyfill": "^0.12.0" } }, "node_modules/@babel/code-frame": { - "version": "7.26.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", - "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==", + "version": "7.27.1", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz", + "integrity": "sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==", "dev": true, "license": "MIT", "dependencies": { - "@babel/helper-validator-identifier": "^7.25.9", + "@babel/helper-validator-identifier": "^7.27.1", "js-tokens": "^4.0.0", - "picocolors": "^1.0.0" + "picocolors": "^1.1.1" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz", - "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==", + "version": "7.27.1", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.27.1.tgz", + "integrity": "sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow==", "dev": true, "license": "MIT", "engines": { @@ -309,9 +306,9 @@ "license": "MIT" }, "node_modules/@mdn/browser-compat-data": { - "version": "6.0.23", - "resolved": "https://registry.npmjs.org/@mdn/browser-compat-data/-/browser-compat-data-6.0.23.tgz", - "integrity": "sha512-LdoI2lPd0bHn3IL4kJ2hxmh4kLE59GarffTR2oqllXc/LIWJNolznUk2lmzUxfColwM07Q3PbN38+ZqHdzmf3A==", + "version": "6.0.32", + "resolved": "https://registry.npmjs.org/@mdn/browser-compat-data/-/browser-compat-data-6.0.32.tgz", + "integrity": "sha512-XXZ0RbkrIw8mr71WbVYmtZk+zWYutS71+/8/E+gyPE3yt/ZNiW4UU5/NcrpgLO4NfIB+VBuWhPzSN6Pb1VxAWA==", "dev": true, "license": "CC0-1.0" }, @@ -775,13 +772,13 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "24.0.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.0.4.tgz", - "integrity": "sha512-ulyqAkrhnuNq9pB76DRBTkcS6YsmDALy6Ua63V8OhrOBgbcYt6IOdzpw5P1+dyRIyMerzLkeYWBeOXPpA9GMAA==", + "version": "24.2.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.2.1.tgz", + "integrity": "sha512-DRh5K+ka5eJic8CjH7td8QpYEV6Zo10gfRkjHCO3weqZHWDtAaSTFtl4+VMqOJ4N5jcuhZ9/l+yy8rVgw7BQeQ==", "dev": true, "license": "MIT", "dependencies": { - "undici-types": "~7.8.0" + "undici-types": "~7.10.0" } }, "node_modules/@types/resolve": { @@ -808,19 +805,6 @@ "dev": true, "license": "ISC" }, - "node_modules/abort-controller": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", - "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "dev": true, - "license": "MIT", - "dependencies": { - "event-target-shim": "^5.0.0" - }, - "engines": { - "node": ">=6.5" - } - }, "node_modules/acorn": { "version": "8.15.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", @@ -845,15 +829,15 @@ } }, "node_modules/addons-linter": { - "version": "7.15.0", - "resolved": "https://registry.npmjs.org/addons-linter/-/addons-linter-7.15.0.tgz", - "integrity": "sha512-Q8obxw1vrud4jcbLP4VWhJL5JS/JrC2ohZVh3NqJ98byPs71Hw+2Yq4Lqt+OpMov60uSS7BC1mdy3LloQ2KlYA==", + "version": "7.18.0", + "resolved": "https://registry.npmjs.org/addons-linter/-/addons-linter-7.18.0.tgz", + "integrity": "sha512-XJ2FiBjwuprKaFte/5KEOPgym3OuBJw1sutUipeYtQ8q2StVzXqwKY+Fwp0wciDlFkmiQmxP9AMeDiKrc0MdRw==", "dev": true, "license": "MPL-2.0", "dependencies": { "@fluent/syntax": "0.19.0", "@fregante/relaxed-json": "2.0.0", - "@mdn/browser-compat-data": "6.0.23", + "@mdn/browser-compat-data": "6.0.32", "addons-moz-compare": "1.3.0", "addons-scanner-utils": "9.13.0", "ajv": "8.17.1", @@ -870,7 +854,7 @@ "fast-json-patch": "3.1.1", "image-size": "2.0.2", "json-merge-patch": "1.0.2", - "pino": "8.20.0", + "pino": "9.7.0", "semver": "7.7.2", "source-map-support": "0.5.21", "upath": "2.0.1", @@ -884,122 +868,6 @@ "node": ">=18.0.0" } }, - "node_modules/addons-linter/node_modules/pino": { - "version": "8.20.0", - "resolved": "https://registry.npmjs.org/pino/-/pino-8.20.0.tgz", - "integrity": "sha512-uhIfMj5TVp+WynVASaVEJFTncTUe4dHBq6CWplu/vBgvGHhvBvQfxz+vcOrnnBQdORH3izaGEurLfNlq3YxdFQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "atomic-sleep": "^1.0.0", - "fast-redact": "^3.1.1", - "on-exit-leak-free": "^2.1.0", - "pino-abstract-transport": "^1.1.0", - "pino-std-serializers": "^6.0.0", - "process-warning": "^3.0.0", - "quick-format-unescaped": "^4.0.3", - "real-require": "^0.2.0", - "safe-stable-stringify": "^2.3.1", - "sonic-boom": "^3.7.0", - "thread-stream": "^2.0.0" - }, - "bin": { - "pino": "bin.js" - } - }, - "node_modules/addons-linter/node_modules/pino-abstract-transport": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-1.2.0.tgz", - "integrity": "sha512-Guhh8EZfPCfH+PMXAb6rKOjGQEoy0xlAIn+irODG5kgfYV+BQ0rGYYWTIel3P5mmyXqkYkPmdIkywsn6QKUR1Q==", - "dev": true, - "license": "MIT", - "dependencies": { - "readable-stream": "^4.0.0", - "split2": "^4.0.0" - } - }, - "node_modules/addons-linter/node_modules/pino-std-serializers": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-6.2.2.tgz", - "integrity": "sha512-cHjPPsE+vhj/tnhCy/wiMh3M3z3h/j15zHQX+S9GkTBgqJuTuJzYJ4gUyACLhDaJ7kk9ba9iRDmbH2tJU03OiA==", - "dev": true, - "license": "MIT" - }, - "node_modules/addons-linter/node_modules/process-warning": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-3.0.0.tgz", - "integrity": "sha512-mqn0kFRl0EoqhnL0GQ0veqFHyIN1yig9RHh/InzORTUiZHFRAur+aMtRkELNwGs9aNwKS6tg/An4NYBPGwvtzQ==", - "dev": true, - "license": "MIT" - }, - "node_modules/addons-linter/node_modules/readable-stream": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.7.0.tgz", - "integrity": "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg==", - "dev": true, - "license": "MIT", - "dependencies": { - "abort-controller": "^3.0.0", - "buffer": "^6.0.3", - "events": "^3.3.0", - "process": "^0.11.10", - "string_decoder": "^1.3.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - } - }, - "node_modules/addons-linter/node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, - "node_modules/addons-linter/node_modules/sonic-boom": { - "version": "3.8.1", - "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-3.8.1.tgz", - "integrity": "sha512-y4Z8LCDBuum+PBP3lSV7RHrXscqksve/bi0as7mhwVnBW+/wUqKT/2Kb7um8yqcFy0duYbbPxzt89Zy2nOCaxg==", - "dev": true, - "license": "MIT", - "dependencies": { - "atomic-sleep": "^1.0.0" - } - }, - "node_modules/addons-linter/node_modules/string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "dev": true, - "license": "MIT", - "dependencies": { - "safe-buffer": "~5.2.0" - } - }, - "node_modules/addons-linter/node_modules/thread-stream": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-2.7.0.tgz", - "integrity": "sha512-qQiRWsU/wvNolI6tbbCKd9iKaTnCXsTwVxhhKM6nctPdujTyztjlbUkUTUymidWcMnZ5pWR0ej4a0tjsW021vw==", - "dev": true, - "license": "MIT", - "dependencies": { - "real-require": "^0.2.0" - } - }, "node_modules/addons-moz-compare": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/addons-moz-compare/-/addons-moz-compare-1.3.0.tgz", @@ -1053,9 +921,9 @@ } }, "node_modules/agent-base": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz", - "integrity": "sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw==", + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", "dev": true, "license": "MIT", "engines": { @@ -1204,27 +1072,6 @@ "dev": true, "license": "MIT" }, - "node_modules/base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, "node_modules/bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -1263,9 +1110,9 @@ } }, "node_modules/boxen/node_modules/chalk": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.4.1.tgz", - "integrity": "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w==", + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.5.0.tgz", + "integrity": "sha512-1tm8DTaJhPBG3bIkVeZt1iZM9GfSX2lzOeDVZH9R9ffRHpmHvxZ/QhgQH/aDTkswQVt+YHdXAdS/In/30OjCbg==", "dev": true, "license": "MIT", "engines": { @@ -1276,9 +1123,9 @@ } }, "node_modules/boxen/node_modules/type-fest": { - "version": "4.33.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.33.0.tgz", - "integrity": "sha512-s6zVrxuyKbbAsSAD5ZPTB77q4YIdRctkTbJ2/Dqlinwz+8ooH2gd+YA7VA6Pa93KML9GockVvoxjZ2vHP+mu8g==", + "version": "4.41.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", + "integrity": "sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==", "dev": true, "license": "(MIT OR CC0-1.0)", "engines": { @@ -1299,31 +1146,6 @@ "concat-map": "0.0.1" } }, - "node_modules/buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT", - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - } - }, "node_modules/buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", @@ -1678,9 +1500,9 @@ } }, "node_modules/css-select": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", - "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.2.2.tgz", + "integrity": "sha512-TizTzUddG/xYLA3NXodFM0fSbNizXjOKhqiQQwvhlspadZokn1KDy0NZFS0wuEubIYAV5/c1/lAr0TaaFXEXzw==", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -1695,9 +1517,9 @@ } }, "node_modules/css-what": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", - "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==", + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.2.2.tgz", + "integrity": "sha512-u/O3vwbptzhMs3L1fQE82ZSLHQQfto5gyZzwteVIEyeaY5Fc7R4dapF/BvRoSYFeqfBk4m0V1Vafq5Pjv25wvA==", "dev": true, "license": "BSD-2-Clause", "engines": { @@ -1917,9 +1739,9 @@ } }, "node_modules/dot-prop/node_modules/type-fest": { - "version": "4.33.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.33.0.tgz", - "integrity": "sha512-s6zVrxuyKbbAsSAD5ZPTB77q4YIdRctkTbJ2/Dqlinwz+8ooH2gd+YA7VA6Pa93KML9GockVvoxjZ2vHP+mu8g==", + "version": "4.41.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", + "integrity": "sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==", "dev": true, "license": "(MIT OR CC0-1.0)", "engines": { @@ -1937,16 +1759,16 @@ "license": "MIT" }, "node_modules/english-verbs-gerunds": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/english-verbs-gerunds/-/english-verbs-gerunds-3.3.1.tgz", - "integrity": "sha512-j1lltTeuvPwgwa/ROAjT/1B1RBA8724uJ2tCjGyRqn87VGAU/YKtYO/camMB1G/WaHT3j5iI3cmdVoPj5H3K2w==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/english-verbs-gerunds/-/english-verbs-gerunds-3.4.0.tgz", + "integrity": "sha512-sc6Zgm7Du+KKIloln0GzcT/fZxIqJBXlfU9B8DLi1bPmKK/hVK3HsRWywNaAGwHU4+SpZ7ADvLvoXlMI2PkwUw==", "dev": true, "license": "Apache-2.0" }, "node_modules/english-verbs-helper": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/english-verbs-helper/-/english-verbs-helper-3.3.1.tgz", - "integrity": "sha512-8mFnB6Z5W44aX20MTA9Wu7Fqad3KkykFcpLAcD3I930J1mIlqmsJhS81Qs8b23QCg2Aq1QfN9t0Xa2hsENFWgQ==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/english-verbs-helper/-/english-verbs-helper-3.4.0.tgz", + "integrity": "sha512-yP1msoIysGuUolx1s3K7dHj5ASqitjHN3PAe3rrF7/mbcHqg1VaLyGVII7Onkv3AHnrPqMT6ITiPtd2rccE7eg==", "dev": true, "license": "Apache-2.0", "funding": { @@ -1955,9 +1777,9 @@ } }, "node_modules/english-verbs-irregular": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/english-verbs-irregular/-/english-verbs-irregular-3.3.1.tgz", - "integrity": "sha512-Ji6a/4QbXKryxLD/yw+tp6xz7kCOcHOdaDcesEyFYHQxUNRnWbLWybXAYnoLn3VHC0AxXbQonZwO6Bw7JvoaVA==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/english-verbs-irregular/-/english-verbs-irregular-3.4.0.tgz", + "integrity": "sha512-Rk0fgdzJ0oqpERPHr6QV2Dp8nnNKO3Si92RWYCe7fgxks8+yEOtUDu0ZBm3AJ6Ccqaa5ZtVh/pndUYdbKkr7xg==", "dev": true, "license": "Apache-2.0" }, @@ -2264,26 +2086,6 @@ "node": ">=0.10.0" } }, - "node_modules/event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, - "node_modules/events": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", - "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.8.x" - } - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -2457,9 +2259,9 @@ "license": "ISC" }, "node_modules/fs-extra": { - "version": "11.3.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.0.tgz", - "integrity": "sha512-Z4XaCL6dUDHfP/jT25jJKMmtxvuwbkrD1vNSMFlo9lNLY2c5FHYSQgHPRZUjAB26TpDEoW9HCOgplrdbaPV/ew==", + "version": "11.3.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.1.tgz", + "integrity": "sha512-eXvGGwZ5CL17ZSwHWd3bbgk7UUpF6IFHtP57NYYakPvHOs8GDgDe5KJI36jIJzDkJ6eJjuzRA8eBQb6SkKue0g==", "dev": true, "license": "MIT", "dependencies": { @@ -2747,27 +2549,6 @@ "node": ">= 14" } }, - "node_modules/ieee754": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "BSD-3-Clause" - }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", @@ -2826,9 +2607,9 @@ } }, "node_modules/indefinite": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/indefinite/-/indefinite-2.5.1.tgz", - "integrity": "sha512-Ul0hCdnSjuFDEloYWeozTaEfljbz+0q+u4HsHns2dOk2DlhGlbRMGFtNcIL+Ve7sZYeIOTOAKA0usAXBGHpNDg==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/indefinite/-/indefinite-2.5.2.tgz", + "integrity": "sha512-J3ELLIk835hmgDMUfNltTCrHz9+CteTnSuXJqvxZT18wo1U2M9/QeeJMw99QdZwPEEr1DE2aBYda101Ojjdw5g==", "dev": true, "license": "MIT", "engines": { @@ -3185,9 +2966,9 @@ "license": "MIT" }, "node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.0.tgz", + "integrity": "sha512-FGuPw30AdOIUTRMC2OMRtQV+jkVj2cfPqSeWXv1NEAJ1qZ5zb1X6z1mFhbfOB/iy3ssJCD+3KuZ8r8C3uVFlAg==", "dev": true, "license": "MIT", "dependencies": { @@ -3221,9 +3002,9 @@ } }, "node_modules/ky": { - "version": "1.7.4", - "resolved": "https://registry.npmjs.org/ky/-/ky-1.7.4.tgz", - "integrity": "sha512-zYEr/gh7uLW2l4su11bmQ2M9xLgQLjyvx58UyNM/6nuqyWFHPX5ktMjvpev3F8QWdjSsHUpnWew4PBCswBNuMQ==", + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/ky/-/ky-1.8.2.tgz", + "integrity": "sha512-XybQJ3d4Ea1kI27DoelE5ZCT3bSJlibYTtQuMsyzKox3TMyayw1asgQdl54WroAm+fIA3ZCr8zXW2RpR7qWVpA==", "dev": true, "license": "MIT", "engines": { @@ -3274,33 +3055,34 @@ } }, "node_modules/lighthouse-logger": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/lighthouse-logger/-/lighthouse-logger-2.0.1.tgz", - "integrity": "sha512-ioBrW3s2i97noEmnXxmUq7cjIcVRjT5HBpAYy8zE11CxU9HqlWHHeRxfeN1tn8F7OEMVPIC9x1f8t3Z7US9ehQ==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/lighthouse-logger/-/lighthouse-logger-2.0.2.tgz", + "integrity": "sha512-vWl2+u5jgOQuZR55Z1WM0XDdrJT6mzMP8zHUct7xTlWhuQs+eV0g+QL0RQdFjT54zVmbhLCP8vIVpy1wGn/gCg==", "dev": true, "license": "Apache-2.0", "dependencies": { - "debug": "^2.6.9", + "debug": "^4.4.1", "marky": "^1.2.2" } }, "node_modules/lighthouse-logger/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", + "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", "dev": true, "license": "MIT", "dependencies": { - "ms": "2.0.0" + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } } }, - "node_modules/lighthouse-logger/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "dev": true, - "license": "MIT" - }, "node_modules/lines-and-columns": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-2.0.4.tgz", @@ -3358,6 +3140,19 @@ "dev": true, "license": "Apache-2.0" }, + "node_modules/metamorpov": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/metamorpov/-/metamorpov-1.0.0.tgz", + "integrity": "sha512-B09TRRxTp5RjYbU1cWB+pP2Q0JTRjmOGrl/BcT3z0g/GmrsYD3r5aDwvtrl/b6Q4F7ULxM2Lp7ZvdcfbzrBHRA==", + "dev": true, + "license": "GPL-3.0-or-later", + "dependencies": { + "english-verbs-gerunds": "^3.4.0", + "english-verbs-helper": "^3.4.0", + "english-verbs-irregular": "^3.4.0", + "indefinite": "^2.5.1" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -3473,16 +3268,16 @@ } }, "node_modules/open": { - "version": "10.1.2", - "resolved": "https://registry.npmjs.org/open/-/open-10.1.2.tgz", - "integrity": "sha512-cxN6aIDPz6rm8hbebcP7vrQNhvRcveZoJU72Y7vskh4oIm+BZwBECnx5nTmrlres1Qapvx27Qo1Auukpf8PKXw==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/open/-/open-10.2.0.tgz", + "integrity": "sha512-YgBpdJHPyQ2UE5x+hlSXcnejzAvD0b22U2OuAP+8OnlJT+PjWPxtgmGqKKc+RgTM63U9gN0YzrYc71R2WT/hTA==", "dev": true, "license": "MIT", "dependencies": { "default-browser": "^5.2.1", "define-lazy-prop": "^3.0.0", "is-inside-container": "^1.0.0", - "is-wsl": "^3.1.0" + "wsl-utils": "^0.1.0" }, "engines": { "node": ">=18" @@ -3491,22 +3286,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/open/node_modules/is-wsl": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-3.1.0.tgz", - "integrity": "sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw==", - "dev": true, - "license": "MIT", - "dependencies": { - "is-inside-container": "^1.0.0" - }, - "engines": { - "node": ">=16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -3792,16 +3571,6 @@ "node": ">= 0.8.0" } }, - "node_modules/process": { - "version": "0.11.10", - "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", - "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 0.6.0" - } - }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -3960,9 +3729,9 @@ } }, "node_modules/registry-auth-token": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-5.0.3.tgz", - "integrity": "sha512-1bpc9IyC+e+CNFRaWyn77tk4xGG4PPUyfakSmA6F6cvUDjrm58dfyJ3II+9yb10EDkHoy1LaPSmHaWLOH3m6HA==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-5.1.0.tgz", + "integrity": "sha512-GdekYuwLXLxMuFTwAPg5UKGLW/UXzQrZvH/Zj791BQif5T05T0RsaLfHc9q3ZOKi7n+BoprPD9mJ0O0k4xzUlw==", "dev": true, "license": "MIT", "dependencies": { @@ -4513,9 +4282,9 @@ "license": "MIT" }, "node_modules/undici-types": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.8.0.tgz", - "integrity": "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==", + "version": "7.10.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.10.0.tgz", + "integrity": "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==", "dev": true, "license": "MIT" }, @@ -4566,9 +4335,9 @@ } }, "node_modules/update-notifier/node_modules/chalk": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.4.1.tgz", - "integrity": "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w==", + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.5.0.tgz", + "integrity": "sha512-1tm8DTaJhPBG3bIkVeZt1iZM9GfSX2lzOeDVZH9R9ffRHpmHvxZ/QhgQH/aDTkswQVt+YHdXAdS/In/30OjCbg==", "dev": true, "license": "MIT", "engines": { @@ -4630,15 +4399,15 @@ } }, "node_modules/web-ext": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/web-ext/-/web-ext-8.8.0.tgz", - "integrity": "sha512-8ecasYMN3zsGUq5ZT73cRrwffDffGC7jnaKKXnZFDSEArWqCf/GNc6/IkvKLDStUocB3CSW5hGffAUHKKi1VrA==", + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/web-ext/-/web-ext-8.9.0.tgz", + "integrity": "sha512-X2IeYfWSf7c/Tireuv48FRfgHougaINBWwwMoYOd9xcXbQGrYXK3IALZZf0cbPpq4AidNxNO8HTKw3SUeWvJgw==", "dev": true, "license": "MPL-2.0", "dependencies": { "@babel/runtime": "7.27.6", "@devicefarmer/adbkit": "3.3.8", - "addons-linter": "7.15.0", + "addons-linter": "7.18.0", "camelcase": "8.0.0", "chrome-launcher": "1.2.0", "debounce": "1.2.1", @@ -4651,7 +4420,7 @@ "jszip": "3.10.1", "multimatch": "6.0.0", "node-notifier": "10.0.1", - "open": "10.1.2", + "open": "10.2.0", "parse-json": "7.1.1", "pino": "9.7.0", "promise-toolbox": "0.21.0", @@ -4809,6 +4578,38 @@ "dev": true, "license": "ISC" }, + "node_modules/wsl-utils": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/wsl-utils/-/wsl-utils-0.1.0.tgz", + "integrity": "sha512-h3Fbisa2nKGPxCpm89Hk33lBLsnaGBvctQopaBSOW/uIs6FTe1ATyAnKFJrzVs9vpGdsTe73WF3V4lIsk4Gacw==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-wsl": "^3.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/wsl-utils/node_modules/is-wsl": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-3.1.0.tgz", + "integrity": "sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-inside-container": "^1.0.0" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/xdg-basedir": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-5.1.0.tgz", diff --git a/package.json b/package.json index 8d9bc28..fa5e1b8 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "metamorpov", "title": "MetamorPOV", - "version": "1.4.0", - "description": "Enables customization of reader-insert stories by replacing author-provided hooks such as Y/n, pov/s, and vrb/do/present/.", + "version": "2.0.0", + "description": "Enables customization of reader-insert stories by translating specific markers such as Y/n, pov/s, and vrb/do/present/.", "type": "module", "repository": { "type": "git", @@ -20,12 +20,9 @@ "@rollup/plugin-commonjs": "28.0.2", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "15.3.0", - "english-verbs-gerunds": "3.3.1", - "english-verbs-helper": "3.3.1", - "english-verbs-irregular": "3.3.1", - "indefinite": "^2.5.1", + "metamorpov": "^1.0.0", "rollup": "^4.27.3", - "web-ext": "^8.3.0", + "web-ext": "^8.9.0", "webextension-polyfill": "^0.12.0" } } diff --git a/src/replace-words.js b/src/replace-words.js index f09829a..5dd4e34 100644 --- a/src/replace-words.js +++ b/src/replace-words.js @@ -1,513 +1,16 @@ var browser = require("webextension-polyfill"); -const verbsHelper = require("english-verbs-helper"); -const verbsIrregular = require("english-verbs-irregular/dist/verbs.json"); -const verbsGerunds = require("english-verbs-gerunds/dist/gerunds.json"); -const verbsData = verbsHelper.mergeVerbsData(verbsIrregular, verbsGerunds); -const articleHelper = require("indefinite"); +const metamorpov = require("metamorpov"); -/* Replaces verbs, point-of-view, name, pronouns, and "also" terms */ -function replaceAll() { +/* Uses MetamorPOV to translate page text */ +function translate() { let options = browser.storage.local.get(); options.then((options) => { const hostname = window.location.hostname; const isEnabled = !(options.domains === undefined) && options.domains.includes(hostname); if (!isEnabled) { return; } - const isNameSet = !(options.name === undefined || options.name == ""); - const isPronounsSet = !(options.preset === undefined || options.preset == ""); - const isPovSet = !(options.pov === undefined || options.pov == ""); - const isPovLegal = isPovSet && (options.pov != "third" || (isNameSet && isPronounsSet)); - const isAllSet = isNameSet && isPronounsSet && isPovLegal; - - if (isPovLegal) { - replaceVerbs(options); - replacePov(options); - replacePlv(options); - } - - if (isNameSet) { - replaceName(options); - } - - if (isPronounsSet) { - replacePronouns(options); - } - - const isAlsoSet = !(options.also === undefined); - if (isAlsoSet) { - replaceAlso(options); - } - - if (isAllSet) { - replaceExceptions(options); - replaceEquals(); - replaceCuts(); - replaceCapitals(); - replaceMirror(); - replaceAn(); - } + metamorpov.translate(document.body, options); }); } -/* Replaces all instances of "Y/n" with the user's name */ -function replaceName(options) { - const searchTerm = /\by\/n\b|\(y\/n\)|\[y\/n\]/ig; - walk(document.body, searchTerm, options["name"], directMethod); -} - -/* Replaces all verb keys */ -function replaceVerbs(options) { - const searchTerm = /(v)r([nb])\/([\w\s]+)\/(?:((?:(?:simple|progressive|perfect|perfect[ _]progressive|participle(?![ _]future))[ _])*(?:past|present|future))\/)*/i; - walk(document.body, searchTerm, options, verbMethod); -} - -/* Replaces all pronoun keys */ -/* This could be made faster if I give premade regexp expressions for each, but I don't want to do that! */ -function replacePronouns(options) { - let pronouns = getPronouns(options.preset, options.other); - walk(document.body, /([Pp])rn\/s/, pronouns["subjective"], pronounMethod); - walk(document.body, /([Pp])rn\/o/, pronouns["objective"], pronounMethod); - walk(document.body, /([Pp])rn\/p/, pronouns["possessive"], pronounMethod); - walk(document.body, /([Pp])rn\/a/, pronouns["adjective"], pronounMethod); - walk(document.body, /([Pp])rn\/r/, pronouns["reflexive"], pronounMethod); - walk(document.body, /([Pp])rn\/H/, pronouns["honorific-abbr"], pronounMethod); - walk(document.body, /([Pp])rn\/h/, pronouns["honorific"], pronounMethod); - walk(document.body, /([Pp])rn\/N/, pronouns["adult"], pronounMethod); - walk(document.body, /([Pp])rn\/n/, pronouns["youth"], pronounMethod); - walk(document.body, /([Pp])rn\/F/, pronouns["parent"], pronounMethod); - walk(document.body, /([Pp])rn\/f/, pronouns["child"], pronounMethod); - walk(document.body, /([Pp])rn\/k/, pronouns["sibling"], pronounMethod); - walk(document.body, /([Pp])rn\/m/, pronouns["married"], pronounMethod); - walk(document.body, /([Pp])rn\/d/, pronouns["dating"], pronounMethod); -} - -/* Gets pronouns based on the provided key (or user input) */ -function getPronouns(key, other) { - switch (key) { - case "she": - return { - "subjective": "she", - "objective": "her", - "possessive": "her", - "adjective": "hers", - "reflexive": "herself", - "honorific-abbr": "Ms.", - "honorific": "miss", - "adult": "woman", - "youth": "girl", - "parent": "mother", - "child": "daughter", - "sibling": "sister", - "married": "wife", - "dating": "girlfriend", - "plurality": "singular" - }; - case "he": - return { - "subjective": "he", - "objective": "him", - "possessive": "his", - "adjective": "his", - "reflexive": "himself", - "honorific-abbr": "Mr.", - "honorific": "mister", - "adult": "man", - "youth": "boy", - "parent": "father", - "child": "son", - "sibling": "brother", - "married": "husband", - "dating": "boyfriend", - "plurality": "singular" - }; - case "they": - return { - "subjective": "they", - "objective": "them", - "possessive": "their", - "adjective": "theirs", - "reflexive": "themself", - "honorific-abbr": "Mx.", - "honorific": "mix", - "adult": "person", - "youth": "kid", - "parent": "parent", - "child": "child", - "sibling": "sibling", - "married": "spouse", - "dating": "partner", - "plurality": "plural" - }; - case "first": - return { - "subjective": "I", - "objective": "me", - "possessive": "my", - "adjective": "mine", - "reflexive": "myself" - }; - case "second": - return { - "subjective": "you", - "objective": "you", - "possessive": "your", - "adjective": "yours", - "reflexive": "yourself" - }; - case "first-plural": - return { - "subjective": "we", - "objective": "us", - "possessive": "our", - "adjective": "ours", - "reflexive": "ourselves" - }; - case "second-plural": - return { - "subjective": "you", - "objective": "you", - "possessive": "your", - "adjective": "yours", - "reflexive": "yourselves" - }; - case "third-plural": - return { - "subjective": "they", - "objective": "them", - "possessive": "their", - "adjective": "theirs", - "reflexive": "themselves" - }; - case "other": - return other; - } -} - -/* Replaces all point-of-view keys */ -function replacePov(options) { - let pronouns; - if (options.pov == "third") { - pronouns = getPronouns(options.preset, options.other); - walk(document.body, /([Pp])ov\/S/, options.name, pronounMethod); - walk(document.body, /([Pp])ov\/O/, options.name, pronounMethod); - walk(document.body, /([Pp])ov\/P/, options.name + "’s", pronounMethod); - walk(document.body, /([Pp])ov\/A/, options.name + "’s", pronounMethod); - walk(document.body, /([Pp])ov\/R/, options.name + "’s self", pronounMethod); - } else { - pronouns = getPronouns(options.pov, null); - walk(document.body, /([Pp])ov\/S/, pronouns["subjective"], pronounMethod); - walk(document.body, /([Pp])ov\/O/, pronouns["objective"], pronounMethod); - walk(document.body, /([Pp])ov\/P/, pronouns["possessive"], pronounMethod); - walk(document.body, /([Pp])ov\/A/, pronouns["adjective"], pronounMethod); - walk(document.body, /([Pp])ov\/R/, pronouns["reflexive"], pronounMethod); - } - walk(document.body, /([Pp])ov\/s/, pronouns["subjective"], pronounMethod); - walk(document.body, /([Pp])ov\/o/, pronouns["objective"], pronounMethod); - walk(document.body, /([Pp])ov\/p/, pronouns["possessive"], pronounMethod); - walk(document.body, /([Pp])ov\/a/, pronouns["adjective"], pronounMethod); - walk(document.body, /([Pp])ov\/r/, pronouns["reflexive"], pronounMethod); -} - -/* Replaces plural point-of-view keys */ -function replacePlv(options) { - let pronouns = getPronouns(options.pov + "-plural", null); - walk(document.body, /([Pp])lv\/s/, pronouns["subjective"], pronounMethod); - walk(document.body, /([Pp])lv\/o/, pronouns["objective"], pronounMethod); - walk(document.body, /([Pp])lv\/p/, pronouns["possessive"], pronounMethod); - walk(document.body, /([Pp])lv\/a/, pronouns["adjective"], pronounMethod); - walk(document.body, /([Pp])lv\/r/, pronouns["reflexive"], pronounMethod); -} - -/* Replaces additional terms specified by the user */ -function replaceAlso(options) { - Object.entries(options.also).forEach(([key, value]) => { - escapeAndReplace(key, value, true); - }); -} - -/* Replaces exception statements by POV */ -function replaceExceptions(options) { - const searchTerm = /exc\/([^\/]*)\/([^\/]*)\/(?:([^\/]*)\/)?/i; - walk(document.body, searchTerm, options, exceptionMethod); -} - -/* Replaces statements by whether they match requested terms */ -function replaceEquals() { - const searchTerm = /eql\/([\w\s]+)\/([\w\s]+)\/([^\/]*)\/(?:([^\/]*)\/)?/i; - walk(document.body, searchTerm, null, equalsMethod); -} - -/* Replaces cut statements with cuts */ -function replaceCuts() { - const searchTerm = /cut\/([^\/]+)\/(off|only) (first|last) ([1-9][0-9]*)\//i; - walk(document.body, searchTerm, null, cutMethod); -} - -/* Replaces capital statements statements with requested casing */ -function replaceCapitals() { - const searchTerm = /(cap|Cap|CAP)\/([^\/]+)\//i; - walk(document.body, searchTerm, null, capitalMethod); -} - -/* Replaces mirror statements with reversed phrases */ -function replaceMirror() { - const searchTerm = /mrr\/([^\/]+)\//i; - walk(document.body, searchTerm, null, mirrorMethod); -} - -/* Replaces ambiguous articles with one suitable to the following word */ -function replaceAn() { - const searchTerm = /a\/an (\w+)/i; - walk(document.body, searchTerm, null, anMethod); -} - -/* Turns a term into regexp format and uses that to replace it */ -function escapeAndReplace(searchTerm, replaceValue, caseSensitive) { - let searchTermEscaped = searchTerm.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); - const flags = caseSensitive ? "g" : "ig" - if (searchTermEscaped[0].match(/[a-z]/i)) { - searchTermEscaped = `\\b${searchTermEscaped}` - } - if (searchTermEscaped[searchTermEscaped.length - 1].match((/[a-z]/i))) { - searchTermEscaped = `${searchTermEscaped}\\b` - } - const searchTermRegexp = new RegExp(searchTermEscaped, flags) - walk(document.body, searchTermRegexp, replaceValue, directMethod); -} - -/* Traverses a node and its children to run the provided replacement method */ -function walk(node, searchTerm, replaceValue, replaceMethod) { - if (node.contentEditable == "true" || node.type == "textarea" || node.type == "input") { return; } - let child, next; - switch (node.nodeType) { - case 1: /* ELEMENT_NODE */ - case 9: /* DOCUMENT_NODE */ - case 11: /* DOCUMENT_FRAGMENT_NODE */ - child = node.firstChild; - while (child) { - next = child.nextSibling; - walk(child, searchTerm, replaceValue, replaceMethod); - child = next; - } - break; - case 3: /* TEXT_NODE */ - replaceMethod(node, searchTerm, replaceValue); - } -} - -/* Replaces every instance of the provided terms */ -function directMethod(node, searchTerm, replaceValue) { - node.nodeValue = node.nodeValue.replaceAll(searchTerm, replaceValue); -} - -/* Replaces all pronouns */ -function pronounMethod(node, searchTerm, pronoun) { - const match = node.nodeValue.match(searchTerm); - if (match == null) { return; } - const isCapital = /P/.test(match[1]); - - let replaceValue = pronoun; - if (isCapital) { - replaceValue = capitalize(replaceValue); - } - - node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue); - pronounMethod(node, searchTerm, pronoun); -} - -/* Replaces all verbs, not used for third-person plural */ -function verbMethod(node, searchTerm, options) { - const match = node.nodeValue.match(searchTerm); - if (match == null) { return; } - const isCapital = /V/.test(match[1]); - const category = match[2]; - const verb = match[3]; - let tense = match[4]; - - if (tense == null) { - tense = "PAST"; - } else { - tense = tense.toUpperCase().replaceAll(" ", "_"); - } - - let povIndex; - switch (category) { - case "B": /* B and b vary by POV, capitalized to indicate a named subject */ - if (options.pov == "third") { - povIndex = getPovIndex("third-singular", null); - } else { - povIndex = getPovIndex(options.pov, options); - } - break; - case "b": - povIndex = getPovIndex(options.pov, options); - break; - case "N": /* N and n are always third-person */ - povIndex = getPovIndex("third-singular", null); - break; - case "n": - povIndex = getPovIndex("third", options); - } - - let replaceValue = verbsHelper.getConjugation(verbsData, verb, tense, povIndex); - - if (isCapital) { - replaceValue = capitalize(replaceValue); - } - - node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue); - verbMethod(node, searchTerm, options); -} - -/* Allows for first, second, and third-person POV to read differently */ -function exceptionMethod(node, searchTerm, options) { - const match = node.nodeValue.match(searchTerm); - if (match == null) { return; } - let replaceValue; - - const isFirstSecondSame = match[3] == null; - if (isFirstSecondSame) { - if (options.pov == "third") { - replaceValue = match[2]; - } else { - replaceValue = match[1]; - } - } else { - if (options.pov == "third") { - replaceValue = match[3]; - } else if (options.pov == "second") { - replaceValue = match[2]; - } else { - replaceValue = match[1]; - } - } - - node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue); - exceptionMethod(node, searchTerm, options); -} - -/* Allows for custom answers to custom words */ -function equalsMethod(node, searchTerm, unused) { - const match = node.nodeValue.match(searchTerm); - if (match == null) { return; } - let replaceValue; - - const isEqual = match[1] === match[2]; - if (isEqual) { - replaceValue = match[3]; - } else { - replaceValue = match[4]; - } - - node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue); - exceptionMethod(node, searchTerm, unused); -} - -/* Allows for custom words to be truncated */ -function cutMethod(node, searchTerm, unused) { - const match = node.nodeValue.match(searchTerm); - if (match == null) { return; } - const target = match[1]; - const length = target.length - const isOnly = match[2] == "only"; - const isFirst = match[3] == "first"; - const index = Number(match[4]); - - let start, end; - if (isOnly) { - if (isFirst) { // only first n - start = 0; - end = Math.min(index, length - 1); - } else { // only last n - start = Math.max(length - index, 1); - end = length; - } - } else { - if (isFirst) { // off first n - start = Math.min(index, length - 1);; - end = length; - } else { // off last n - start = 0; - end = Math.max(length - index, 1); - } - } - - const replaceValue = target.slice(start, end); - - node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue); - cutMethod(node, searchTerm, unused); -} - -/* Allows for custom words to be capitalized */ -function capitalMethod(node, searchTerm, unused) { - const match = node.nodeValue.match(searchTerm); - if (match == null) { return; } - const style = match[1]; - const target = match[2]; - const isLowerCase = /c/.test(style.slice(0,1)); // cap - - let replaceValue; - if (isLowerCase) { - replaceValue = target.toLowerCase(); - } else { - const isStartCase = /a/.test(style.slice(1,2)); // Cap - if (isStartCase) { - replaceValue = capitalize(target); - } else { // CAP - replaceValue = target.toUpperCase(); - } - } - - node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue); - capitalMethod(node, searchTerm, unused); -} - -/* Allows for custom words to be mirrored */ -function mirrorMethod(node, searchTerm, unused) { - const match = node.nodeValue.match(searchTerm); - if (match == null) { return; } - const target = match[1]; - - let replaceValue = target.split('').reverse().join(''); - - node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue); - mirrorMethod(node, searchTerm, unused); -} - -/* Allows for custom words to have the right article */ -function anMethod(node, searchTerm, unused) { - const match = node.nodeValue.match(searchTerm); - if (match == null) { return; } - const target = match[1]; - - let replaceValue = articleHelper(target, { numbers: 'colloquial' }); - - node.nodeValue = node.nodeValue.replace(searchTerm, replaceValue); - mirrorMethod(node, searchTerm, unused); -} - -/* Returns the input word, capitalized */ -function capitalize(word) { - return word.charAt(0).toUpperCase() + word.slice(1); -} - -/* Determines the index for point-of-view to be used when conjugating verbs */ -function getPovIndex(pov, options) { - switch (pov) { - case "first": - return 0; - case "second": - return 1; - case "third-singular": - return 2; - case "third": - if (getPronouns(options.preset, options.other).plurality == "singular") { - return 2; - } else { /* Plurality is plural, "they go" */ - return 5; - } - return getThirdIndex(options); - } -} - -replaceAll(); +translate();