sitoctt/static/local-file-tweaks.js

29 lines
619 B
JavaScript
Raw Normal View History

2024-08-27 22:55:45 +02:00
(function(){
if (location.protocol !== 'file:') {
window.PatchLocalFileAnchor = Void;
2024-08-27 22:55:45 +02:00
return;
}
window.PatchLocalFileAnchor = (function PatchLocalFileAnchor (anchorEl) {
var href = anchorEl.href;
if (href.startsWith('file://')) {
var tokens = href.split('#');
href = tokens[0];
if (href.endsWith('/')) {
href += 'index.html';
2024-08-27 22:55:45 +02:00
}
tokens = tokens.slice(1);
if (tokens.length) {
href += ('#' + tokens.join('#'));
}
anchorEl.href = href;
}
});
window.addEventListener('DOMContentLoaded', (function(){
Array.from(document.querySelectorAll('a[href]')).forEach(PatchLocalFileAnchor);
2024-08-27 22:55:45 +02:00
}));
})();