Skip to content

Instantly share code, notes, and snippets.

@hidao80
Last active March 9, 2023 22:13
Show Gist options
  • Save hidao80/f45c3c0f6b7b9bead0b01cd7e3d3314a to your computer and use it in GitHub Desktop.
Save hidao80/f45c3c0f6b7b9bead0b01cd7e3d3314a to your computer and use it in GitHub Desktop.
Blur text in Misskey v11 and Mastodon.
javascript:(()%3D%3E%7Bconst%20KEY%3D%22FediverseTextBlur_bookmarklet_cssRules_indexes%22%2Cstyles%3D%5B%22article%20.havbbuyv%2C%5Cnarticle%20.status__content%2C%5Cnarticle%20.display-name%20%7B%5Cnfilter%3A%20blur(5px)%3B%5Cn%7D%22%5D%3Blet%20indexes%3DJSON.parse(localStorage.getItem(KEY)%7C%7C%22%5B%5D%22)%3Bconst%20usableSheet%3D%5B...document.styleSheets%5D.slice(-1)%5B0%5D%3Bif(indexes.length%3E0)%7Bfor(const%20e%20of%20indexes)usableSheet.deleteRule(e)%3BlocalStorage.setItem(KEY%2C%22%5B%5D%22)%7Delse%7Bconst%20e%3DusableSheet.cssRules.length%3Bfor(let%20s%20of%20styles)indexes.push(e)%2CusableSheet.insertRule(s%2Ce)%3BlocalStorage.setItem(KEY%2CJSON.stringify(indexes))%7D%7D)()
// @name Fediverse text blur
// @description Blur text in Misskey v11 and Mastodon.
// @author hidao80
// @version 1.0
// @license MIT
const SCRIPT_NAME = 'FediverseTextBlur_bookmarklet';
const styles = [
`article .havbbuyv,
article .status__content,
article .display-name {
filter: blur(5px);
}`,
];
let indexes = JSON.parse(localStorage.getItem(SCRIPT_NAME + '_cssRules_indexes') || '[]');
DEBUG && console.debug(`[${SCRIPT_NAME}]: init indexes:`);
DEBUG && console.debug(indexes);
// Style is a later winner, so send and add
const usableSheet = [...document.styleSheets].slice(-1)[0];
if (indexes.length > 0) {
for (const index of indexes) {
usableSheet.deleteRule(index);
}
localStorage.setItem(SCRIPT_NAME + '_cssRules_indexes', '[]');
DEBUG && console.debug(`[${SCRIPT_NAME}]: styles deleted.`);
} else {
const index = usableSheet.cssRules.length;
for (let style of styles) {
indexes.push(index);
usableSheet.insertRule(style, index);
}
localStorage.setItem(SCRIPT_NAME + '_cssRules_indexes', JSON.stringify(indexes));
DEBUG && console.debug(`[${SCRIPT_NAME}]: styles added.`);
DEBUG && console.debug(indexes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment