// ==UserScript==
// @name Filester middle-click / new tab fix
// @match https://filester.me/f/*
// @match https://filester.sh/f/*
// @grant none
// ==/UserScript==
(function() {
function urlFor(el) {
const m = (el.getAttribute('onclick') || '').match(/\/d\/[A-Za-z0-9]+/);
return m ? location.origin + m[0] : null;
}
function fix(el) {
if (el.dataset.newtabFixed) return;
el.dataset.newtabFixed = "1";
el.title = "Left: open | Middle/Ctrl+Click: new tab";
el.addEventListener('mousedown', e => {
if (e.button === 1) e.preventDefault(); // no autoscroll
});
el.addEventListener('auxclick', e => {
if (e.button === 1) {
e.preventDefault(); e.stopPropagation();
const u = urlFor(el);
if (u) window.open(u, '_blank', 'noopener');
}
});
el.addEventListener('click', e => {
if (e.ctrlKey || e.metaKey || e.shiftKey) {
e.preventDefault(); e.stopPropagation();
const u = urlFor(el);
if (u) window.open(u, '_blank', 'noopener');
}
});
// native button: gives right-click > Open in new tab for free
const u = urlFor(el);
if (u && !el.querySelector('.newtab-btn')) {
const a = document.createElement('a');
a.href = u; a.target = '_blank'; a.rel = 'noopener';
a.className = 'newtab-btn'; a.textContent = '↗';
a.title = 'Open in new tab';
a.style.cssText = 'position:absolute;top:.5rem;left:.5rem;background:rgba(0,0,0,.6);color:#fff;border-radius:6px;padding:2px 7px;text-decoration:none;z-index:5';
a.addEventListener('click', e => e.stopPropagation());
el.style.position = 'relative';
el.appendChild(a);
}
}
function scan() {
document.querySelectorAll('.file-item').forEach(fix);
}
scan();
new MutationObserver(scan).observe(document.body, {childList:true, subtree:true});
})();