AnkiWeb: Download buttons for addons

Adds download buttons to addon pages on AnkiWeb.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        AnkiWeb: Download buttons for addons
// @namespace   flan
// @description Adds download buttons to addon pages on AnkiWeb.
// @include     https://ankiweb.net/shared/info/*
// @version     1
// @grant       none
// @license     https://unlicense.org/
// ==/UserScript==

function basename(path) {
	let s = path.split("/");
	return s[s.length-1];
}

function add_dl_button(after, version) {
	let a = document.createElement("a");
	a.href = `/shared/download/${basename(window.location.pathname)}?v=${version}`;
	a.className = "btn btn-primary btn-lg";
	a.style.marginRight = "1em";
	a.innerText = `Download (${version}.x)`;
	after.parentElement.insertBefore(a, after.nextSibling);
}

let id_card = document.querySelector(".card-outline-primary");

id_card.style.display = "inline-block";
id_card.style.marginRight = "1em";

if(document.querySelector("a[href='/shared/addons/2.1']"))
	add_dl_button(id_card, "2.1");

if(document.querySelector("a[href='/shared/addons/2.0']"))
	add_dl_button(id_card, "2.0");