Skip to content

Instantly share code, notes, and snippets.

@JonathanGawrych
Created December 19, 2023 07:20
Show Gist options
  • Save JonathanGawrych/9c4e695c0730b1bd54b898929824a8e8 to your computer and use it in GitHub Desktop.
Save JonathanGawrych/9c4e695c0730b1bd54b898929824a8e8 to your computer and use it in GitHub Desktop.
Userscript to add toggle buttons to FA posts.
// ==UserScript==
// @name Hide FA
// @namespace http://tampermonkey.net/
// @version 2023-12-19
// @description try to take over the world!
// @author You
// @match https://www.furaffinity.net/search/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=furaffinity.net
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function() {
'use strict';
const head = document.getElementsByTagName('head')[0];
const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = `
.hide-img { height: auto !important; }
.hide-img b { display: none !important; }
.small-btn { font-size: 10px !important; line-height: 14px; padding: 0 5px; margin: 0 5px; }
`;
head.appendChild(style);
const toHide = new Set(JSON.parse(GM_getValue('toHide', JSON.stringify([]))));
const updateHidden = () => {
Array.from(document.querySelectorAll('figure')).forEach(
e => e.classList.toggle('hide-img', toHide.has(e.id))
);
};
updateHidden();
const saveHide = () => {
GM_setValue('toHide', JSON.stringify([...toHide]));
updateHidden();
};
const toggleAll = () => {
const shouldHide = !toHide.has(document.querySelector('figure').id);
Array.from(document.querySelectorAll('figure')).forEach(
e => toHide[shouldHide ? 'add' : 'delete'](e.id)
);
saveHide();
};
const toggleOne = (e) => {
const shouldHide = !toHide.has(e.id);
toHide[shouldHide ? 'add' : 'delete'](e.id);
saveHide();
};
const toggleAllButton = document.createElement('button');
toggleAllButton.textContent = 'Toggle all';
toggleAllButton.addEventListener('click', toggleAll);
toggleAllButton.setAttribute('type', 'button');
document.querySelector('.gallery-section .section-header').appendChild(toggleAllButton);
Array.from(document.querySelectorAll('figure')).forEach(e => {
const toggleOneButton = document.createElement('button');
toggleOneButton.textContent = 'T';
toggleOneButton.classList.add('small-btn');
toggleOneButton.addEventListener('click', () => toggleOne(e));
toggleOneButton.setAttribute('type', 'button');
e.querySelector('figcaption p').prepend(toggleOneButton);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment