Migrate to new reader command

`:reader --old` retained for old behaviour
This commit is contained in:
Oliver Blanthorn 2023-04-05 20:44:04 +02:00
parent cc59b83bee
commit 93352f08b5
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3

View file

@ -2292,11 +2292,15 @@ export async function zoom(level = 0, rel = "false", tabId = "auto") {
} }
} }
/** Opens the current page in Firefox's reader mode. /**
* You currently cannot use Tridactyl while in reader mode. * @hidden
* Old version of the reader command. Opens the current page in Firefox's reader mode.
* You cannot use Tridactyl while in this reader mode.
*
* Use [[reader]] instead
*/ */
//#background //#background
export async function reader() { export async function readerold() {
if (await firefoxVersionAtLeast(58)) { if (await firefoxVersionAtLeast(58)) {
const aTab = await activeTab() const aTab = await activeTab()
if (aTab.isArticle) { if (aTab.isArticle) {
@ -5989,14 +5993,30 @@ export async function extoptions(...optionNameArgs: string[]) {
//#content_helper //#content_helper
import { Readability } from "@mozilla/readability" import { Readability } from "@mozilla/readability"
//#content //#content_helper
export async function reader2() { export async function readerurl() {
document.querySelectorAll(".TridactylStatusIndicator").forEach(ind => ind.parentNode.removeChild(ind)) document.querySelectorAll(".TridactylStatusIndicator").forEach(ind => ind.parentNode.removeChild(ind))
const article = new Readability(document).parse() const article = new Readability(document).parse()
article["link"] = window.location.href article["link"] = window.location.href
return browser.runtime.getURL("static/reader.html#" + btoa(encodeURIComponent(JSON.stringify(article))))
}
// todo: sanitise //#content
open(browser.runtime.getURL("static/reader.html#" + btoa(encodeURIComponent(JSON.stringify(article))))) export async function reader(...args: string[]) {
switch(args[0]) {
case "--old":
readerold()
break
case "--tab":
tabopen(await readerurl())
break
case "--window":
winopen(await readerurl())
break
default:
open(await readerurl())
break
}
} }
/** /**