Filter videos by duration natively, persist settings, and decode redirect URLs. Flawless Desktop & Mobile UI.
// ==UserScript==
// @name GayMaleTube Duration Filter & Link Decoder (Native UI)
// @namespace http://tampermonkey.net/
// @version 3.1
// @description Filter videos by duration natively, persist settings, and decode redirect URLs. Flawless Desktop & Mobile UI.
// @author You
// @match *://*.gaymaletube.com/*
// @match *://gaymaletube.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Settings
const STORAGE_KEY = 'gmt_custom_min_duration';
const savedFilter = localStorage.getItem(STORAGE_KEY);
let currentFilterMinutes = savedFilter ? parseFloat(savedFilter) : null;
// ==========================================
// 1. Decode the Tracking / Out Links
// ==========================================
function decodeVideoLinks(card) {
if (card.dataset.linksDecoded === "true") return;
const outLinks = card.querySelectorAll('a[href^="/out/?"]');
outLinks.forEach(link => {
try {
const urlObj = new URL(link.href, window.location.origin);
const encodedPayload = urlObj.searchParams.get('l');
if (encodedPayload) {
// Normalize Base64 string and fix padding
let b64 = encodedPayload.replace(/-/g, '+').replace(/_/g, '/');
while (b64.length % 4) { b64 += '='; }
const binaryString = atob(b64);
const match = binaryString.match(/https?:\/\/[a-zA-Z0-9\-._~:/?#[\]@!$&*+;=%]+/);
if (match && match[0]) {
link.href = match[0];
link.removeAttribute('rel');
}
}
} catch (err) {}
});
card.dataset.linksDecoded = "true";
}
// ==========================================
// 2. Duration Filter Logic
// ==========================================
function applyVisibility(card) {
if (currentFilterMinutes === null) {
card.style.display = '';
return;
}
const timeBadge = card.querySelector('.item-meta-container .badge');
let durationStr = timeBadge ? timeBadge.textContent.trim() : '';
const match = durationStr.match(/(?:(\d+):)?(\d+):(\d{2})/);
if (match) {
const hours = match[1] ? parseInt(match[1], 10) : 0;
const mins = parseInt(match[2], 10);
const secs = parseInt(match[3], 10);
const totalMinutes = (hours * 60) + mins + (secs / 60);
if (totalMinutes >= currentFilterMinutes) {
card.style.display = '';
} else {
card.style.display = 'none';
}
} else {
card.style.display = 'none';
}
}
function processCard(card) {
decodeVideoLinks(card);
applyVisibility(card);
}
// ==========================================
// 3. Apply/Reset State Handlers
// ==========================================
function applyFilter(val) {
const parsed = parseFloat(val);
if (isNaN(parsed)) return;
currentFilterMinutes = parsed;
localStorage.setItem(STORAGE_KEY, parsed);
updateAllUI();
document.querySelectorAll('.cards-container .card').forEach(processCard);
}
function resetFilter() {
currentFilterMinutes = null;
localStorage.removeItem(STORAGE_KEY);
updateAllUI();
document.querySelectorAll('.cards-container .card').forEach(processCard);
}
function updateAllUI() {
// Sync Desktop Button States
document.querySelectorAll('.gmt-custom-btn').forEach(btn => {
const menu = btn.nextElementSibling;
if (menu) menu.style.display = 'none'; // Close menus
const label = btn.querySelector('.label');
if (currentFilterMinutes !== null) {
label.innerHTML = `<b>Min: ${currentFilterMinutes}+ mins</b>`;
btn.classList.add('bg-zinc-200', 'dark:bg-zinc-700');
} else {
label.textContent = 'Custom Min';
btn.classList.remove('bg-zinc-200', 'dark:bg-zinc-700');
}
});
// Sync Desktop & Mobile Inputs
document.querySelectorAll('.gmt-custom-input').forEach(inp => {
inp.value = currentFilterMinutes !== null ? currentFilterMinutes : '';
});
}
// ==========================================
// 4. Inject Native-Looking UI Dropdown
// ==========================================
function injectCustomFilter() {
const containers = document.querySelectorAll('.filter-button-container');
containers.forEach(container => {
if (container.querySelector('.gmt-custom-filter-container')) return;
// Detect if this specific container is the mobile flyout or the desktop nav
const isMobileForm = container.closest('form[name="mobile-filter"]') !== null;
const wrapper = document.createElement('div');
if (isMobileForm) {
// -------- MOBILE LAYOUT --------
// On mobile, the site doesn't use dropdown buttons inside the side-drawer.
// They just list the options below a header.
wrapper.className = 'content-filter-container w-full flex-shrink-0 gmt-custom-filter-container';
wrapper.innerHTML = `
<div class="filter-title-container flex justify-between px-3 desktop:hidden mb-2 mt-4">
<div class="filter-header-title m-0 font-medium mb-1 text-base text-zinc-900 dark:text-zinc-100">
Custom Min Duration
</div>
</div>
<div class="px-3">
<div class="flex flex-col gap-2">
<input type="number" class="gmt-custom-input w-full p-2 border border-zinc-300 dark:border-zinc-600 rounded bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 outline-none focus:border-zinc-500" placeholder="e.g., 15" min="0" value="${currentFilterMinutes !== null ? currentFilterMinutes : ''}">
<div class="flex justify-between gap-2 mt-1">
<button type="button" class="gmt-apply-btn w-full p-2 rounded bg-blue-600 hover:bg-blue-700 text-white font-medium cursor-pointer border-0 transition-colors">Apply</button>
<button type="button" class="gmt-reset-btn w-full p-2 rounded bg-red-600 hover:bg-red-700 text-white font-medium cursor-pointer border-0 transition-colors">Clear</button>
</div>
</div>
</div>
`;
} else {
// -------- DESKTOP LAYOUT --------
wrapper.className = 'filter-dropdown content-filter-container whitespace-nowrap relative gmt-custom-filter-container';
wrapper.innerHTML = `
<button type="button" class="chip inline-flex whitespace-nowrap gap-1 w-auto p-2 items-center text-sm rounded-lg transition-colors duration-200 ease-in-out cursor-pointer border border-zinc-300 dark:border-zinc-600 text-zinc-900 dark:text-zinc-100 bg-zinc-100 dark:bg-zinc-800 hover:bg-zinc-200 dark:hover:bg-zinc-700 gmt-custom-btn ${currentFilterMinutes !== null ? 'bg-zinc-200 dark:bg-zinc-700' : ''}">
<span class="label">${currentFilterMinutes !== null ? `<b>Min: ${currentFilterMinutes}+ mins</b>` : 'Custom Min'}</span>
<i class="far icon-end fa-chevron-down"></i>
</button>
<div class="dropdown-menu gmt-custom-menu bg-zinc-100 dark:bg-zinc-800 border border-zinc-300 dark:border-zinc-600" style="display: none; position: absolute; z-index: 1050; padding: 12px; margin-top: 4px; border-radius: 8px; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.5); width: 220px; left: 0;">
<div class="flex flex-col gap-2">
<label class="text-sm font-bold text-zinc-900 dark:text-zinc-100">Minimum Minutes:</label>
<input type="number" class="gmt-custom-input w-full p-2 border border-zinc-300 dark:border-zinc-600 rounded bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 outline-none focus:border-zinc-500" placeholder="e.g., 15" min="0" value="${currentFilterMinutes !== null ? currentFilterMinutes : ''}">
<div class="flex justify-between gap-2 mt-2">
<button type="button" class="gmt-apply-btn w-full p-2 rounded bg-blue-600 hover:bg-blue-700 text-white font-medium cursor-pointer border-0 transition-colors">Apply</button>
<button type="button" class="gmt-reset-btn w-full p-2 rounded bg-red-600 hover:bg-red-700 text-white font-medium cursor-pointer border-0 transition-colors">Clear</button>
</div>
</div>
</div>
`;
}
container.appendChild(wrapper);
const input = wrapper.querySelector('.gmt-custom-input');
const applyBtn = wrapper.querySelector('.gmt-apply-btn');
const resetBtn = wrapper.querySelector('.gmt-reset-btn');
// --- Prevention Handlers (Stops website's form submission) ---
const stopProp = (e) => e.stopPropagation();
wrapper.addEventListener('mousedown', stopProp);
wrapper.addEventListener('click', stopProp);
input.addEventListener('keydown', stopProp);
input.addEventListener('keyup', stopProp);
// Handle Desktop Dropdown Opening
if (!isMobileForm) {
const btn = wrapper.querySelector('.gmt-custom-btn');
const menu = wrapper.querySelector('.gmt-custom-menu');
btn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
const isHidden = menu.style.display === 'none';
document.querySelectorAll('.gmt-custom-menu').forEach(m => m.style.display = 'none');
if (isHidden) {
menu.style.display = 'block';
input.focus();
}
});
}
input.addEventListener('keypress', (e) => {
e.stopPropagation();
if (e.key === 'Enter') {
e.preventDefault();
applyFilter(input.value);
}
});
applyBtn.addEventListener('click', (e) => {
e.preventDefault(); e.stopPropagation();
applyFilter(input.value);
});
resetBtn.addEventListener('click', (e) => {
e.preventDefault(); e.stopPropagation();
resetFilter();
});
});
}
// Global listener to close desktop dropdown if user clicks away
document.addEventListener('click', (e) => {
if (!e.target.closest('.gmt-custom-filter-container')) {
document.querySelectorAll('.gmt-custom-menu').forEach(m => m.style.display = 'none');
}
});
// ==========================================
// 5. Initial Run & DOM Observers
// ==========================================
injectCustomFilter();
setInterval(injectCustomFilter, 1500);
document.querySelectorAll('.cards-container .card').forEach(processCard);
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === 1) {
if (node.classList && node.classList.contains('card')) {
processCard(node);
} else if (node.querySelectorAll) {
const innerCards = node.querySelectorAll('.card');
if (innerCards.length > 0) {
innerCards.forEach(processCard);
}
}
}
});
});
});
observer.observe(document.body, { childList: true, subtree: true });
})();