Pearltrees Copy text button

Tampermonkey script to add a copy button to pearltrees 'notes'.

目前為 2024-11-23 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Pearltrees Copy text button
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-11-14
  5. // @description Tampermonkey script to add a copy button to pearltrees 'notes'.
  6. // @author You
  7. // @match https://www.pearltrees.com/*
  8. // @license GNU GPLv3
  9. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  10. // @grant none
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14.  
  15. let styleSheet = `
  16. .copyBtn {
  17. padding:0;
  18. margin:0;
  19. font-size: 15px;
  20. background:rgb(0,0,0,.65);
  21. color:rgb(255,255,255);
  22. border-radius:50%;
  23. border-color:rgb(0,0,0,.65);
  24. width:20px;
  25. height:20px;
  26. }
  27. `;
  28. let s = document.createElement('style');
  29. s.type = "text/css";
  30. s.innerHTML = styleSheet;
  31. (document.head || document.documentElement).appendChild(s);
  32.  
  33. var flag = false ;
  34. var output = " ";
  35. var previousOutput = null;
  36.  
  37. var previousButtonContainer = null;
  38. var previousContainer = null;
  39. var pElements = null;
  40. var previousPElements = null;
  41. var previousPElementsId = null;
  42. var vraiContainer="";
  43. let JSP = 1;
  44. var previousVraiContainerId = "";
  45.  
  46.  
  47. function checkParagraphCount() {
  48. const container = document.getElementsByClassName('scrap-selection-container');
  49. // console.log("container.length : " + container.length + " || flag : "+flag + "|| JSP : " + JSP)
  50.  
  51. if(container.length!==0 && flag === true ){
  52.  
  53. for(let i=0; i<container.length;i++) {
  54. vraiContainer = container[i];
  55. // console.log("vraiContainer.id = " + vraiContainer.id + "// previousVraiContainerId = "+ previousVraiContainerId )
  56. if (vraiContainer.id != previousVraiContainerId ){
  57. // console.log("ALORSPEUTETRE")
  58. break
  59. }
  60. }
  61.  
  62. pElements = vraiContainer.querySelectorAll('p');
  63. if (pElements.length == 0) return // console.log("ABORT THE MISSION" + vraiContainer.id)
  64.  
  65. vraiContainer.style.borderRadius = "15px";
  66. vraiContainer.style.transition = ".7s"
  67. vraiContainer.title = "click to copy"
  68. vraiContainer.onclick = function() {
  69. navigator.clipboard.writeText(output);
  70. alert('Text Copied Successfully!')
  71. }
  72. vraiContainer.onmouseover = function() {vraiContainer.style.background = "rgb(240, 240, 240)"}
  73. vraiContainer.onmouseout = function() {vraiContainer.style.background = "rgb(255,255,255)"}
  74.  
  75. // console.log("1er if passe")
  76. vraiContainer.id = JSP;
  77. previousVraiContainerId = JSP;
  78.  
  79. if (output != " ") previousOutput = output
  80. output = "";
  81.  
  82. for(let i=0; i<pElements.length;i++) {
  83. let outputToAdd = pElements[i].textContent
  84. output+= outputToAdd + '\n\n' ;
  85. }
  86.  
  87. pElements = null;
  88. flag = false;
  89. previousContainer=container;
  90. JSP += 1;
  91.  
  92. // console.log("OUTPUT\\\\\\\\\\\\ " +output + " \\\\\\\\\\\\OUTPUT")
  93. // output = "";
  94. // previousButtonContainer = buttonContainer;
  95. // console.log(pElements);
  96.  
  97. // console.log(pElementsId)
  98. // previousPElementsId = pElementsId;
  99. // console.log('FLAG = FALSE')
  100.  
  101. // console.log ( " JPS + = 1" )
  102. }
  103. }
  104.  
  105.  
  106. const observer2 = new MutationObserver(checkParagraphCount);
  107. observer2.observe(document.body, { childList: true, subtree: true });
  108. checkParagraphCount();
  109.  
  110. function checkUrl() {
  111. var path = window.location.pathname;
  112. var page = path.split("/").pop();
  113. var precedentPath = "";
  114. if(page.startsWith('item') && precedentPath!=path) {
  115. flag = true;
  116. // console.log('FLAG = TRUE')
  117. precedentPath=path;
  118. }
  119. }
  120.  
  121. checkUrl();
  122. window.addEventListener('popstate', checkUrl);
  123. const pushState = history.pushState;
  124. const replaceState = history.replaceState;
  125. history.pushState = function() {
  126. pushState.apply(history, arguments);
  127. checkUrl();
  128. };
  129. history.replaceState = function() {
  130. replaceState.apply(history, arguments);
  131. checkUrl();
  132. };
  133.  
  134.  
  135.  
  136. })();