diff --git a/src/excmds.ts b/src/excmds.ts index 7bf8e9cd..b3ea4bc1 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -6074,6 +6074,17 @@ export async function readerurl() { * Use `:reader --old` to use Firefox's built-in reader mode, which Tridactyl can't run on. * * __NB:__ the reader page is a privileged environment which has access to all Tridactyl functions, notably the native messenger if you have it installed. We are parsing untrusted web-content to run in this environment. Mozilla's readability library will strip out most of these, then we use a sanitation library, `js-xss`, to strip out any remaining unsafe tags, but if there was a serious bug in this library, and a targeted attack against Tridactyl, an attacker could get remote code execution. If you're worried about this, use `:reader --old` instead or only use `:reader` on pages you trust. + * + * You may use [userContent.css](http://kb.mozillazine.org/index.php?title=UserContent.css&printable=yes) to enhance or override default styling of the new reader view. The `body` of the page has id `tridactyl-reader` and the article content follows in a `main` tag. Therefore to alter default styling, you can do something like this in your `userContent.css`: + * + * ```css + * #tridactyl-reader > main { + * width: 80vw !important; + * text-align: left; + * } + * ``` + * + * Follow [issue #4657](https://github.com/tridactyl/tridactyl/issues/4657) if you would like to find out when we have made a more user-friendly solution. */ //#content export async function reader(...args: string[]) { diff --git a/src/lib/config.ts b/src/lib/config.ts index 9af3ecb0..e958fc87 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -1290,6 +1290,11 @@ export class default_config { * https://fusejs.io/api/options.html#threshold */ completionfuzziness = 0.3 + + /** + * Whether to show article url in the document.title of Reader View. + */ + readerurlintitle: "true" | "false" = "false" } const platform_defaults = { diff --git a/src/reader.ts b/src/reader.ts index 3a8d6932..adb61357 100644 --- a/src/reader.ts +++ b/src/reader.ts @@ -1,14 +1,30 @@ -// import * as config from "@src/lib/config" +import * as config from "@src/lib/config" import xss from "xss" -function updatePage(){ - const article = JSON.parse(decodeURIComponent(atob(window.location.hash.substr(1)))) - article.content = xss(article.content, {stripIgnoreTag: true}) - document.body.innerHTML = article.content +async function updatePage() { + const article = JSON.parse( + decodeURIComponent(atob(window.location.hash.substr(1))), + ) + article.content = xss(article.content, { stripIgnoreTag: true }) + const content = document.createElement("main") + content.innerHTML = article.content + document.body.appendChild(content) if (article.title !== undefined) { const header = document.createElement("header") const title = document.createElement("h1") - document.title = [article.siteName, article.title].filter(Boolean).join(": ") // sensible? + if ( + (await config.getAsync("readerurlintitle")) == "true" && + !(article.title ?? "").includes(article.link) + ) { + document.title = + [article.siteName, article.title].filter(Boolean).join(": ") + + " :: " + + article.link + } else { + document.title = [article.siteName, article.title] + .filter(Boolean) + .join(": ") + } title.textContent = article.title header.appendChild(title) if (article.byline !== undefined) { @@ -19,7 +35,9 @@ function updatePage(){ document.body.insertBefore(header, document.body.firstChild) } if (article.link !== undefined) { - const link = (document.getElementById("tricanonlink") as HTMLLinkElement) ?? document.createElement("link") + const link = + (document.getElementById("tricanonlink") as HTMLLinkElement) ?? + document.createElement("link") link.rel = "canonical" link.id = "tricanonlink" link.href = article.link diff --git a/src/static/css/reader.css b/src/static/css/reader.css index 8a741c36..2432303b 100644 --- a/src/static/css/reader.css +++ b/src/static/css/reader.css @@ -91,29 +91,22 @@ html { scroll-behavior: smooth; } -/* Make the body a nice central block */ body { color: var(--text); background-color: var(--bg); font-size: 1.15rem; line-height: 1.5; - display: grid; - grid-template-columns: 1fr min(45rem, 90%) 1fr; margin: 0; text-align: justify; hyphens: auto; } -body > * { - grid-column: 2; -} /* Make the header bg full width, but the content inline with body */ body > header { background-color: var(--accent-bg); border-bottom: 1px solid var(--border); text-align: center; - padding: 0 0.5rem 2rem 0.5rem; - grid-column: 1 / -1; + padding: 2rem 0.5rem 2rem 0.5rem; } body > header h1 { @@ -126,9 +119,10 @@ body > header p { margin: 1rem auto; } -/* Add a little padding to ensure spacing is correct between content and header > nav */ -main { +body > main { padding-top: 1.5rem; + width: min(45rem, 90%); + margin: auto; } body > footer { diff --git a/src/static/reader.html b/src/static/reader.html index 5f97c7dd..17e90e81 100644 --- a/src/static/reader.html +++ b/src/static/reader.html @@ -8,7 +8,7 @@ - +