Last active
January 11, 2024 15:33
-
-
Save nethad/046c7166f15f7ffaeebd82c8b5be0fb2 to your computer and use it in GitHub Desktop.
Intercom Copy/Delete Notes Tampermonkey script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Intercom Copy Notes | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://app.intercom.com/* | |
// @icon https://www.google.com/s2/favicons?domain=intercom.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const buildButton = (label) => { | |
const newButton = document.createElement("button") | |
newButton.setAttribute("type", "button") | |
newButton.classList.add("inbox2__button", "bg-gray-lightest", "text-black", "mx-2", "px-2") | |
const span = document.createElement("span") | |
span.textContent = label | |
newButton.appendChild(span) | |
return newButton | |
} | |
const attachButton = () => { | |
const allNotes = document.querySelectorAll("[data-part-group-category='4']") | |
allNotes.forEach((noteElement) => { | |
const buttonRow = document.createElement("div") | |
buttonRow.classList.add("js-x-button-row", "text-right", "mt-3") | |
const copyButton = buildButton("Kopieren") | |
copyButton.addEventListener("click", () => { | |
const paragraphs = noteElement.querySelectorAll("p") | |
const text = Array.from(paragraphs).map(e => e.textContent).join("\n") | |
navigator.clipboard.writeText(text) | |
copyButton.textContent = "Kopieren ✅" | |
}) | |
buttonRow.append(copyButton) | |
const deleteButton = buildButton("Löschen") | |
deleteButton.addEventListener("click", () => { | |
const dropdown = noteElement.querySelector(".inbox2__message-actions-pill") | |
dropdown.classList.remove("invisible") | |
dropdown.querySelector("span").click() | |
setTimeout(() => { | |
const items = document.querySelectorAll(".js-command-k-modal .dropdown__list-item") | |
const deleteItem = document.querySelector("[data-intercom-target-action-menu-item='delete-message']") | |
deleteItem.click() | |
setTimeout(() => { | |
// const deleteButton = Array.from(document.querySelectorAll(".ds-new__modal__container button")).find((e) => e.textContent.trim() == "Delete") | |
// document.querySelector("div[data-modal-wrapper] .ds-new__modal__footer button:nth-child(2)") | |
// const deleteButton = document.querySelector("[data-test-modal-container] button.bg-red-light") | |
const deleteButton = Array.from(document.querySelectorAll("div[data-modal-wrapper] button")).slice(-1)[0] | |
deleteButton.click() | |
}, 1) | |
}, 1) | |
}) | |
buttonRow.append(deleteButton) | |
noteElement.querySelectorAll(".js-x-button-row").forEach((e) => e.remove()) | |
noteElement.appendChild(buttonRow) | |
}) | |
} | |
var pushState = history.pushState; | |
history.pushState = function(state) { | |
setTimeout(() => attachButton(), 1000) | |
return pushState.apply(history, arguments); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment