Created
June 1, 2024 01:49
-
-
Save hazushi3/3c995294eeb7baff6694a29f9d457e83 to your computer and use it in GitHub Desktop.
Redgifs Blacklist + quality of life
This file contains hidden or 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 Redgifs Blacklist + QOL | |
// @namespace https://gist.github.com/hazushi3 | |
// @version 1.0 | |
// @description Hide posts containing specific tags with wildcard support, automatically unmutes and mutes on hidden videos. Some love from chatGPT. | |
// @author hazushi3 | |
// @match https://www.redgifs.com/* | |
// @exclude https://www.redgifs.com/watch/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const blacklist = ["*dick*", "male*", "CBT", "BDSM"]; //example tags, it's not case senstive, use * for wildcard | |
const regexPatterns = blacklist.map(pattern => new RegExp(`^${pattern.replace(/\*/g, ".*")}$`, "i")); //support wildcard | |
function checkAndHidePosts() { | |
const parentDivs = document.querySelectorAll('.GifPreview');//find all posts | |
parentDivs.forEach(parentDiv => { //loop through all divs from above | |
const tags = parentDiv.querySelectorAll('.tagButton .text'); //look for divs containg tags | |
const tagTexts = new Set(); | |
tags.forEach(tag => { //look through all divs and add them to array tagTexts | |
tagTexts.add(tag.textContent.trim().toLowerCase()); | |
}); | |
const anyTagPresent = regexPatterns.some(regex => { // check does any of the tag appears in tagsTexts | |
return [...tagTexts].some(tag => regex.test(tag)); | |
}); | |
if (anyTagPresent && parentDiv.classList.contains('GifPreview_isActive') && (parentDiv.children[3].firstChild.children[2].firstChild.ariaLabel == "Sound On")){ //if post contains blacklisted tags and is currenlty shown and is the sound on | |
document.getElementsByClassName("SoundButton")[0].click() //clicks the sound button to turn it off | |
} | |
if ((!parentDiv.parsed) && parentDiv.classList.contains('GifPreview_isActive') && (parentDiv.children[3].firstChild.children[2].firstChild.ariaLabel == "Sound Off")){ //check is the post not parsed and is it currently show and is the sound off | |
document.getElementsByClassName("SoundButton")[0].click() //clicks it to unmute sound | |
} | |
if (anyTagPresent && (!parentDiv.parsed)) { | |
parentDiv.parsed = true //mark a post as already done, this way it will not spam it nonstop | |
parentDiv.children[1].firstChild.style.display = "none" //hideo video | |
parentDiv.children[1].firstChild.children[1].remove() //remove video, one of these two is prob not needed but if it works it works and icbb to check it | |
let img = parentDiv.children[0].children[0]; // find background images | |
let anchor = document.createElement("a"); // create <a> tag | |
anchor.href = `https://www.redgifs.com/watch/${parentDiv.id.substring(4)}` //make <a> tag clickable | |
let image = img.cloneNode(true) //clones original background image | |
anchor.appendChild(image) //appends background to immage | |
anchor.target = "_blank"; //makes URL open in new tab | |
img.parentNode.replaceChild(anchor, img) //replace background image with clickable background image | |
} | |
}); | |
} | |
window.addEventListener('load', checkAndHidePosts); | |
setInterval(checkAndHidePosts, 20); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment