Move rewriteUrlClosure into the web/chromecom.js file

Given that this is only used for the Chrome-addon, we can move this code into the relevant file instead.
This commit is contained in:
Jonas Jenwald 2023-02-09 11:12:20 +01:00
parent 9cea76483a
commit 40a3de8c37
2 changed files with 17 additions and 20 deletions

View File

@ -27,6 +27,23 @@ if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME")) {
); );
} }
(function rewriteUrlClosure() {
// Run this code outside DOMContentLoaded to make sure that the URL
// is rewritten as soon as possible.
const queryString = document.location.search.slice(1);
const m = /(^|&)file=([^&]*)/.exec(queryString);
const defaultUrl = m ? decodeURIComponent(m[2]) : "";
// Example: chrome-extension://.../http://example.com/file.pdf
const humanReadableUrl = "/" + defaultUrl + location.hash;
history.replaceState(history.state, "", humanReadableUrl);
if (top === window) {
chrome.runtime.sendMessage("showPageAction");
}
AppOptions.set("defaultUrl", defaultUrl);
})();
const ChromeCom = { const ChromeCom = {
/** /**
* Creates an event that the extension is listening for and will * Creates an event that the extension is listening for and will

View File

@ -36,26 +36,6 @@ window.PDFViewerApplication = PDFViewerApplication;
window.PDFViewerApplicationConstants = AppConstants; window.PDFViewerApplicationConstants = AppConstants;
window.PDFViewerApplicationOptions = AppOptions; window.PDFViewerApplicationOptions = AppOptions;
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
(function rewriteUrlClosure() {
// Run this code outside DOMContentLoaded to make sure that the URL
// is rewritten as soon as possible.
const queryString = document.location.search.slice(1);
const m = /(^|&)file=([^&]*)/.exec(queryString);
const defaultUrl = m ? decodeURIComponent(m[2]) : "";
// Example: chrome-extension://.../http://example.com/file.pdf
const humanReadableUrl = "/" + defaultUrl + location.hash;
history.replaceState(history.state, "", humanReadableUrl);
if (top === window) {
// eslint-disable-next-line no-undef
chrome.runtime.sendMessage("showPageAction");
}
AppOptions.set("defaultUrl", defaultUrl);
})();
}
function getViewerConfiguration() { function getViewerConfiguration() {
return { return {
appContainer: document.body, appContainer: document.body,