Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Fix #371, make unpause resume reading an about:reader page
Browse files Browse the repository at this point in the history
Generally this makes Reader Mode narration a kind of service
  • Loading branch information
ianb committed Oct 7, 2019
1 parent e6b9e51 commit 365af5b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions extension/services/readerMode/readerMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* globals intents, serviceList, content */

this.services.readerMode = (function() {
class ReaderMode extends serviceList.Service {
async pause() {
await this.initTab("/services/spotify/player.js");
await this.callTab("pause");
}

async unpause() {
const activeTab = (await browser.tabs.query({ active: true }))[0];
if (!activeTab.url.startsWith("about:reader")) {
const e = new Error("Cannot unpause a non-reader tab");
e.displayMessage = "Cannot unpause";
throw e;
}
await content.lazyInject(activeTab.id, [
"/intents/read/startNarration.js",
]);
await this.callOneTab(activeTab.id, "narrate");
}

async pauseAny() {
return intents.read.pauseAny();
}
}

Object.assign(ReaderMode, {
id: "readerMode",
title: "Reader Mode",
baseUrl: "about:reader",
skipAutodetect: true,
});

intents.music.register(ReaderMode);
})();

0 comments on commit 365af5b

Please sign in to comment.