Zotero Plugins Install/Update

自动检查更新Zotero插件

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

  1. // ==UserScript==
  2. // @name Zotero Plugins Install/Update
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 自动检查更新Zotero插件
  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.  
  17. // zotero://plugin/?action=install&url=https%3A%2F%2Fgithub.com%2Fvolatile-static%2FChartero%2Freleases%2Fdownload%2F2.0.0%2Fchartero.xpi
  18. setTimeout(() => {
  19. GM_xmlhttpRequest({
  20. method: "POST",
  21. url: "http://127.0.0.1:23119/getAllPluginVersion",
  22. headers: {
  23. "Content-Type": "application/json",
  24. },
  25. responseType: "json",
  26. onload: function (res) {
  27. const addons = res.response;
  28. console.log(addons);
  29. [...document.querySelectorAll("tr td")]
  30. .filter(i => i.innerText == "7")
  31. .forEach(td => {
  32. const a = td.parentNode.children[0].querySelector("a") || td.parentNode.previousElementSibling.children[0].querySelector("a")
  33. const homepageURL = a.getAttribute("href")
  34. const addon = addons.find(addon => addon.homepageURL.toLowerCase() == homepageURL.toLowerCase())
  35. const aArr = [...td.parentNode.children].slice(-1)[0].querySelectorAll("a")
  36. if (addon) {
  37. const version = td.nextElementSibling.innerText
  38. console.log(addon.id, "最新版本", version, "安装版本", addon.version)
  39. if (version.replace(/^v/, "") > addon.version.replace(/^v/, "")) {
  40. aArr.forEach(a => {
  41. const href = a.getAttribute("href")
  42. a.innerText = `从${a.innerText}更新`;
  43. a.style.color="deeppink"
  44. a.setAttribute("href", `zotero://plugin/?action=install&url=${encodeURIComponent(href)}`)
  45. })
  46. } else {
  47. [...td.parentNode.children].slice(-1)[0].innerText = "已安装"
  48. }
  49. } else {
  50. aArr.forEach(a => {
  51. const href = a.getAttribute("href")
  52. a.innerText = `从${a.innerText}安装`;
  53. a.setAttribute("href", `zotero://plugin/?action=install&url=${encodeURIComponent(href)}`)
  54. })
  55. }
  56. })
  57.  
  58. }
  59. })
  60. }, 1000)
  61.  
  62. })();