Guest User

Blur Media

a guest
Aug 22nd, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Blur Media
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.0
  5. // @description  Blur images and videos until clicked, with temporary unblur on hover
  6. // @author       You
  7. // @match        *://kiwifarms.st/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     // Style for blurring media
  15.     const blurStyle = `
  16.         .blurred {
  17.             filter: blur(15px);
  18.             transition: filter 0.3s ease;
  19.         }
  20.         .blurred:hover {
  21.             filter: none;
  22.         }
  23.     `;
  24.  
  25.     // Create and add the style to the document head
  26.     const styleSheet = document.createElement('style');
  27.     styleSheet.type = 'text/css';
  28.     styleSheet.innerText = blurStyle;
  29.     document.head.appendChild(styleSheet);
  30.  
  31.     // Function to blur all media elements
  32.     function blurMedia() {
  33.         const mediaElements = document.querySelectorAll('img, video');
  34.         mediaElements.forEach(media => {
  35.             if (!media.classList.contains('blurred')) {
  36.                 media.classList.add('blurred');
  37.                 media.addEventListener('click', () => {
  38.                     media.classList.remove('blurred');
  39.                 });
  40.             }
  41.         });
  42.     }
  43.  
  44.     // Run the blurMedia function initially
  45.     blurMedia();
  46.  
  47.     // Observe DOM changes to handle dynamically added media
  48.     const observer = new MutationObserver(() => {
  49.         blurMedia();
  50.     });
  51.  
  52.     // Start observing the document body for changes
  53.     observer.observe(document.body, { childList: true, subtree: true });
  54. })();
Advertisement
Add Comment
Please, Sign In to add comment