This repository has been archived by the owner on Feb 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #371, make unpause resume reading an about:reader page
Generally this makes Reader Mode narration a kind of service
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |