Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
79 lines (67 loc) · 2.58 KB
/
Copy pathscript.js
File metadata and controls
79 lines (67 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* HiRes Image: Enhances image sharpness by loading original files.
*/
(function() {
"use strict";
const sharpen = function(img) {
if (!img || img.dataset.hiResProcessed) return;
try {
const url = new URL(img.src);
// Match images scaled by DokuWiki (containing w= or h=)
if (url.searchParams.has('w') || url.searchParams.has('h')) {
const w = url.searchParams.get('w');
const h = url.searchParams.get('h');
// Remove scaling parameters and security tokens to fetch original
url.searchParams.delete('w');
url.searchParams.delete('h');
url.searchParams.delete('tok');
img.src = url.toString();
// Apply CSS constraints to maintain intended layout size
if (w) {
img.style.width = w + 'px';
}
else {
img.style.width = 'auto';
}
if (h) {
img.style.height = h + 'px';
}
else {
img.style.height = 'auto';
}
// Optimization for High-DPI (Retina) displays
img.style.imageRendering = '-webkit-optimize-contrast';
img.dataset.hiResProcessed = "true";
}
} catch (e) {
// Ignore parsing errors for non-standard URLs
}
};
const scan = function() {
const sel = 'img.media, img.medialeft, img.mediaright, img.mediacenter';
document.querySelectorAll(sel).forEach(sharpen);
};
// Run on initial page load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', scan);
} else {
scan(); // Run immediately
}
// Dynamic observer for editors (like Prosemirror) or async content
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1) {
if (node.tagName === 'IMG') {
sharpen(node);
} else {
node.querySelectorAll('img').forEach(sharpen);
}
}
});
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
})();