Skip to content

Commit

Permalink
Gh-pages for live demo viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaprsd committed Dec 16, 2024
1 parent ff3f688 commit dec2f62
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/pdfjs
Submodule pdfjs updated 2 files
+1 −1 web/viewer.html
+1 −2 web/viewer.mjs
8 changes: 2 additions & 6 deletions src/scripts/extension.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/* Load extension scripts and add-on into the viewer page */
if (window.location.protocol === "moz-extension:") {
import("./mv2/page-script.js");
} else {
import("./mv3/page-script.js");
}
import "./mv2/page-script.js";
import "./doqment.js";
import "/doq/addon/doq.js";
import "../doq/addon/doq.js";
38 changes: 8 additions & 30 deletions src/scripts/mv2/page-script.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,22 @@
import { getPdfUrl, addLink, execOnEvent, isTouchScreen } from "../utils.js";
import { addLink, execOnEvent } from "../utils.js";

/* Rebranding */
document.title = "doqment PDF Reader";
const favIcon = addLink("icon", "/images/icon32.png");
const favIcon = addLink("icon", "../../images/icon32.png");

/* Display host website favicon (if available) */
const pdfUrl = getPdfUrl();
if (self === top && pdfUrl?.startsWith("http")) {
const origIcon = new URL(pdfUrl).origin + "/favicon.ico";
fetch(origIcon, {method: "HEAD"}).then(resp => {
if (resp.ok && resp.headers.get("content-type")?.includes("image/"))
favIcon.href = origIcon;
});
browser.tabs.getCurrent().then(tab => {
browser.pageAction.show(tab.id);
});
}

/* Make Firefox the pre-selected color scheme */
function selectFirefox() {
/* scheme = 0 because of the migration code in doq */
const pref = JSON.stringify({ scheme: 0 });
/* Make Solarized the pre-selected color scheme */
function selectSolarized() {
/* scheme = 3 because of the migration code in doq */
let pref = JSON.stringify({ scheme: 3, tone: "1" });
localStorage.setItem("doq.preferences.light", pref);
pref = JSON.stringify({ scheme: 3, tone: "2" });
localStorage.setItem("doq.preferences.dark", pref);
}

/* Disable the annotation editors by default on mobile */
async function disableAnnotEditors() {
const platform = await browser.runtime.getPlatformInfo();
if (platform.os === "android" && isTouchScreen()) {
const app = window.PDFViewerApplication;
app.preferences.set("annotationEditorMode", -1);
}
}

/* Disable hardware accelerated rendering of canvas */
function forceSoftwareRender() {
const doqOptions = { softwareRender: true };
localStorage.setItem("doq.options", JSON.stringify(doqOptions));
}

execOnEvent("init", [selectFirefox, disableAnnotEditors])
execOnEvent("update-0.9", [forceSoftwareRender])
execOnEvent("init", [selectSolarized, forceSoftwareRender])

0 comments on commit dec2f62

Please sign in to comment.