Last active
April 1, 2024 23:07
-
-
Save ultimateshadsform/1e9206f372af40ec2f48f88e20a93e51 to your computer and use it in GitHub Desktop.
This file contains 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 Auto Click "Boop" Spans and "Boop" Button | |
// @namespace tampermonkey.net | |
// @version 1.0 | |
// @description Automatically clicks on spans containing text "Boop" and buttons with aria-label="boop" when they come into view during scrolling | |
// @author You | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Function to handle clicking on elements | |
function clickElement(element) { | |
if (element) { | |
element.click(); | |
} | |
} | |
// Function to handle intersection observer for "Boop" spans | |
function handleSpanIntersection(entries, observer) { | |
entries.forEach(entry => { | |
if (entry.isIntersecting && entry.target.textContent.trim() === 'Boop') { | |
clickElement(entry.target.parentElement); | |
} | |
}); | |
} | |
// Create a new IntersectionObserver to watch for "Boop" spans coming into view | |
const spanObserver = new IntersectionObserver(handleSpanIntersection, { threshold: 0.5 }); | |
// Function to observe "Boop" spans | |
function observeBoopSpans() { | |
document.querySelectorAll('span').forEach(span => { | |
if (span.textContent.trim() === 'Boop' && !span.__observed) { | |
spanObserver.observe(span); | |
span.__observed = true; // Mark the span as observed to avoid duplicate observation | |
} | |
}); | |
} | |
// Function to handle intersection observer for "Boop" buttons | |
function handleButtonIntersection(entries, observer) { | |
entries.forEach(entry => { | |
if (entry.isIntersecting && entry.target.getAttribute('aria-label') === 'boop') { | |
clickElement(entry.target); | |
} | |
}); | |
} | |
// Create a new IntersectionObserver to watch for "Boop" buttons coming into view | |
const buttonObserver = new IntersectionObserver(handleButtonIntersection, { threshold: 0.5 }); | |
// Function to observe "Boop" buttons | |
function observeBoopButtons() { | |
document.querySelectorAll('button[aria-label="boop"]').forEach(button => { | |
if (!button.__observed) { | |
buttonObserver.observe(button); | |
button.__observed = true; // Mark the button as observed to avoid duplicate observation | |
} | |
}); | |
} | |
// Function to run on scroll | |
function runScriptOnScroll() { | |
if (window.scrollY >= 500) { | |
// Click on buttons with aria-label="boop" | |
observeBoopButtons(); | |
// Observe new "Boop" spans as they come into view during scrolling | |
observeBoopSpans(); | |
} | |
} | |
// Run the script when the page is loaded | |
observeBoopSpans(); | |
// Run the script when the page is scrolled | |
window.addEventListener('scroll', runScriptOnScroll); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment