Last active
May 9, 2026 00:19
-
-
Save kaiser62/6c64380b5ac20ba593869f1b06a3bd93 to your computer and use it in GitHub Desktop.
iOS optimized video link collector with history poison blocker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Video Link Collector + History Poison Blocker - iOS Optimized | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.5 | |
| // @description Collect & copy all video links from page, and block back-button history traps. | |
| // @match *://www.thekamababa.com/* | |
| // @match *://desibf.com/* | |
| // @match *://www.xxxvideoindian2.com/* | |
| // @run-at document-start | |
| // @grant none | |
| // @inject-into page | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| function installHistoryPoisonBlocker() { | |
| 'use strict'; | |
| if (history.__historyPoisonBlockerInstalled) { | |
| return; | |
| } | |
| var originalPushState = history.pushState.bind(history); | |
| var originalReplaceState = history.replaceState.bind(history); | |
| var WINDOW_MS = 3000; | |
| var SAME_URL_LIMIT = 2; | |
| var calls = []; | |
| function normalizeUrl(url) { | |
| if (url === undefined || url === null || url === '') { | |
| return location.href; | |
| } | |
| try { | |
| return new URL(String(url), location.href).href; | |
| } catch (error) { | |
| return String(url); | |
| } | |
| } | |
| function prune(now) { | |
| while (calls.length && now - calls[0].time > WINDOW_MS) { | |
| calls.shift(); | |
| } | |
| } | |
| function shouldBlockPushState(url) { | |
| var now = Date.now(); | |
| var target = normalizeUrl(url); | |
| var current = location.href; | |
| var sameUrlCount = 0; | |
| var i; | |
| if (url === undefined || url === null || url === '' || target === current) { | |
| return true; | |
| } | |
| prune(now); | |
| calls.push({ time: now, target: target }); | |
| for (i = 0; i < calls.length; i += 1) { | |
| if (calls[i].target === current) { | |
| sameUrlCount += 1; | |
| } | |
| } | |
| return target === current && sameUrlCount > SAME_URL_LIMIT; | |
| } | |
| Object.defineProperty(history, 'pushState', { | |
| configurable: true, | |
| writable: true, | |
| value: function pushStateGuard(state, title, url) { | |
| if (shouldBlockPushState(url)) { | |
| console.warn('[History Poison Blocker] Blocked same-page history.pushState()', { | |
| url: normalizeUrl(url), | |
| state: state | |
| }); | |
| return; | |
| } | |
| return originalPushState(state, title, url); | |
| } | |
| }); | |
| Object.defineProperty(history, 'replaceState', { | |
| configurable: true, | |
| writable: true, | |
| value: function replaceStateGuard(state, title, url) { | |
| return originalReplaceState(state, title, url); | |
| } | |
| }); | |
| try { | |
| Object.defineProperty(history, '__historyPoisonBlockerInstalled', { | |
| configurable: false, | |
| enumerable: false, | |
| value: true | |
| }); | |
| } catch (error) { | |
| history.__historyPoisonBlockerInstalled = true; | |
| } | |
| } | |
| function installBlockerEarly() { | |
| try { | |
| installHistoryPoisonBlocker(); | |
| } catch (error) {} | |
| try { | |
| var inject = document.createElement('script'); | |
| inject.textContent = '(' + installHistoryPoisonBlocker.toString() + ')();'; | |
| (document.documentElement || document.head || document).appendChild(inject); | |
| inject.parentNode.removeChild(inject); | |
| } catch (error) {} | |
| } | |
| installBlockerEarly(); | |
| var allLinks = new Set(); | |
| var scannedPages = {}; | |
| var scanningPages = false; | |
| var observer = null; | |
| function addLink(url) { | |
| if (!url) { | |
| return; | |
| } | |
| try { | |
| url = new URL(String(url), location.href).href; | |
| } catch (error) { | |
| url = String(url); | |
| } | |
| if (isMediaUrl(url)) { | |
| allLinks.add(url); | |
| } | |
| } | |
| function isMediaUrl(url) { | |
| return /\.(mp4|m3u8|webm|mov|m4v|avi|mkv)(\?|#|$)/i.test(String(url || '')); | |
| } | |
| function decodeCleanTubePlayerUrl(url) { | |
| var q; | |
| var decoded; | |
| var match; | |
| if (!url || url.indexOf('player-x.php') === -1 || url.indexOf('q=') === -1) { | |
| return; | |
| } | |
| try { | |
| q = new URL(url, location.href).searchParams.get('q'); | |
| decoded = decodeURIComponent(atob(q || '')); | |
| match = decoded.match(/<source[^>]+src=["']([^"']+)["']/i); | |
| if (match && match[1]) { | |
| addLink(match[1]); | |
| } | |
| } catch (error) {} | |
| } | |
| function collectFromHtml(html, baseUrl) { | |
| var doc; | |
| var media; | |
| var frames; | |
| var i; | |
| var src; | |
| try { | |
| doc = new DOMParser().parseFromString(html, 'text/html'); | |
| } catch (error) { | |
| return; | |
| } | |
| media = doc.querySelectorAll('video[src], source[src], video[data-src], source[data-src], [data-video], [data-mp4], [data-trailer]'); | |
| frames = doc.querySelectorAll('iframe[src]'); | |
| for (i = 0; i < media.length; i += 1) { | |
| src = media[i].getAttribute('src') || media[i].getAttribute('data-src') || media[i].getAttribute('data-video') || media[i].getAttribute('data-mp4') || media[i].getAttribute('data-trailer'); | |
| if (src) { | |
| try { | |
| addLink(new URL(src, baseUrl).href); | |
| } catch (error) { | |
| addLink(src); | |
| } | |
| } | |
| } | |
| for (i = 0; i < frames.length; i += 1) { | |
| src = frames[i].getAttribute('src'); | |
| try { | |
| decodeCleanTubePlayerUrl(new URL(src, baseUrl).href); | |
| } catch (error) { | |
| decodeCleanTubePlayerUrl(src); | |
| } | |
| } | |
| } | |
| function collectLinkedPostMedia() { | |
| var links; | |
| var i; | |
| var href; | |
| var tasks = []; | |
| if (scanningPages || allLinks.size > 0 || location.hostname !== 'desibf.com') { | |
| return; | |
| } | |
| links = document.querySelectorAll('article.thumb-block a[href], .thumb-block a[href], .video-preview-item a[href]'); | |
| scanningPages = true; | |
| for (i = 0; i < links.length && tasks.length < 24; i += 1) { | |
| href = links[i].href; | |
| if (!href || scannedPages[href] || href.indexOf(location.origin + '/') !== 0 || href.indexOf('/page/') !== -1 || href.indexOf('/tag/') !== -1 || href.indexOf('/category/') !== -1) { | |
| continue; | |
| } | |
| scannedPages[href] = true; | |
| tasks.push(fetch(href, { credentials: 'same-origin' }).then(function (response) { | |
| return response.text().then(function (html) { | |
| collectFromHtml(html, response.url); | |
| }); | |
| }).catch(function () {})); | |
| } | |
| Promise.all(tasks).then(function () { | |
| scanningPages = false; | |
| }).catch(function () { | |
| scanningPages = false; | |
| }); | |
| } | |
| function collectLinks() { | |
| var articles = document.querySelectorAll('article[data-trailer]'); | |
| var media = document.querySelectorAll('video[src], source[src], video[data-src], source[data-src], [data-video], [data-mp4], [data-trailer]'); | |
| var frames = document.querySelectorAll('iframe[src]'); | |
| var i; | |
| var el; | |
| var url; | |
| for (i = 0; i < articles.length; i += 1) { | |
| url = articles[i].getAttribute('data-trailer'); | |
| addLink(url); | |
| } | |
| for (i = 0; i < media.length; i += 1) { | |
| el = media[i]; | |
| addLink(el.getAttribute('src')); | |
| addLink(el.getAttribute('data-src')); | |
| addLink(el.getAttribute('data-video')); | |
| addLink(el.getAttribute('data-mp4')); | |
| addLink(el.getAttribute('data-trailer')); | |
| } | |
| for (i = 0; i < frames.length; i += 1) { | |
| decodeCleanTubePlayerUrl(frames[i].getAttribute('src')); | |
| } | |
| collectLinkedPostMedia(); | |
| } | |
| function copyToClipboard(text) { | |
| if (navigator.clipboard && navigator.clipboard.writeText) { | |
| return navigator.clipboard.writeText(text).then(function () { | |
| return true; | |
| }).catch(function () { | |
| return fallbackCopyToClipboard(text); | |
| }); | |
| } | |
| return Promise.resolve(fallbackCopyToClipboard(text)); | |
| } | |
| function fallbackCopyToClipboard(text) { | |
| var textArea = document.createElement('textarea'); | |
| var success = false; | |
| textArea.value = text; | |
| textArea.setAttribute('readonly', 'readonly'); | |
| textArea.style.position = 'fixed'; | |
| textArea.style.top = '0'; | |
| textArea.style.left = '0'; | |
| textArea.style.width = '1px'; | |
| textArea.style.height = '1px'; | |
| textArea.style.opacity = '0'; | |
| textArea.style.zIndex = '-1'; | |
| document.body.appendChild(textArea); | |
| textArea.focus(); | |
| textArea.select(); | |
| textArea.setSelectionRange(0, textArea.value.length); | |
| try { | |
| success = document.execCommand('copy'); | |
| } catch (error) { | |
| success = false; | |
| } | |
| document.body.removeChild(textArea); | |
| return success; | |
| } | |
| function createUI() { | |
| var bar; | |
| var btn; | |
| var counter; | |
| if (document.getElementById('video-copy-bar')) { | |
| return; | |
| } | |
| bar = document.createElement('div'); | |
| bar.id = 'video-copy-bar'; | |
| Object.assign(bar.style, { | |
| position: 'fixed', | |
| top: 'env(safe-area-inset-top, 0)', | |
| left: '0', | |
| width: '100%', | |
| background: '#111', | |
| color: '#fff', | |
| padding: '10px 8px', | |
| zIndex: '2147483647', | |
| display: 'flex', | |
| gap: '10px', | |
| alignItems: 'center', | |
| fontSize: '14px', | |
| boxSizing: 'border-box' | |
| }); | |
| btn = document.createElement('button'); | |
| btn.textContent = 'π Copy All Links'; | |
| Object.assign(btn.style, { | |
| padding: '8px 12px', | |
| cursor: 'pointer', | |
| background: '#ff5722', | |
| border: 'none', | |
| color: '#fff', | |
| borderRadius: '4px', | |
| fontWeight: 'bold', | |
| fontSize: '14px' | |
| }); | |
| counter = document.createElement('span'); | |
| counter.textContent = 'Links: 0'; | |
| btn.addEventListener('click', function (event) { | |
| var text; | |
| event.preventDefault(); | |
| collectLinks(); | |
| if (allLinks.size === 0) { | |
| btn.textContent = 'β οΈ No Links'; | |
| setTimeout(function () { | |
| btn.textContent = 'π Copy All Links'; | |
| }, 2000); | |
| return; | |
| } | |
| text = Array.from(allLinks).join('\n'); | |
| copyToClipboard(text).then(function (success) { | |
| if (success) { | |
| btn.textContent = 'β Copied (' + allLinks.size + ')'; | |
| } else { | |
| btn.textContent = 'β Failed'; | |
| } | |
| setTimeout(function () { | |
| btn.textContent = 'π Copy All Links'; | |
| }, 2000); | |
| }); | |
| }); | |
| bar.appendChild(btn); | |
| bar.appendChild(counter); | |
| document.body.appendChild(bar); | |
| setInterval(function () { | |
| collectLinks(); | |
| counter.textContent = 'Links: ' + allLinks.size; | |
| }, 1500); | |
| } | |
| function init() { | |
| createUI(); | |
| collectLinks(); | |
| if (!observer && document.body) { | |
| observer = new MutationObserver(collectLinks); | |
| observer.observe(document.body, { | |
| childList: true, | |
| subtree: true | |
| }); | |
| } | |
| } | |
| if (document.readyState === 'loading') { | |
| document.addEventListener('DOMContentLoaded', init); | |
| } else { | |
| init(); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment