TC4Shell.com - Add Download Buttons for 7-Zip Plugins page

Add download buttons to TC4Shell.com's 7-Zip plugins listing page, so one may download from the listing page directly, without opening plugin's page.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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           TC4Shell.com - Add Download Buttons for 7-Zip Plugins page
// @name:ru        TC4Shell.com - Добавьте кнопки загрузки для cтраница плагинов архиватора 7-Zip
// @description    Add download buttons to TC4Shell.com's 7-Zip plugins listing page, so one may download from the listing page directly, without opening plugin's page.
// @description:ru Добавьте кнопки загрузки на страницу списка плагинов 7-Zip TC4Shell.com, чтобы можно было загружать напрямую со страницы списка, не открывая страницу плагина.
// @namespace      RainSlide
// @author         RainSlide
// @match          *://www.tc4shell.com/en/7zip/
// @match          *://www.tc4shell.com/ru/7zip/
// @version        1.2
// @license        blessing
// @grant          none
// ==/UserScript==

const links = document.querySelectorAll('#content a');

if (links.length > 0) {

// const pageURL = location.origin + location.pathname;
const pageURL = new URL("./", location).href;

const match = (x, arr) => arr.some( y => y === x );

const plugins = Array.from(links).filter(
	plugin => (
		plugin.href.replace(/[^/]+\/$/, "") === pageURL &&
		match(plugin.parentNode.tagName, ["H2", "P"])
	)
);

if (plugins.length > 0) {

document.head.appendChild(document.createElement("style")).textContent =
`#content h1 ~ div > h2 { display: flex; justify-content: space-between; }
.button_download_small { height: 2em; line-height: 1; padding: .5em;
	font-family: inherit; font-size: .75em; background-color: #e84c3d; }
.button_download_small:hover { background-color: #ff605f; }`;

plugins.forEach(
	plugin => {

		const pluginName = plugin.textContent.split(" ", 1)[0];

		const fileName = match(pluginName, ["Asar7z", "Lzip7z"])
			? pluginName.replace(/7z$/, "")
			: pluginName;

		const i18nMap = new Map([["en", "Download"], ["ru", "Скачать"]]);

		const download = Object.assign(
			document.createElement("a"), {
				href: "/binary/" + fileName + ".zip",
				download: "",
				textContent: i18nMap.get(location.pathname.slice(1, 3)) || "Download"
			}
		);

		switch (plugin.parentNode.tagName) {
			case "H2":
				download.className = "button button_download_small";
				plugin.after(download);
				break;
			case "P":
				plugin.after(" (", download, ")");
				break;
		}

	}
);

}

}