Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create folder e621-extension, then put the following files inside it.
- // Go to chrome://extensions/ put yourself in developer mode (top right), then "Load Unpacked Extension"; the _folder_ you created is the extension.
- // manifest.json
- {
- "manifest_version": 3,
- "name": "e621 Blacklist Toggle",
- "version": "0.1",
- "content_scripts": [{
- "matches": ["https://e621.net/*", "https://e926.net/*"],
- "js": ["content-script.js"]
- }],
- "web_accessible_resources": [{
- "resources": ["e621.user.js"],
- "matches": ["https://e621.net/*", "https://e926.net/*"],
- "use_dynamic_url": true
- }]
- }
- // content-script.js
- // Credit: https://stackoverflow.com/a/9517879
- var s = document.createElement('script');
- s.src = chrome.runtime.getURL('e621.user.js');
- s.onload = function() {
- this.remove();
- };
- (document.head || document.documentElement).appendChild(s);
- // e621.user.js
- // ==UserScript==
- // @name Blacklist Toggle
- // @match https://e621.net/*
- // @match https://e926.net/*
- // ==/UserScript==
- (function() {
- function runWhenReady(run) {
- if (document.readyState != 'loading')
- run();
- else
- document.addEventListener('DOMContentLoaded', run);
- }
- runWhenReady(function() {
- function toggle(set, key) {
- set.delete(key) || set.add(key);
- }
- let off;
- function setOff(keys) {
- off = new Set(keys);
- off.forEach(key => {
- Danbooru.Blacklist.lineSet(key, false);
- })
- if (off.size)
- Danbooru.Blacklist.apply();
- }
- // Expire after six hours
- let expire = new Date(
- new Date(
- window.localStorage.getItem('blacklist_last')
- ).getTime()
- + 6 * 60 * 60 * 1000
- );
- if (expire < new Date())
- window.localStorage.removeItem('blacklist_off');
- setOff(JSON.parse(window.localStorage.getItem('blacklist_off')) || []);
- addEventListener('storage', e => {
- // wipe on Disable/Re-enable all blacklist entries
- if (e.key === 'dab') {
- window.localStorage.removeItem('blacklist_off');
- Danbooru.Blacklist.entries.forEach(entry => {
- entry.disabled = !!JSON.parse(e.newValue);
- })
- Danbooru.Blacklist.apply();
- return;
- }
- if (e.key !== 'blacklist_off')
- return;
- // re-enable all, then disable from local storage
- Danbooru.Blacklist.entries.forEach(entry => {
- entry.disabled = false;
- })
- setOff(JSON.parse(e.newValue) || []);
- });
- let lineToggle = Danbooru.Blacklist.lineToggle; // monkey patch it
- Danbooru.Blacklist.lineToggle = (t) => {
- lineToggle(t);
- window.localStorage.setItem('blacklist_last', new Date().toJSON());
- toggle(off, t);
- window.localStorage.setItem('blacklist_off', JSON.stringify(Array.from(off.keys())));
- };
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement