# Greasemonkey Example Rules This document contains useful example rules you can use with Greasemonkey. Copy and paste these into your extension to get started quickly. ## Table of Contents 1. [Page Styling](#page-styling) 2. [Element Manipulation](#element-manipulation) 3. [Content Blocking](#content-blocking) 4. [Automation](#automation) 5. [Custom Features](#custom-features) --- ## Page Styling ### Dark Mode for Any Site **Match Type:** URL contains string **URL Pattern:** `example.com` (replace with your target site) **CSS Code:** ```css body { background-color: #1a1a1a !important; color: #e0e0e0 !important; } a { color: #4a9eff !important; } div, p, span, article { background-color: #1a1a1a !important; color: #e0e0e0 !important; } ``` ### Increase Font Size **Match Type:** URL contains string **URL Pattern:** `news-site.com` **CSS Code:** ```css body { font-size: 18px !important; line-height: 1.6 !important; } p { font-size: 18px !important; } ``` ### Remove Animations **Match Type:** URL contains string **URL Pattern:** (any site with annoying animations) **CSS Code:** ```css * { animation: none !important; transition: none !important; } ``` ### Custom Color Scheme **Match Type:** URL contains string **URL Pattern:** `docs.` (targets documentation sites) **CSS Code:** ```css :root { --bg-color: #282c34; --text-color: #abb2bf; --accent-color: #61afef; } body { background-color: var(--bg-color) !important; color: var(--text-color) !important; } a { color: var(--accent-color) !important; } ``` --- ## Element Manipulation ### Highlight Search Results **Match Type:** Page contains element **Element Selector:** `.search-result` **CSS Code:** ```css .search-result:hover { background-color: #fff3cd !important; border-left: 4px solid #ffc107 !important; transition: all 0.2s ease !important; } ``` ### Auto-Expand Collapsed Content **Match Type:** Page contains element **Element Selector:** `.collapsed` **JavaScript Code:** ```javascript document.querySelectorAll('.collapsed').forEach(elem => { elem.classList.remove('collapsed'); elem.style.display = 'block'; }); ``` ### Add Copy Buttons to Code Blocks **Match Type:** Page contains element **Element Selector:** `pre code` **JavaScript Code:** ```javascript document.querySelectorAll('pre code').forEach(block => { const button = document.createElement('button'); button.textContent = 'Copy'; button.style.cssText = 'position:absolute;top:5px;right:5px;padding:5px 10px;cursor:pointer;'; button.onclick = () => { navigator.clipboard.writeText(block.textContent); button.textContent = 'Copied!'; setTimeout(() => button.textContent = 'Copy', 2000); }; block.parentElement.style.position = 'relative'; block.parentElement.appendChild(button); }); ``` ### Enhance Tables **Match Type:** Page contains element **Element Selector:** `table` **CSS Code:** ```css table { border-collapse: collapse !important; width: 100% !important; margin: 20px 0 !important; } table th { background-color: #4CAF50 !important; color: white !important; padding: 12px !important; text-align: left !important; } table td { padding: 10px !important; border-bottom: 1px solid #ddd !important; } table tr:hover { background-color: #f5f5f5 !important; } ``` --- ## Content Blocking ### Hide Advertisements **Match Type:** URL contains string **URL Pattern:** (target site) **CSS Code:** ```css .ad, .ads, .advertisement, [class*="ad-"], [id*="ad-"], .sponsored, .promotion { display: none !important; } ``` ### Remove Cookie Notices **Match Type:** URL contains string **URL Pattern:** (any site) **CSS Code:** ```css [class*="cookie"], [id*="cookie"], [class*="consent"], [id*="gdpr"], .privacy-banner { display: none !important; } ``` ### Hide Social Media Widgets **Match Type:** URL contains string **URL Pattern:** (target site) **CSS Code:** ```css .social-share, .share-buttons, [class*="social-"], iframe[src*="facebook"], iframe[src*="twitter"] { display: none !important; } ``` ### Remove Popups **Match Type:** URL contains string **URL Pattern:** (target site) **JavaScript Code:** ```javascript // Remove overlay popups document.querySelectorAll('.popup, .modal, .overlay').forEach(el => { el.remove(); }); // Re-enable scrolling document.body.style.overflow = 'auto'; document.documentElement.style.overflow = 'auto'; ``` --- ## Automation ### Auto-Close Annoying Popups **Match Type:** Page contains element **Element Selector:** `.modal` **JavaScript Code:** ```javascript setTimeout(() => { const closeButton = document.querySelector('.modal .close, .modal [aria-label="Close"]'); if (closeButton) { closeButton.click(); console.log('Popup auto-closed'); } }, 2000); ``` ### Auto-Accept Cookies **Match Type:** Page contains element **Element Selector:** `[class*="cookie"]` **JavaScript Code:** ```javascript const acceptButton = document.querySelector( 'button[id*="accept"], button[class*="accept"], .cookie-accept, #acceptCookies' ); if (acceptButton) { acceptButton.click(); console.log('Cookies auto-accepted'); } ``` ### Auto-Fill Test Form **Match Type:** Both URL and element **URL Pattern:** `test-form.html` **Element Selector:** `#myForm` **JavaScript Code:** ```javascript document.getElementById('username').value = 'testuser'; document.getElementById('email').value = 'test@example.com'; console.log('Form auto-filled'); ``` ### Skip Video Ads **Match Type:** Page contains element **Element Selector:** `.video-player` **JavaScript Code:** ```javascript setInterval(() => { const skipButton = document.querySelector('.skip-ad, .ytp-ad-skip-button'); if (skipButton && skipButton.offsetParent !== null) { skipButton.click(); console.log('Ad skipped'); } }, 1000); ``` --- ## Custom Features ### Add Floating Note Pad **Match Type:** URL contains string **URL Pattern:** (any site where you want notes) **JavaScript Code:** ```javascript const notepad = document.createElement('div'); notepad.innerHTML = `