Pearltrees Copy text button

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Pearltrees Copy text button
// @namespace    http://tampermonkey.net/
// @version      2024-11-14
// @description  Tampermonkey script to add a copy button to pearltrees 'notes'.
// @author       You
// @match        https://www.pearltrees.com/*
// @license      GNU GPLv3
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    let styleSheet = `
.copyBtn {
    padding:0;
    margin:0;
    font-size: 15px;
    background:rgb(0,0,0,.65);
    color:rgb(255,255,255);
    border-radius:50%;
    border-color:rgb(0,0,0,.65);
    width:20px;
    height:20px;
}
`;
    let s = document.createElement('style');
    s.type = "text/css";
    s.innerHTML = styleSheet;
    (document.head || document.documentElement).appendChild(s);

    var flag = false ;
    var output = " ";
    var previousOutput = null;

    var previousButtonContainer = null;
    var previousContainer = null;
    var pElements = null;
    var previousPElements = null;
    var previousPElementsId = null;
    var vraiContainer="";
    let JSP = 1;
    var previousVraiContainerId = "";


    function checkParagraphCount() {
        const container = document.getElementsByClassName('scrap-selection-container');
        // console.log("container.length : " + container.length + " || flag : "+flag + "|| JSP : " + JSP)

        if(container.length!==0 && flag === true ){

            for(let i=0; i<container.length;i++) {
                  vraiContainer = container[i];
              //  console.log("vraiContainer.id = " + vraiContainer.id + "// previousVraiContainerId = "+ previousVraiContainerId )
                if (vraiContainer.id != previousVraiContainerId ){
                    // console.log("ALORSPEUTETRE")
                    break
                }
            }

            pElements = vraiContainer.querySelectorAll('p');
            if (pElements.length == 0) return // console.log("ABORT THE MISSION" + vraiContainer.id)

            vraiContainer.style.borderRadius = "15px";
            vraiContainer.style.transition = ".7s"
            vraiContainer.title = "click to copy"
            vraiContainer.onclick = function() {
                navigator.clipboard.writeText(output);
                alert('Text Copied Successfully!')
            }
            vraiContainer.onmouseover = function() {vraiContainer.style.background = "rgb(240, 240, 240)"}
            vraiContainer.onmouseout = function() {vraiContainer.style.background = "rgb(255,255,255)"}

            // console.log("1er if passe")
            vraiContainer.id = JSP;
            previousVraiContainerId = JSP;

            if (output != " ") previousOutput = output
            output = "";

            for(let i=0; i<pElements.length;i++) {
                let outputToAdd = pElements[i].textContent
                output+= outputToAdd + '\n\n' ;
            }

            pElements = null;
            flag = false;
            previousContainer=container;
            JSP += 1;

            // console.log("OUTPUT\\\\\\\\\\\\      " +output + "    \\\\\\\\\\\\OUTPUT")
            // output = "";
            // previousButtonContainer = buttonContainer;
            // console.log(pElements);

            // console.log(pElementsId)
            // previousPElementsId = pElementsId;
            // console.log('FLAG = FALSE')

            // console.log ( " JPS + = 1" )
        }
    }


    const observer2 = new MutationObserver(checkParagraphCount);
    observer2.observe(document.body, { childList: true, subtree: true });
    checkParagraphCount();

    function checkUrl() {
        var path = window.location.pathname;
        var page = path.split("/").pop();
        var precedentPath = "";
        if(page.startsWith('item') && precedentPath!=path) {
            flag = true;
            // console.log('FLAG = TRUE')
            precedentPath=path;
        }
    }

    checkUrl();
    window.addEventListener('popstate', checkUrl);
    const pushState = history.pushState;
    const replaceState = history.replaceState;
    history.pushState = function() {
        pushState.apply(history, arguments);
        checkUrl();
    };
    history.replaceState = function() {
        replaceState.apply(history, arguments);
        checkUrl();
    };



})();