diff options
-rw-r--r-- | .github/dependabot.yml | 8 | ||||
-rw-r--r-- | e2e/tab.test.ts | 14 | ||||
-rw-r--r-- | package.json | 6 | ||||
-rw-r--r-- | src/@types/web-ext-api/index.d.ts | 4 | ||||
-rw-r--r-- | src/background/operators/impls/TabOperatorFactoryChain.ts | 3 | ||||
-rw-r--r-- | src/background/operators/impls/ToggleReaderOperator.ts | 11 | ||||
-rw-r--r-- | src/background/presenters/TabPresenter.ts | 6 | ||||
-rw-r--r-- | src/settings/keymaps.ts | 1 | ||||
-rw-r--r-- | src/shared/operations.ts | 7 | ||||
-rw-r--r-- | src/shared/settings/Settings.ts | 1 | ||||
-rw-r--r-- | yarn.lock | 67 |
11 files changed, 91 insertions, 37 deletions
diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..d376c5d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: +- package-ecosystem: npm + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + versioning-strategy: increase diff --git a/e2e/tab.test.ts b/e2e/tab.test.ts index 49d1c03..b59c246 100644 --- a/e2e/tab.test.ts +++ b/e2e/tab.test.ts @@ -107,6 +107,20 @@ describe("tab test", () => { assert.strictEqual(current[0].pinned, true); }); + it("switches to reader view", async () => { + await browser.tabs.update(tabs[0].id, { active: true }); + const page = await Page.currentContext(webdriver); + await page.sendKeys("g", "r"); + + // Unable to switch to reader view, but an error message occurs + const console = await page.getConsole(); + const errorMessage = await console.getErrorMessage(); + assert.strictEqual( + errorMessage, + "The specified tab cannot be placed into reader mode." + ); + }); + it("selects previous tab by K", async () => { await browser.tabs.update(tabs[2].id, { active: true }); const page = await Page.currentContext(webdriver); diff --git a/package.json b/package.json index 7b0afed..ad13ed2 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "homepage": "https://github.com/ueokande/vim-vixen", "devDependencies": { "@types/assert": "^1.4.6", - "@types/chai": "^4.2.8", + "@types/chai": "^4.2.18", "@types/express": "^4.17.2", "@types/mocha": "^8.0.1", "@types/node": "^14.14.13", @@ -43,7 +43,7 @@ "ajv-cli": "^5.0.0", "chai": "^4.2.0", "css-loader": "^5.0.1", - "eslint": "7.25.0", + "eslint": "7.26.0", "eslint-config-prettier": "8.3.0", "eslint-plugin-prettier": "3.4.0", "eslint-plugin-react": "7.23.2", @@ -83,6 +83,6 @@ "web-ext-types": "^3.2.1", "webextensions-api-fake": "^0.9.1", "webpack": "4.46.0", - "webpack-cli": "4.6.0" + "webpack-cli": "4.7.0" } } diff --git a/src/@types/web-ext-api/index.d.ts b/src/@types/web-ext-api/index.d.ts index 7eed334..c2ffbb2 100644 --- a/src/@types/web-ext-api/index.d.ts +++ b/src/@types/web-ext-api/index.d.ts @@ -1,3 +1,7 @@ +declare namespace browser.tabs { + function toggleReaderMode(tabId?: number): Promise<void>; +} + declare namespace browser.browserSettings.homepageOverride { type BrowserSettings = { value: string; diff --git a/src/background/operators/impls/TabOperatorFactoryChain.ts b/src/background/operators/impls/TabOperatorFactoryChain.ts index edd3eaf..d526f86 100644 --- a/src/background/operators/impls/TabOperatorFactoryChain.ts +++ b/src/background/operators/impls/TabOperatorFactoryChain.ts @@ -16,6 +16,7 @@ import PinTabOperator from "./PinTabOperator"; import UnpinTabOperator from "./UnpinTabOperator"; import TogglePinnedTabOperator from "./TogglePinnedTabOperator"; import DuplicateTabOperator from "./DuplicateTabOperator"; +import ToggleReaderOperator from "./ToggleReaderOperator"; @injectable() export default class TabOperatorFactoryChain implements OperatorFactoryChain { @@ -58,6 +59,8 @@ export default class TabOperatorFactoryChain implements OperatorFactoryChain { return new TogglePinnedTabOperator(this.tabPresenter); case operations.TAB_DUPLICATE: return new DuplicateTabOperator(this.tabPresenter); + case operations.TAB_TOGGLE_READER: + return new ToggleReaderOperator(this.tabPresenter); } return null; } diff --git a/src/background/operators/impls/ToggleReaderOperator.ts b/src/background/operators/impls/ToggleReaderOperator.ts new file mode 100644 index 0000000..681e4c3 --- /dev/null +++ b/src/background/operators/impls/ToggleReaderOperator.ts @@ -0,0 +1,11 @@ +import Operator from "../Operator"; +import TabPresenter from "../../presenters/TabPresenter"; + +export default class ToggleReaderOperator implements Operator { + constructor(private readonly tabPresenter: TabPresenter) {} + + async run(): Promise<void> { + const tab = await this.tabPresenter.getCurrent(); + return this.tabPresenter.toggleReaderMode(tab.id as number); + } +} diff --git a/src/background/presenters/TabPresenter.ts b/src/background/presenters/TabPresenter.ts index 2f8f5d9..ef4b343 100644 --- a/src/background/presenters/TabPresenter.ts +++ b/src/background/presenters/TabPresenter.ts @@ -47,6 +47,8 @@ export default interface TabPresenter { onSelected( listener: (arg: { tabId: number; windowId: number }) => void ): void; + + toggleReaderMode(tabId: number): Promise<void>; } export class TabPresenterImpl implements TabPresenter { @@ -152,6 +154,10 @@ export class TabPresenterImpl implements TabPresenter { ): void { browser.tabs.onActivated.addListener(listener); } + + toggleReaderMode(tabId: number): Promise<void> { + return browser.tabs.toggleReaderMode(tabId); + } } const tabPresenter = new TabPresenterImpl(); diff --git a/src/settings/keymaps.ts b/src/settings/keymaps.ts index 25c7a51..ff87cf4 100644 --- a/src/settings/keymaps.ts +++ b/src/settings/keymaps.ts @@ -31,6 +31,7 @@ const fields = [ ['tabs.reload?{"cache":true}', "Reload with no caches"], ["tabs.pin.toggle", "Toggle pinned state"], ["tabs.duplicate", "Duplicate a tab"], + ["tabs.reader.toggle", "Reader view"], ], [ ['follow.start?{"newTab":false,"background":false}', "Follow a link"], diff --git a/src/shared/operations.ts b/src/shared/operations.ts index 3544502..1433011 100644 --- a/src/shared/operations.ts +++ b/src/shared/operations.ts @@ -56,6 +56,7 @@ export const TAB_PIN = "tabs.pin"; export const TAB_UNPIN = "tabs.unpin"; export const TAB_TOGGLE_PINNED = "tabs.pin.toggle"; export const TAB_DUPLICATE = "tabs.duplicate"; +export const TAB_TOGGLE_READER = "tabs.reader.toggle"; // Zooms export const ZOOM_IN = "zoom.in"; @@ -257,6 +258,10 @@ export interface TabDuplicateOperation { type: typeof TAB_DUPLICATE; } +export interface TabToggleReaderOperation { + type: typeof TAB_TOGGLE_READER; +} + export interface ZoomInOperation { type: typeof ZOOM_IN; } @@ -352,6 +357,7 @@ export type Operation = | TabUnpinOperation | TabTogglePinnedOperation | TabDuplicateOperation + | TabToggleReaderOperation | ZoomInOperation | ZoomOutOperation | ZoomNeutralOperation @@ -506,6 +512,7 @@ export const valueOf = (o: any): Operation => { case TAB_UNPIN: case TAB_TOGGLE_PINNED: case TAB_DUPLICATE: + case TAB_TOGGLE_READER: case ZOOM_IN: case ZOOM_OUT: case ZOOM_NEUTRAL: diff --git a/src/shared/settings/Settings.ts b/src/shared/settings/Settings.ts index 43297a3..6c4fa0a 100644 --- a/src/shared/settings/Settings.ts +++ b/src/shared/settings/Settings.ts @@ -133,6 +133,7 @@ export const DefaultSettingJSONText = `{ "gf": { "type": "page.source" }, "gh": { "type": "page.home" }, "gH": { "type": "page.home", "newTab": true }, + "gr": { "type": "tabs.reader.toggle" }, "y": { "type": "urls.yank" }, "p": { "type": "urls.paste", "newTab": false }, "P": { "type": "urls.paste", "newTab": true }, @@ -141,10 +141,10 @@ resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.7.5.tgz#77211291c1900a700b8a78cfafda3160d76949ed" integrity sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg== -"@eslint/eslintrc@^0.4.0": - version "0.4.0" - resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.0.tgz#99cc0a0584d72f1df38b900fb062ba995f395547" - integrity sha512-2ZPCc+uNbjV5ERJr+aKSPRwZgKd2z11x0EgLvb1PURmUrn9QNRXFqje0Ldq454PfAVyaJYyrDvvIKSFP4NnBog== +"@eslint/eslintrc@^0.4.1": + version "0.4.1" + resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.1.tgz#442763b88cecbe3ee0ec7ca6d6dd6168550cbf14" + integrity sha512-5v7TDE9plVhvxQeWLXDTvFvJBdH6pEsdnl2g/dAptmuFEPedQ4Erq5rsDsX+mvAM610IhNaO2W5V1dOOnDKxkQ== dependencies: ajv "^6.12.4" debug "^4.1.1" @@ -226,10 +226,10 @@ "@types/connect" "*" "@types/node" "*" -"@types/chai@^4.2.8": - version "4.2.17" - resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.17.tgz#85f9f0610f514b22a94125d441f73eef65bde5cc" - integrity sha512-LaiwWNnYuL8xJlQcE91QB2JoswWZckq9A4b+nMPq8dt8AP96727Nb3X4e74u+E3tm4NLTILNI9MYFsyVc30wSA== +"@types/chai@^4.2.18": + version "4.2.18" + resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.18.tgz#0c8e298dbff8205e2266606c1ea5fbdba29b46e4" + integrity sha512-rS27+EkB/RE1Iz3u0XtVL5q36MGDWbgYe7zWiodyKNUnthxY0rukK5V36eiUCtCisB7NN8zKYH6DO2M37qxFEQ== "@types/color-name@^1.1.1": version "1.1.1" @@ -694,22 +694,22 @@ "@webassemblyjs/wast-parser" "1.9.0" "@xtuc/long" "4.2.2" -"@webpack-cli/configtest@^1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-1.0.2.tgz#2a20812bfb3a2ebb0b27ee26a52eeb3e3f000836" - integrity sha512-3OBzV2fBGZ5TBfdW50cha1lHDVf9vlvRXnjpVbJBa20pSZQaSkMJZiwA8V2vD9ogyeXn8nU5s5A6mHyf5jhMzA== +"@webpack-cli/configtest@^1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@webpack-cli/configtest/-/configtest-1.0.3.tgz#204bcff87cda3ea4810881f7ea96e5f5321b87b9" + integrity sha512-WQs0ep98FXX2XBAfQpRbY0Ma6ADw8JR6xoIkaIiJIzClGOMqVRvPCWqndTxf28DgFopWan0EKtHtg/5W1h0Zkw== -"@webpack-cli/info@^1.2.3": - version "1.2.3" - resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-1.2.3.tgz#ef819d10ace2976b6d134c7c823a3e79ee31a92c" - integrity sha512-lLek3/T7u40lTqzCGpC6CAbY6+vXhdhmwFRxZLMnRm6/sIF/7qMpT8MocXCRQfz0JAh63wpbXLMnsQ5162WS7Q== +"@webpack-cli/info@^1.2.4": + version "1.2.4" + resolved "https://registry.yarnpkg.com/@webpack-cli/info/-/info-1.2.4.tgz#7381fd41c9577b2d8f6c2594fad397ef49ad5573" + integrity sha512-ogE2T4+pLhTTPS/8MM3IjHn0IYplKM4HbVNMCWA9N4NrdPzunwenpCsqKEXyejMfRu6K8mhauIPYf8ZxWG5O6g== dependencies: envinfo "^7.7.3" -"@webpack-cli/serve@^1.3.1": - version "1.3.1" - resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.3.1.tgz#911d1b3ff4a843304b9c3bacf67bb34672418441" - integrity sha512-0qXvpeYO6vaNoRBI52/UsbcaBydJCggoBBnIo/ovQQdn6fug0BgwsjorV1hVS7fMqGVTZGcVxv8334gjmbj5hw== +"@webpack-cli/serve@^1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.4.0.tgz#f84fd07bcacefe56ce762925798871092f0f228e" + integrity sha512-xgT/HqJ+uLWGX+Mzufusl3cgjAcnqYYskaB7o0vRcwOEfuu6hMzSILQpnIzFMGsTaeaX4Nnekl+6fadLbl1/Vg== "@xtuc/ieee754@^1.2.0": version "1.2.0" @@ -2077,7 +2077,7 @@ enhanced-resolve@^4.0.0, enhanced-resolve@^4.5.0: memory-fs "^0.5.0" tapable "^1.0.0" -enquirer@^2.3.5, enquirer@^2.3.6: +enquirer@^2.3.5: version "2.3.6" resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d" integrity sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg== @@ -2265,13 +2265,13 @@ eslint-visitor-keys@^2.0.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz#21fdc8fbcd9c795cc0321f0563702095751511a8" integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ== -eslint@7.25.0, eslint@^7.9.0: - version "7.25.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.25.0.tgz#1309e4404d94e676e3e831b3a3ad2b050031eb67" - integrity sha512-TVpSovpvCNpLURIScDRB6g5CYu/ZFq9GfX2hLNIV4dSBKxIWojeDODvYl3t0k0VtMxYeR8OXPCFE5+oHMlGfhw== +eslint@7.26.0, eslint@^7.9.0: + version "7.26.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.26.0.tgz#d416fdcdcb3236cd8f282065312813f8c13982f6" + integrity sha512-4R1ieRf52/izcZE7AlLy56uIHHDLT74Yzz2Iv2l6kDaYvEu9x+wMB5dZArVL8SYGXSYV2YAg70FcW5Y5nGGNIg== dependencies: "@babel/code-frame" "7.12.11" - "@eslint/eslintrc" "^0.4.0" + "@eslint/eslintrc" "^0.4.1" ajv "^6.10.0" chalk "^4.0.0" cross-spawn "^7.0.2" @@ -6265,18 +6265,17 @@ webextensions-api-fake@^0.9.1: dependencies: sinon-chrome "^3.0.0" -webpack-cli@4.6.0: - version "4.6.0" - resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-4.6.0.tgz#27ae86bfaec0cf393fcfd58abdc5a229ad32fd16" - integrity sha512-9YV+qTcGMjQFiY7Nb1kmnupvb1x40lfpj8pwdO/bom+sQiP4OBMKjHq29YQrlDWDPZO9r/qWaRRywKaRDKqBTA== +webpack-cli@4.7.0: + version "4.7.0" + resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-4.7.0.tgz#3195a777f1f802ecda732f6c95d24c0004bc5a35" + integrity sha512-7bKr9182/sGfjFm+xdZSwgQuFjgEcy0iCTIBxRUeteJ2Kr8/Wz0qNJX+jw60LU36jApt4nmMkep6+W5AKhok6g== dependencies: "@discoveryjs/json-ext" "^0.5.0" - "@webpack-cli/configtest" "^1.0.2" - "@webpack-cli/info" "^1.2.3" - "@webpack-cli/serve" "^1.3.1" + "@webpack-cli/configtest" "^1.0.3" + "@webpack-cli/info" "^1.2.4" + "@webpack-cli/serve" "^1.4.0" colorette "^1.2.1" commander "^7.0.0" - enquirer "^2.3.6" execa "^5.0.0" fastest-levenshtein "^1.0.12" import-local "^3.0.2" |