Skip to content

Instantly share code, notes, and snippets.

@splintor
Last active June 23, 2022 06:38
Show Gist options
  • Save splintor/6e6c459e0f5e0f621d0b32fa5807fbd8 to your computer and use it in GitHub Desktop.
Save splintor/6e6c459e0f5e0f621d0b32fa5807fbd8 to your computer and use it in GitHub Desktop.
Wix Dashboard - Add buttons to copy IDs
// ==UserScript==
// @name Wix Dashboard - Add buttons to copy IDs
// @namespace https://github.com/splintor/
// @version 0.3
// @description Make it easy to copy entities' UUID in Wix Dashboard
// @author You
// @match https://manage.wix.com/dashboard/*
// @match https://manage.editorx.com/dashboard/*
// @icon https://wix.com/favicon.ico
// @downloadURL https://gist.githubusercontent.com/splintor/6e6c459e0f5e0f621d0b32fa5807fbd8/raw
// @updateURL https://gist.githubusercontent.com/splintor/6e6c459e0f5e0f621d0b32fa5807fbd8/raw
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
const getMSID = () => location.href.split('dashboard/')[1].split('/')[0]
const $ = s => document.querySelector(s);
const $$ = s => document.querySelectorAll(s);
const svgData = '<svg viewBox="0 0 24 24" fill="currentColor" width="24" height="24"><path d="M19,5 C19.5522847,5 20,5.44771525 20,6 L20,16 C20,16.5522847 19.5522847,17 19,17 L17,17 L17,19 C17,19.5522847 16.5522847,20 16,20 L6,20 C5.44771525,20 5,19.5522847 5,19 L5,9 C5,8.44771525 5.44771525,8 6,8 L8,8 L8,6 C8,5.44771525 8.44771525,5 9,5 L19,5 Z M8,9 L6,9 L6,19 L16,19 L16,17 L9,17 C8.44771525,17 8,16.5522847 8,16 L8,9 Z M19,6 L9,6 L9,16 L19,16 L19,6 Z"></path></svg>'
function copyText(text) {
var inp = document.createElement('input');
document.body.appendChild(inp)
inp.value = text
inp.select();
document.execCommand('copy',false);
inp.remove();
}
function addToast(text) {
const bmRoot = $('[data-hook="right-side-area"]')
const toast = document.createElement("div")
toast.innerHTML = text
toast.className = 'copyButtonToast'
bmRoot.insertBefore(toast, bmRoot.firstChild)
setTimeout(() => toast.remove(), 1000)
}
function addCopyButton(element, textToCopy, textType, className) {
const button = document.createElement("span")
button.className = className + ' copyButton'
button.title = textToCopy
button.innerHTML = svgData + ' Copy ' + textType
button.addEventListener('click', (event) => {
event.preventDefault()
event.stopPropagation()
copyText(textToCopy)
addToast(textType + ' "' + textToCopy + '" was copied.')
})
element.parentNode.insertBefore(button, element)
}
function addButtons() {
if (!$('.copy-msid-button')) {
const searchInput = $('[data-hook="search-everything-input"]')
if (searchInput) {
addCopyButton(searchInput, getMSID(), 'MSID', 'copy-msid-button')
}
}
if ($('[data-hook="contacts-list-table"]') && !$('.copy-contact-button')) {
$$('[data-hook="contacts-list-table"] tr[data-hook="contact"] div[data-hook^="contact-lastActivity-"]').forEach(el => {
const contactId = el.attributes['data-hook'].nodeValue.replace(/^contact-lastActivity-|-tooltip$/g, '')
addCopyButton(el, contactId, 'Contact ID', 'copy-contact-button')
})
}
}
GM_addStyle('.copyButton { font-family: Madefor; display: flex; align-items: center; color: blue; cursor: pointer; font-size: .9em; margin-top: 3px; margin-left: -140px; position: absolute; }')
GM_addStyle('[data-hook="contacts-list-table"] tr .copy-contact-button { display: none }');
GM_addStyle('[data-hook="contacts-list-table"] tr:hover .copy-contact-button { display: flex }');
GM_addStyle('.copyButtonToast { font-family: Madefor; font-size: .9em; background-color: lightgreen; padding: 8px; text-align: center; position: absolute; width: 100%; z-index: 10000; }');
setInterval(addButtons, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment