复制 Notion 页面正文内容

Copy the Notion page's html content to clipboard.

当前为 2020-03-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Copy Notion Page Content
  3. // @name:zh-CN 复制 Notion 页面正文内容
  4. // @namespace http://www.notion.so/
  5. // @version 0.1
  6. // @description Copy the Notion page's html content to clipboard.
  7. // @description:zh-cn 复制 Notion 页面正文部分的 HTML 到剪贴板。
  8. // @author Ruter Lü
  9. // @match https://www.notion.so/*
  10. // @match https://notion.ruterly.com/*
  11. // @grant none
  12. // @run-at document-idle
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Helper function to wait for the element ready
  19. const waitFor = (...selectors) => new Promise(resolve => {
  20. const delay = 500;
  21. const f = () => {
  22. const elements = selectors.map(selector => document.querySelector(selector));
  23. if (elements.every(element => element != null)) {
  24. resolve(elements);
  25. } else {
  26. setTimeout(f, delay);
  27. }
  28. }
  29. f();
  30. });
  31. waitFor('div.notion-scroller .notion-record-icon').then(([iconEl]) => {
  32. console.log('Notion Page Loaded.');
  33. const disabled = iconEl.getAttribute('aria-disabled');
  34. if (disabled === 'true') {
  35. // Bind click event
  36. iconEl.addEventListener('click', event => {
  37. let content = document.querySelector('.notion-page-content');
  38. navigator.clipboard.writeText(content.outerHTML).then(function() {
  39. /* clipboard successfully set */
  40. console.log('Copy Notion Page Content Success.');
  41. }, function(e) {
  42. /* clipboard write failed */
  43. console.error(e);
  44. });
  45. });
  46. } else {
  47. return;
  48. }
  49. });
  50. })();