Hypothesis导出为markdown文件

导出Hypothesis高亮和注释为markdown文件

目前为 2023-02-25 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Hypothesis导出为markdown文件
  3. // @namespace https://coycs.com/
  4. // @version 1.0.0
  5. // @description 导出Hypothesis高亮和注释为markdown文件
  6. // @author coycs
  7. // @match *://hypothes.is/users/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11. (function () {
  12. "use strict";
  13. window.onload = function () {
  14. // 添加全部导出按钮
  15. let exportAllBtn = document.createElement("span");
  16. exportAllBtn.textContent = "导出全部";
  17. exportAllBtn.style.cssText = "margin-left: 8px;font-weight: bold;cursor: pointer;";
  18. document.querySelector(".search-results__total").appendChild(exportAllBtn);
  19. exportAllBtn.addEventListener("click", function () {
  20. let exportBtns = document.querySelectorAll("#exportBtn");
  21. exportBtns.forEach(n => {
  22. n.click();
  23. });
  24. });
  25. // 添加导出按钮
  26. const listitems = document.querySelectorAll('li[role="listitem"]');
  27. listitems.forEach(function (e) {
  28. e.style.cssText = "display: flex;";
  29. let bucket = e.querySelector(".search-result-bucket.js-search-bucket");
  30. bucket.style.cssText = "flex: 1;";
  31. let exportBtn = document.createElement("div");
  32. exportBtn.id = "exportBtn";
  33. exportBtn.textContent = "导出";
  34. exportBtn.style.cssText =
  35. "display: flex;align-items: center;justify-content: center;font-weight: bold;color: inherit;cursor: pointer;";
  36. let that = e;
  37. exportBtn.addEventListener("click", function () {
  38. ExportListItem(that);
  39. });
  40. e.appendChild(exportBtn);
  41. });
  42. };
  43. // 导出单个项目
  44. function ExportListItem(listitem) {
  45. const title = listitem.querySelector('a[data-ref="title"]').innerText;
  46. const url_a = listitem.querySelector(
  47. "div.search-bucket-stats__val.search-bucket-stats__url > a"
  48. );
  49. let outcome = new String();
  50. if (url_a) {
  51. const url = url_a.href;
  52. outcome = outcome.concat(`> 来自:${url}\n`);
  53. } else {
  54. outcome = outcome.concat("> 来自:本地文件\n");
  55. }
  56. const annotations = listitem.querySelectorAll("li.annotation-card");
  57. for (let i = annotations.length - 1; i > -1; i--) {
  58. const quote = annotations[i]
  59. .querySelector("blockquote.annotation-card__quote")
  60. .innerText.trim();
  61. const text = annotations[i].querySelector("div.annotation-card__text").innerText.trim();
  62. if (text) {
  63. outcome = outcome + "\n" + "> " + quote + "\n" + "\n" + text + "\n";
  64. } else {
  65. outcome = outcome + "\n" + "> " + quote + "\n";
  66. }
  67. }
  68. // 导出为markdown文件
  69. let blob = new Blob([outcome], { type: "application/md" });
  70. let aTag = document.createElement("a");
  71. aTag.download = title + ".md";
  72. aTag.href = URL.createObjectURL(blob);
  73. aTag.click();
  74. URL.revokeObjectURL(blob);
  75. }
  76. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址