For Pestpac, adds buttons at the bottom of the tables to copy their information on a specific website
当前为
// ==UserScript==
// @name Copy Address Information Buttons
// @version 1.7
// @description For Pestpac, adds buttons at the bottom of the tables to copy their information on a specific website
// @author Jamie Cruz
// @match https://app.pestpac.com/location/*
// @grant none
// @license MIT
// @namespace https://greasyfork.org/users/1433767
// ==/UserScript==
(function() {
'use strict';
function addCopyButton(tableId, buttonText, color) {
var table = document.getElementById(tableId);
if (table) {
// Create and style the button
var button = document.createElement("button");
button.innerHTML = buttonText;
button.style.margin = "10px";
button.style.padding = "10px";
button.style.backgroundColor = "#1565C0";
button.style.color = "white";
button.style.border = "none";
button.style.borderRadius = "5px";
button.style.cursor = "pointer";
// Insert the button at the bottom of the table
table.parentNode.insertBefore(button, table.nextSibling);
// Function to copy table data
button.addEventListener("click", function() {
var range = document.createRange();
range.selectNode(table);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
try {
document.execCommand('copy');
alert(buttonText + " copied to clipboard!");
} catch (err) {
console.error("Failed to copy table data.", err);
}
window.getSelection().removeAllRanges();
});
}
}
window.onload = function() {
addCopyButton("location-address-block", "Copy Location Address", "#1565C0");
addCopyButton("billto-address-block", "Copy Billto Address", "#D32F2F");
};
})();