mirror of
https://github.com/zadam/trilium.git
synced 2025-12-29 18:54:29 +01:00
feat(pdfjs): debounce saving view config
This commit is contained in:
parent
84425e86e9
commit
359f398afa
@ -2,17 +2,7 @@ export default function interceptViewHistory() {
|
||||
const originalSetItem = Storage.prototype.setItem;
|
||||
Storage.prototype.setItem = function (key: string, value: string) {
|
||||
if (key === "pdfjs.history") {
|
||||
// Parse the history and remove entries that are not relevant.
|
||||
const history = JSON.parse(value);
|
||||
const fingerprint = window.PDFViewerApplication?.pdfDocument?.fingerprints?.[0];
|
||||
if (fingerprint) {
|
||||
history.files = history.files.filter((file: any) => file.fingerprint === fingerprint);
|
||||
}
|
||||
|
||||
window.parent.postMessage({
|
||||
type: "pdfjs-viewer-save-view-history",
|
||||
data: JSON.stringify(history)
|
||||
}, "*");
|
||||
saveHistory(value);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -28,3 +18,25 @@ export default function interceptViewHistory() {
|
||||
return originalGetItem.call(this, key);
|
||||
}
|
||||
}
|
||||
|
||||
let saveTimeout: number | null = null;
|
||||
|
||||
function saveHistory(value: string) {
|
||||
if (saveTimeout) {
|
||||
clearTimeout(saveTimeout);
|
||||
}
|
||||
saveTimeout = window.setTimeout(() => {
|
||||
// Parse the history and remove entries that are not relevant.
|
||||
const history = JSON.parse(value);
|
||||
const fingerprint = window.PDFViewerApplication?.pdfDocument?.fingerprints?.[0];
|
||||
if (fingerprint) {
|
||||
history.files = history.files.filter((file: any) => file.fingerprint === fingerprint);
|
||||
}
|
||||
|
||||
window.parent.postMessage({
|
||||
type: "pdfjs-viewer-save-view-history",
|
||||
data: JSON.stringify(history)
|
||||
}, "*");
|
||||
saveTimeout = null;
|
||||
}, 2_000);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user