Zotero Plugins Install/Update

Zotero Plugins

当前为 2023-10-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Zotero Plugins Install/Update
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Zotero Plugins
  6. // @author Polygon
  7. // @match https://plugins.zotero-chinese.com/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=zotero-chinese.com
  9. // @grant GM_xmlhttpRequest
  10. // @grant unsafeWindow
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16. // zotero://plugin/?action=install&url=https%3A%2F%2Fgithub.com%2Fvolatile-static%2FChartero%2Freleases%2Fdownload%2F2.0.0%2Fchartero.xpi
  17. const id = setInterval(() => {
  18. if (!document.querySelector("table")) {
  19. return
  20. }
  21. clearInterval(id)
  22. GM_xmlhttpRequest({
  23. method: "POST",
  24. url: "http://127.0.0.1:23119/getAllPluginVersion",
  25. headers: {
  26. "Content-Type": "application/json",
  27. },
  28. responseType: "json",
  29. onload: function (res) {
  30. const addons = res.response;
  31. main(addons)
  32. }
  33. })
  34.  
  35. }, 10)
  36. const main = (addons) => {
  37. [...document.querySelectorAll("tr td")]
  38. .filter(i => i.innerText == "7")
  39. .forEach(td => {
  40. const a = td.parentNode.children[0].querySelector("a") || td.parentNode.previousElementSibling.children[0].querySelector("a")
  41. const homepageURL = a.getAttribute("href")
  42. const addon = addons.find(addon => addon.homepageURL.toLowerCase() == homepageURL.toLowerCase())
  43. const sourceNode = [...td.parentNode.children].slice(-1)[0]
  44. const sourceAtags = sourceNode.querySelectorAll("a")
  45. sourceAtags.forEach(a => {
  46. const href = a.getAttribute("href")
  47. a.innerText = `从${a.innerText}安装`;
  48. sourceNode.style.backgroundColor = "rgba(66, 185, 131, .2)"
  49. a.setAttribute("href", `zotero://plugin/?action=install&url=${encodeURIComponent(href)}`)
  50. a.style.color = "#42b983"
  51. })
  52. if (addon) {
  53. const version = td.nextElementSibling.innerText
  54. console.log(addon.id, "最新版本", version, "安装版本", addon.version)
  55. if (version.replace(/^v/, "") > addon.version.replace(/^v/, "")) {
  56. sourceAtags.forEach(a => {
  57. const href = a.getAttribute("href")
  58. a.innerText = a.innerText.replace("安装", "更新")
  59. sourceNode.style.backgroundColor = "#42b983"
  60. a.style.color = "white"
  61. a.setAttribute("href", `zotero://plugin/?action=install&url=${encodeURIComponent(href)}`)
  62. })
  63. } else {
  64. sourceNode.style.backgroundColor = "#42b983"
  65. sourceNode.innerHTML = `<span style="font-weight: bold; color: white;">⭐已安装</span>`;
  66. }
  67. }
  68. })
  69. }
  70.  
  71. })();