Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name RG Tweet Video Remover with Catalog
- // @namespace http://tampermonkey.net/
- // @version 1.1
- // @description Floating RG button removes tweet_video posts, catalogs URLs, and copies them via 📋 button
- // @author you
- // @match *://nitter.privacydev.net/*
- // @match *://nitter.poast.org/*
- // @match *://xcancel.com/*
- // @match *://lightbrd.com/*
- // @match *://nitter.net/*
- // @grant GM_setClipboard
- // ==/UserScript==
- (function() {
- 'use strict';
- let isActive = false;
- let observer = null;
- let deletedUrls = new Set();
- function isDarkMode() {
- return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
- }
- function getStatusUrl(item) {
- // Try to find the status link in the tweet/post element
- let aList = item.querySelectorAll('a[href*="/status/"]');
- for (let a of aList) {
- let match = a.href.match(/https:\/\/(twitter|x)\.com\/[^/]+\/status\/\d+/);
- if (match) return match;
- }
- return null;
- }
- function removeRelevantPosts() {
- const items = document.querySelectorAll('.timeline-item, article, [data-testid="tweet"]');
- items.forEach(function(item) {
- if (
- item.innerHTML.includes('video.twimg.com%2Ftweet_video%2F') ||
- item.innerHTML.includes('video.twimg.com/tweet_video/')
- ) {
- let url = getStatusUrl(item);
- if (url && !deletedUrls.has(url)) {
- deletedUrls.add(url);
- addUrlToCatalog(url);
- }
- item.remove();
- }
- });
- }
- // --- UI Elements ---
- // RG Toggle Button
- let fabButton = document.createElement('button');
- fabButton.textContent = "RG ";
- fabButton.setAttribute('aria-label', 'Remove GIF posts');
- fabButton.title = 'RG Inactive: Click to activate';
- fabButton.style.position = 'fixed';
- fabButton.style.bottom = '24px';
- fabButton.style.left = '116px';
- fabButton.style.zIndex = '99999';
- fabButton.style.fontSize = '18px';
- fabButton.style.padding = '10px 18px';
- fabButton.style.borderRadius = '24px';
- fabButton.style.border = '1.5px solid #ccc';
- fabButton.style.boxShadow = '0 4px 24px rgba(0,0,0,0.11)';
- fabButton.style.fontWeight = 'bold';
- fabButton.style.cursor = 'pointer';
- fabButton.style.transition = 'background 0.2s,color 0.2s';
- fabButton.style.background = isDarkMode() ? '#222' : '#fff';
- fabButton.style.color = isDarkMode() ? '#fff' : '#005940';
- fabButton.style.userSelect = 'none';
- document.body.appendChild(fabButton);
- // Catalog UI (collapsible)
- let catalogUI = document.createElement('div');
- catalogUI.style.position = 'fixed';
- catalogUI.style.left = '116px';
- catalogUI.style.bottom = '76px';
- catalogUI.style.zIndex = '99999';
- catalogUI.style.minWidth = '272px';
- catalogUI.style.maxWidth = '330px';
- catalogUI.style.maxHeight = '300px';
- catalogUI.style.overflowY = 'auto';
- catalogUI.style.background = isDarkMode() ? '#232629' : '#fbfbfb';
- catalogUI.style.color = isDarkMode() ? '#fff' : '#212121';
- catalogUI.style.border = '1.5px solid #ccc';
- catalogUI.style.border = '1.5px solid #ccc';
- catalogUI.style.borderRadius = '12px';
- catalogUI.style.boxShadow = '0 4px 24px rgba(0,0,0,0.12)';
- catalogUI.style.padding = '10px 10px 8px 12px';
- catalogUI.style.fontSize = '15px';
- catalogUI.style.display = 'flex';
- catalogUI.style.flexDirection = 'column';
- catalogUI.style.gap = '7px';
- catalogUI.style.userSelect = 'text';
- // Collapsible header
- const catalogHeader = document.createElement('div');
- catalogHeader.style.display = 'flex';
- catalogHeader.style.justifyContent = 'space-between';
- catalogHeader.style.alignItems = 'center';
- catalogHeader.style.cursor = 'pointer';
- catalogHeader.style.paddingBottom = '6px';
- catalogHeader.style.borderBottom = '1px solid #ccc';
- const headerTitle = document.createElement('span');
- headerTitle.textContent = '🗂️ Removed Status URLs';
- const collapseBtn = document.createElement('span');
- collapseBtn.textContent = '▾'; // Collapsed: '▸', Expanded: '▾'
- collapseBtn.style.fontSize = '14px';
- collapseBtn.style.marginLeft = '7px';
- catalogHeader.appendChild(headerTitle);
- catalogHeader.appendChild(collapseBtn);
- // URL List
- const urlList = document.createElement('div');
- urlList.id = 'rg-url-list';
- urlList.style.margin = '7px 0 0 0';
- urlList.style.display = 'block';
- // Copy button
- const copyBtn = document.createElement('button');
- copyBtn.textContent = '📋';
- copyBtn.title = 'Copy all URLs';
- copyBtn.style.margin = '3px 0 0 3px';
- copyBtn.style.border = '1px solid #bbb';
- copyBtn.style.borderRadius = '6px';
- copyBtn.style.padding = '3px 7px';
- copyBtn.style.background = isDarkMode() ? '#333' : '#eee';
- copyBtn.style.color = isDarkMode() ? '#fff' : '#222';
- copyBtn.style.fontSize = '15px';
- copyBtn.style.cursor = 'pointer';
- copyBtn.style.alignSelf = 'flex-start';
- copyBtn.style.transition = 'background 0.15s';
- copyBtn.addEventListener('click', function () {
- const allUrls = Array.from(deletedUrls).join('\n');
- if (typeof GM_setClipboard !== 'undefined') {
- GM_setClipboard(allUrls, { type: 'text', mimetype: 'text/plain' });
- } else if (navigator.clipboard) {
- navigator.clipboard.writeText(allUrls);
- }
- copyBtn.textContent = '✅';
- setTimeout(() => (copyBtn.textContent = '📋'), 900);
- });
- // Collapse functionality
- let collapsed = false;
- catalogHeader.addEventListener('click', function () {
- collapsed = !collapsed;
- urlList.style.display = collapsed ? 'none' : 'block';
- copyBtn.style.display = collapsed ? 'none' : 'inline-block';
- collapseBtn.textContent = collapsed ? '▸' : '▾';
- });
- // Add children to catalog UI
- catalogUI.appendChild(catalogHeader);
- catalogUI.appendChild(copyBtn);
- catalogUI.appendChild(urlList);
- document.body.appendChild(catalogUI);
- function addUrlToCatalog(url) {
- if (document.getElementById('rg-url-' + btoa(url))) return;
- const urlBox = document.createElement('div');
- urlBox.textContent = url;
- urlBox.style.background = isDarkMode() ? '#181c1f' : '#f2f2f4';
- urlBox.style.borderRadius = '4px';
- urlBox.style.padding = '4px 7px';
- urlBox.style.margin = '2px 0';
- urlBox.style.wordBreak = 'break-all';
- urlBox.id = 'rg-url-' + btoa(url);
- urlList.appendChild(urlBox);
- }
- function refreshCatalogTheme() {
- catalogUI.style.background = isDarkMode() ? '#232629' : '#fbfbfb';
- catalogUI.style.color = isDarkMode() ? '#fff' : '#212121';
- copyBtn.style.background = isDarkMode() ? '#333' : '#eee';
- copyBtn.style.color = isDarkMode() ? '#fff' : '#222';
- urlList.querySelectorAll('div').forEach(el => {
- el.style.background = isDarkMode() ? '#181c1f' : '#f2f2f4';
- });
- fabButton.style.background = isDarkMode() ? (isActive ? '#048848':'#222') : (isActive ? '#23be78':'#fff');
- fabButton.style.color = isDarkMode() ? '#fff' : (isActive ? '#fff' : '#005940');
- }
- // The RG button logic
- function setButtonActive(active) {
- if(active){
- removeRelevantPosts();
- observer = new MutationObserver(() => {
- removeRelevantPosts();
- });
- observer.observe(document.body, {childList:true, subtree:true});
- fabButton.style.background = isDarkMode() ? '#048848' : '#23be78';
- fabButton.style.color = '#fff';
- fabButton.title = 'RG Active: Hides tweet_video posts';
- } else {
- if(observer) observer.disconnect();
- observer = null;
- fabButton.style.background = isDarkMode() ? '#222' : '#fff';
- fabButton.style.color = isDarkMode() ? '#fff' : '#005940';
- fabButton.title = 'RG Inactive: Click to activate';
- }
- refreshCatalogTheme();
- }
- fabButton.addEventListener('click', function() {
- isActive = !isActive;
- setButtonActive(isActive);
- });
- // On page reload
- window.addEventListener("pageshow",function(){
- setButtonActive(isActive);
- });
- // Update on dark/light change
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', refreshCatalogTheme);
- // Don't let the catalog or button block pointer events to stuff underneath
- fabButton.style.pointerEvents = 'auto';
- catalogUI.style.pointerEvents = 'auto';
- // Extra: give RG button and catalog unique IDs for styling/debug
- fabButton.id = '__rg_fab_button';
- catalogUI.id = '__rg_catalog_ui';
- })();
Advertisement
Add Comment
Please, Sign In to add comment