Pearltrees Copy text button

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

23.11.2024 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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();
    };



})();