Copy todoist task comments to clipboard latest version (currently v1.0.2)

← Back to User Scripts

Script Content

// ==UserScript==
// @name         Todoist: Copy Task Comments
// @namespace    https://www.timhilton.xyz/user-scripts
// @version      1.0.2
// @description  Adds a button for copying todoist task comments to clipboard
// @author       Tim Hilton
// @match        https://app.todoist.com/app/task/*
// @grant        GM_setClipboard
// ==/UserScript==

(function() {
    'use strict';

    const LOG_PREFIX = '[Todoist: Copy Task Comments]';
    
    console.debug(`${LOG_PREFIX} Script initialized`);

    // Create a new button
    let button = document.createElement('button');
    button.textContent = 'Copy all comments';
    button.style.border = '2px solid white';
    button.style.width = '22px';
    button.style.height = '22px';

    // Add a click event listener to the button
    button.addEventListener('click', function() {
        console.debug(`${LOG_PREFIX} Button click event triggered`);

        // Find all divs with class="note_content"
        let noteDivs = document.querySelectorAll('div.note_content');
        console.debug(`${LOG_PREFIX} Found ${noteDivs.length} note divs`);

        // Initialize an empty array to hold the contents of the 

elements let noteContents = []; // Loop through the note divs noteDivs.forEach(function(div) { // Find all

elements within the current div let pElements = div.querySelectorAll('p'); // Loop through the

elements and add their contents to the array pElements.forEach(function(p) { noteContents.push(p.textContent); }); }); // Join the array into a single string with a new line between each element let notesString = noteContents.join('\n'); console.debug(`${LOG_PREFIX} Collected ${noteContents.length} comments`); // Copy the string to the clipboard GM_setClipboard(notesString); console.log(`${LOG_PREFIX} 🎉 Copied ${noteContents.length} comments to clipboard`); }); // Create a mutation observer to watch for changes in the DOM let mutationCount = 0; let observer = new MutationObserver(function(mutations) { mutationCount++; console.debug(`${LOG_PREFIX} Mutation #${mutationCount} detected`); mutations.forEach(function(mutation) { if (mutation.type === 'childList') { // Find the div with data-testid="task-detail-default-header" let headerDiv = document.querySelector('div[data-testid="task-detail-default-header"]'); if (headerDiv) { console.debug(`${LOG_PREFIX} Found header div`); // Add the button to the header div headerDiv.appendChild(button); console.log(`${LOG_PREFIX} ✅ Button added to header`); // Stop observing once the button has been added observer.disconnect(); } } }); }); // Start observing the document with the configured parameters observer.observe(document, { childList: true, subtree: true }); console.debug(`${LOG_PREFIX} Mutation observer set up`); })();