// ==UserScript==
// @name Filter short videos + realign grid
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Hides videos shorter than 5 minutes and displays the rest in a clean grid
// @match https://onlyfans.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
const MIN_DURATION = 5 * 60;
let active = false;
let gridContainer = null;
const alreadyAdded = new Set();
let originalScroller = null;
let mutationObserver = null;
function parseDuration(text) {
if (!text) return 0;
const parts = text.trim().split(':').map(Number);
if (parts.length === 2) return parts[0] * 60 + parts[1];
if (parts.length === 3) return parts[0] * 3600 + parts[1] * 60 + parts[2];
return 0;
}
function isValidVideo(anchor) {
const durationEl = anchor.querySelector('.b-purchase__list-item__count');
if (!durationEl) return true;
return parseDuration(durationEl.textContent) >= MIN_DURATION;
}
// ── ENABLE ─────────────────────────────────────────────
function enable() {
originalScroller = document.querySelector('.vue-recycle-scroller');
if (!originalScroller) return;
originalScroller.style.cssText = `
opacity: 0;
pointer-events: none;
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
`;
gridContainer = document.createElement('div');
gridContainer.id = 'filter-grid-custom';
gridContainer.style.cssText = `
display: flex;
flex-wrap: wrap;
gap: 2px;
width: 100%;
box-sizing: border-box;
`;
originalScroller.parentNode.insertBefore(gridContainer, originalScroller);
collectAndFilter();
keepScrollActive();
observe();
}
// ── DISABLE ────────────────────────────────────────────
function disable() {
if (mutationObserver) {
mutationObserver.disconnect();
mutationObserver = null;
}
if (gridContainer) {
gridContainer.remove();
gridContainer = null;
}
if (originalScroller) {
originalScroller.style.cssText = '';
originalScroller = null;
}
alreadyAdded.clear();
}
// ── TOGGLE ─────────────────────────────────────────────
function toggle() {
active = !active;
active ? enable() : disable();
updateButton();
}
// ── BUTTON ─────────────────────────────────────────────
function createButton() {
const btn = document.createElement('button');
btn.id = 'filter-toggle-btn';
btn.textContent = '🎬 Filter OFF';
btn.style.cssText = `
position: fixed;
bottom: 24px;
right: 24px;
z-index: 99999;
padding: 10px 16px;
border-radius: 24px;
border: none;
cursor: pointer;
font-size: 13px;
font-weight: bold;
box-shadow: 0 2px 10px rgba(0,0,0,0.4);
transition: background 0.2s, color 0.2s;
background: #333;
color: #aaa;
`;
btn.addEventListener('click', toggle);
document.body.appendChild(btn);
return btn;
}
function updateButton() {
const btn = document.getElementById('filter-toggle-btn');
if (!btn) return;
if (active) {
btn.textContent = '🎬 Filter ON';
btn.style.background = '#00aff0';
btn.style.color = '#fff';
} else {
btn.textContent = '🎬 Filter OFF';
btn.style.background = '#333';
btn.style.color = '#aaa';
}
}
// ── CORE ───────────────────────────────────────────────
function collectAndFilter() {
const scroller = document.querySelector('.vue-recycle-scroller');
if (!scroller || !gridContainer) return;
scroller.querySelectorAll('a.b-photos__item').forEach(anchor => {
const id = anchor.getAttribute('data-id');
if (!id || alreadyAdded.has(id)) return;
if (!isValidVideo(anchor)) {
alreadyAdded.add(id);
return;
}
alreadyAdded.add(id);
const clone = anchor.cloneNode(true);
clone.style.cssText = `
width: calc(33% - 1px);
height: 200px !important;
max-height: 200px !important;
display: block;
flex-shrink: 0;
box-sizing: border-box;
position: relative;
overflow: hidden;
padding: 0 !important;
margin: 0 !important;
`;
const img = clone.querySelector('img');
if (img) {
img.style.cssText = `
width: 100%;
height: 100%;
max-height: 200px !important;
object-fit: cover;
display: block;
position: absolute;
top: 0;
left: 0;
`;
}
gridContainer.appendChild(clone);
});
}
function keepScrollActive() {
const scroller = document.querySelector('.vue-recycle-scroller');
if (!scroller) return;
window.addEventListener('scroll', () => {
scroller.scrollTop = window.scrollY;
}, { passive: true });
}
function observe() {
mutationObserver = new MutationObserver(() => {
if (active) collectAndFilter();
});
mutationObserver.observe(document.body, {
childList: true,
subtree: true
});
}
// ── INIT ───────────────────────────────────────────────
function init() {
createButton();
}
if (document.readyState === 'complete') {
init();
} else {
window.addEventListener('load', init);
}
})();