AnkiWeb: Download buttons for addons

Adds download buttons to addon pages on AnkiWeb.

  1. // ==UserScript==
  2. // @name AnkiWeb: Download buttons for addons
  3. // @namespace flan
  4. // @description Adds download buttons to addon pages on AnkiWeb.
  5. // @include https://ankiweb.net/shared/info/*
  6. // @version 1
  7. // @grant none
  8. // @license https://unlicense.org/
  9. // ==/UserScript==
  10.  
  11. function basename(path) {
  12. let s = path.split("/");
  13. return s[s.length-1];
  14. }
  15.  
  16. function add_dl_button(after, version) {
  17. let a = document.createElement("a");
  18. a.href = `/shared/download/${basename(window.location.pathname)}?v=${version}`;
  19. a.className = "btn btn-primary btn-lg";
  20. a.style.marginRight = "1em";
  21. a.innerText = `Download (${version}.x)`;
  22. after.parentElement.insertBefore(a, after.nextSibling);
  23. }
  24.  
  25. let id_card = document.querySelector(".card-outline-primary");
  26.  
  27. id_card.style.display = "inline-block";
  28. id_card.style.marginRight = "1em";
  29.  
  30. if(document.querySelector("a[href='/shared/addons/2.1']"))
  31. add_dl_button(id_card, "2.1");
  32.  
  33. if(document.querySelector("a[href='/shared/addons/2.0']"))
  34. add_dl_button(id_card, "2.0");