Skip to content
Snippets Groups Projects
Commit bc494dc4 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

speed up result page timings

parent 58f30c26
No related branches found
No related tags found
1 merge request!2255Development
......@@ -47,6 +47,15 @@ document.addEventListener("DOMContentLoaded", (event) => {
});
}
// Add a element with the ID "plugin-btn" if it does not exist on this page
// Used to determine if a web extension is installed
if (document.getElementById("plugin-btn") == null) {
let new_container = document.createElement("div");
new_container.classList.add("hidden");
new_container.id = "plugin-btn";
document.querySelector("body").appendChild(new_container);
}
backButtons();
});
......@@ -54,6 +63,7 @@ reportJSAvailabilityForAuthenticatedSearch();
function reportJSAvailabilityForAuthenticatedSearch() {
let Cookies = require("js-cookie");
let key_cookie = Cookies.get("key");
if (key_cookie !== undefined) {
Cookies.set("js_available", "true", { sameSite: 'Lax' });
}
......@@ -77,4 +87,33 @@ function backButtons() {
(async () => {
statistics.registerPageLoadEvents();
})();
\ No newline at end of file
})();
document.addEventListener("readystatechange", e => {
if (document.readyState == "complete") {
setTimeout(() => {
// Check if a web extension is active
let extension_installed = document.getElementById("plugin-btn") == null;
if (extension_installed) {
updateWebExtensionStatus((new Date()).getTime());
} else {
updateWebExtensionStatus("no");
}
}, 250);
}
})
function updateWebExtensionStatus(time) {
let Cookies = require("js-cookie");
let extension_cookie = Cookies.get("webextension");
if (time != "no" && extension_cookie == undefined) {
Cookies.set("webextension", time, { sameSite: "Lax" });
} else if (time == "no" && extension_cookie != undefined) {
Cookies.remove("webextension");
}
if (localStorage) {
localStorage.setItem("webextension", time);
}
window.webextension = time;
window.dispatchEvent(new CustomEvent("webextension_status_update", { detail: time }));
}
\ No newline at end of file
......@@ -24,9 +24,30 @@ window.addEventListener("beforeunload", () => {
})
fetch(url).then(result => {
interval = setInterval(verify, 100);
webextensioncheck().then(() => {
interval = setInterval(verify, 100);
verify();
});
});
async function webextensioncheck() {
return new Promise(resolve => {
if (localStorage && localStorage.getItem("webextension") != null) {
return resolve();
} else if (window.webextension != undefined) {
return resolve();
} else {
let timeout = setTimeout(() => {
resolve();
}, 500);
window.addEventListener("webextension_status_update", e => {
clearTimeout(timeout);
resolve();
});
}
});
}
function getKey() {
let nonce_element = document.querySelector("meta[name=nonce]");
return nonce_element.content;
......
......@@ -21,6 +21,7 @@
<script src="{{ mix('js/index.js') }}"></script>
<link rel="stylesheet" href="{{ LaravelLocalization::getLocalizedURL(null, '/index.css?id=' . $mgv) }}">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<script src="{{mix('js/utility.js')}}"></script>
<meta http-equiv="refresh" content="1">
</head>
<body>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment