Add Download Button to TC4Shell.com 7-Zip Plugins Page

So you no longer needs to click into every updated plugin for the download links.

2021-04-10 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        Add Download Button to TC4Shell.com 7-Zip Plugins Page
// @description So you no longer needs to click into every updated plugin for the download links.
// @namespace   RainSlide
// @author      RainSlide
// @match       *://www.tc4shell.com/en/7zip/
// @match       *://www.tc4shell.com/ru/7zip/
// @version     1.1
// @grant       none
// ==/UserScript==

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

if (plugins.length > 0) {

document.head.appendChild(
	Object.assign(
		document.createElement("style"), {
			textContent: `
#content h1 ~ div > h2 {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
}

.button_download_small {
	padding: .5em;
	height: 2em;
	line-height: 1;
	font-family: inherit;
	font-size: smaller;
	background-color: #e84c3d;
}
.button_download_small:hover {
	background-color: #ff605f;
}
`.trim()
		}
	)
);

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

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

plugins.forEach(
	plugin => {

		const parent = plugin.parentNode;

		if (
			plugin.href.replace(/[^/]+\/$/, "") === pageURL &&
			match(parent.tagName, ["H2", "P"])
		) {

			let filename = plugin.textContent.split(" ", 1)[0];

			const href = "/binary/" + (
				match(parent.tagName, ["Asar7z", "Lzip7z"])
					? filename.replace(/7z$/, "")
					: filename
			) + ".zip";

			const download = Object.assign(
				document.createElement("a"), {
					href, download: "", textContent: "Download"
				}
			);

			if (parent.tagName === "H2") {
				download.className = "button button_download_small";
				plugin.after(download);
			} else if (parent.tagName === "P") {
				plugin.after(" (", download, ")");
			}

		}

	}
);

}