SHOW:
|
|
- or go back to the newest paste.
| 1 | // ==UserScript== | |
| 2 | // @name RG Tweet Video Remover | |
| 3 | // @namespace http://tampermonkey.net/ | |
| 4 | // @version 1.0 | |
| 5 | // @description Floating RG button activates/deactivates tweet_video post removal | |
| 6 | // @author you | |
| 7 | - | // @match *://twitter.com/* |
| 7 | + | // @match *://nitter.privacydev.net/* |
| 8 | - | // @match *://x.com/* |
| 8 | + | // @match *://nitter.poast.org/* |
| 9 | // @match *://xcancel.com/* | |
| 10 | // @match *://lightbrd.com/* | |
| 11 | // @match *://nitter.net/* | |
| 12 | // @grant none | |
| 13 | // ==/UserScript== | |
| 14 | ||
| 15 | (function() {
| |
| 16 | 'use strict'; | |
| 17 | ||
| 18 | let isActive = false; | |
| 19 | let observer = null; | |
| 20 | ||
| 21 | function removeRelevantPosts() {
| |
| 22 | const items = document.querySelectorAll('.timeline-item, article, [data-testid="tweet"]');
| |
| 23 | items.forEach(function(item) {
| |
| 24 | if ( | |
| 25 | item.innerHTML.includes('video.twimg.com%2Ftweet_video%2F') ||
| |
| 26 | item.innerHTML.includes('video.twimg.com/tweet_video/')
| |
| 27 | ) {
| |
| 28 | item.remove(); | |
| 29 | } | |
| 30 | }); | |
| 31 | } | |
| 32 | ||
| 33 | function setButtonActive(active) {
| |
| 34 | if(active){
| |
| 35 | removeRelevantPosts(); | |
| 36 | observer = new MutationObserver(() => {
| |
| 37 | removeRelevantPosts(); | |
| 38 | }); | |
| 39 | observer.observe(document.body, {childList:true, subtree:true});
| |
| 40 | fabButton.style.background = isDarkMode() ? '#048848' : '#23be78'; | |
| 41 | fabButton.style.color = '#fff'; | |
| 42 | fabButton.title = 'RG Active: Hides tweet_video posts'; | |
| 43 | } else {
| |
| 44 | if(observer) observer.disconnect(); | |
| 45 | observer = null; | |
| 46 | fabButton.style.background = isDarkMode() ? '#222' : '#fff'; | |
| 47 | fabButton.style.color = isDarkMode() ? '#fff' : '#005940'; | |
| 48 | fabButton.title = 'RG Inactive: Click to activate'; | |
| 49 | } | |
| 50 | } | |
| 51 | ||
| 52 | function isDarkMode() {
| |
| 53 | return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
| |
| 54 | } | |
| 55 | ||
| 56 | // Create floating button | |
| 57 | let fabButton = document.createElement('button');
| |
| 58 | fabButton.textContent = "RG "; | |
| 59 | fabButton.setAttribute('aria-label', 'Remove GIF posts');
| |
| 60 | fabButton.title = 'RG Inactive: Click to activate'; | |
| 61 | fabButton.style.position = 'fixed'; | |
| 62 | fabButton.style.bottom = '24px'; | |
| 63 | fabButton.style.left = '116px'; // ~2 places to right from far left; each "place" ~46px, adjust for your UI. | |
| 64 | fabButton.style.zIndex = '99999'; | |
| 65 | fabButton.style.fontSize = '18px'; | |
| 66 | fabButton.style.padding = '10px 18px'; | |
| 67 | fabButton.style.borderRadius = '24px'; | |
| 68 | fabButton.style.border = '1.5px solid #ccc'; | |
| 69 | fabButton.style.boxShadow = '0 4px 24px rgba(0,0,0,0.11)'; | |
| 70 | fabButton.style.fontWeight = 'bold'; | |
| 71 | fabButton.style.cursor = 'pointer'; | |
| 72 | fabButton.style.transition = 'background 0.2s,color 0.2s'; | |
| 73 | fabButton.style.background = isDarkMode() ? '#222' : '#fff'; | |
| 74 | fabButton.style.color = isDarkMode() ? '#fff' : '#005940'; | |
| 75 | fabButton.style.userSelect = 'none'; | |
| 76 | ||
| 77 | document.body.appendChild(fabButton); | |
| 78 | ||
| 79 | let style = document.createElement('style');
| |
| 80 | style.textContent = ` | |
| 81 | #__rg_fab_button:active {transform: scale(0.98);}
| |
| 82 | `; | |
| 83 | document.head.appendChild(style); | |
| 84 | ||
| 85 | fabButton.addEventListener('click', function() {
| |
| 86 | isActive = !isActive; | |
| 87 | - | // Persist state on reload |
| 87 | + | |
| 88 | }); | |
| 89 | ||
| 90 | // Persist state on reload | |
| 91 | window.addEventListener("pageshow",function(){
| |
| 92 | setButtonActive(isActive); | |
| 93 | }); | |
| 94 | ||
| 95 | // Optional: update button color on theme change | |
| 96 | window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function() {
| |
| 97 | setButtonActive(isActive); | |
| 98 | }); | |
| 99 | })(); | |
| 100 |