Furaffinity Open Selected

Adds a button for open all selected submissiuns

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Furaffinity Open Selected
// @namespace    https://greatest.deepsurf.us/ru/users/303426-титан
// @version      1.3
// @description  Adds a button for open all selected submissiuns
// @author       Титан
// @match        https://www.furaffinity.net/msg/submissions/*
// @require      https://greatest.deepsurf.us/scripts/21927-arrive-js/code/arrivejs.js
// @icon         https://www.google.com/s2/favicons?sz=64&domain=furaffinity.net
// @grant        GM.setValue
// @grant        GM.getValue
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @license      MIT
// ==/UserScript==

(function() {
	'use strict';
	let openDelay; // increase timeout to get less often 503 error. Or set to 0 and install "503 reload" script
	let coloredButtons;
    const css = `
button[class="standard remove-checked"] {
	background-color:#ff000021
}
button[class="standard invert-selection"] {
	filter: invert(1) hue-rotate(180deg);
}
button[class="standard open-selected"] {
	background-color:#0803
}
`

	var arriveOptions = {
		fireOnAttributesModification: false,
		onceOnly: true,
		existing: true
	};

	document.arrive(".section-options.actions", arriveOptions, function (newElem) {CreateButton(newElem)});
	let menuCommand_ColoredButtons;
	let menuCommand_OpenDelay;
	RegisterMenuCommands().then(() => {
		ApplyColoredButtons();
	});
	

	async function RegisterMenuCommands() {
		coloredButtons = await GM.getValue('coloredButtons', true)
		openDelay = await GM.getValue('openDelay', 30);
		menuCommand_ColoredButtons = GM_registerMenuCommand( `Colored Buttons ${(coloredButtons? "✅":"❎")}`, async () => {
			coloredButtons = !coloredButtons;
			await GM.setValue('coloredButtons', coloredButtons);
			ApplyColoredButtons()
			ReInitializeMenuCommands();
		});
		menuCommand_OpenDelay = GM_registerMenuCommand( `Change Open Delay [${openDelay} ms]`, async () => {
			
			let delay = prompt("Set Open Delay (ms)", await openDelay);
			if (delay) {
				delay = parseInt(delay);
				if (isNaN(delay)) {
					alert("Invalid input. Please enter a valid number.");
					return;
				}
				openDelay = delay;
				await GM.setValue('openDelay', openDelay);
			}

			ReInitializeMenuCommands();
		});
	}

	function ApplyColoredButtons() {
		if (coloredButtons)
			ApplyCss();
		else
			RemoveCss();
	}

	function ReInitializeMenuCommands() {
		GM_unregisterMenuCommand(menuCommand_ColoredButtons);
		GM_unregisterMenuCommand(menuCommand_OpenDelay);
		RegisterMenuCommands();
	}

	function ApplyCss() {
		const style = document.createElement("style");
		style.textContent = css;
		style.id = "coloredButtons";
		document.head.appendChild(style);
	}
	function RemoveCss() {
		let style = document.getElementById("coloredButtons");
		if (style) {
			style.remove();
		}
	}

	openDelay = GM.getValue('openDelay', 30);

	

	function CreateButton(Panel) {
			let galleries = document.querySelectorAll(".gallery");
			if(galleries) {
				let newButton = document.createElement('button');
				newButton.classList.add('standard');
                newButton.classList.add('open-checked');
				newButton.setAttribute('type','button');
				newButton.onclick = function() {
					let i = 0;
					for(let gallery of galleries) {
						for (let figure of gallery.children) {
							if (figure.classList.contains('checked')) {
								setTimeout(function () {
									window.open(figure.firstElementChild.firstElementChild.firstElementChild.href)
								}, openDelay * i++);
							}
						}
					}
					window.focus();
				}
				newButton.append(document.createTextNode("Open Selected"));
				newButton.className = "standard open-selected";
				Panel.lastElementChild.previousSibling.previousSibling.before(newButton)
			}
	}


})();