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 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Add Download Button to TC4Shell.com 7-Zip Plugins Page
  3. // @description So you no longer needs to click into every updated plugin for the download links.
  4. // @namespace RainSlide
  5. // @author RainSlide
  6. // @match *://www.tc4shell.com/en/7zip/
  7. // @match *://www.tc4shell.com/ru/7zip/
  8. // @version 1.1
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. const plugins = document.querySelectorAll('#content a');
  13.  
  14. if (plugins.length > 0) {
  15.  
  16. document.head.appendChild(
  17. Object.assign(
  18. document.createElement("style"), {
  19. textContent: `
  20. #content h1 ~ div > h2 {
  21. display: flex;
  22. flex-direction: row;
  23. justify-content: space-between;
  24. align-items: center;
  25. }
  26.  
  27. .button_download_small {
  28. padding: .5em;
  29. height: 2em;
  30. line-height: 1;
  31. font-family: inherit;
  32. font-size: smaller;
  33. background-color: #e84c3d;
  34. }
  35. .button_download_small:hover {
  36. background-color: #ff605f;
  37. }
  38. `.trim()
  39. }
  40. )
  41. );
  42.  
  43. // const pageURL = location.origin + location.pathname;
  44. const pageURL = new URL("./", location).href;
  45.  
  46. const match = (x, arr) => arr.some( y => y === x );
  47.  
  48. plugins.forEach(
  49. plugin => {
  50.  
  51. const parent = plugin.parentNode;
  52.  
  53. if (
  54. plugin.href.replace(/[^/]+\/$/, "") === pageURL &&
  55. match(parent.tagName, ["H2", "P"])
  56. ) {
  57.  
  58. let filename = plugin.textContent.split(" ", 1)[0];
  59.  
  60. const href = "/binary/" + (
  61. match(parent.tagName, ["Asar7z", "Lzip7z"])
  62. ? filename.replace(/7z$/, "")
  63. : filename
  64. ) + ".zip";
  65.  
  66. const download = Object.assign(
  67. document.createElement("a"), {
  68. href, download: "", textContent: "Download"
  69. }
  70. );
  71.  
  72. if (parent.tagName === "H2") {
  73. download.className = "button button_download_small";
  74. plugin.after(download);
  75. } else if (parent.tagName === "P") {
  76. plugin.after(" (", download, ")");
  77. }
  78.  
  79. }
  80.  
  81. }
  82. );
  83.  
  84. }