AnkiWeb: Download buttons for addons

Adds download buttons to addon pages on AnkiWeb.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==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");