Copy Address Information Buttons

For Pestpac, adds buttons at the bottom of the tables to copy their information on a specific website

  1. // ==UserScript==
  2. // @name Copy Address Information Buttons
  3. // @version 2.2
  4. // @description For Pestpac, adds buttons at the bottom of the tables to copy their information on a specific website
  5. // @author Jamie Cruz
  6. // @match https://app.pestpac.com/location/*
  7. // @grant none
  8. // @license MIT
  9. // @namespace https://gf.qytechs.cn/users/1433767
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function addCopyButton(tableId, buttonText, color, formatSingleLine = false) {
  16. var table = document.getElementById(tableId);
  17. if (table) {
  18. var button = document.createElement("button");
  19. button.innerHTML = buttonText;
  20. button.style.margin = "10px";
  21. button.style.padding = "10px";
  22. button.style.backgroundColor = color;
  23. button.style.color = "white";
  24. button.style.border = "none";
  25. button.style.borderRadius = "5px";
  26. button.style.cursor = "pointer";
  27. button.style.width = "160px"; // Set a fixed width for both buttons
  28. button.style.height = "25px"; // Set a fixed height for both buttons
  29.  
  30. // Center-align text both vertically and horizontally
  31. button.style.display = "flex";
  32. button.style.justifyContent = "center";
  33. button.style.alignItems = "center";
  34.  
  35. // Create a new table row and cell
  36. var newRow = table.insertRow(-1); // Insert row at the end of the table
  37. var newCell = newRow.insertCell(0);
  38. newCell.colSpan = table.rows[0].cells.length; // Make the cell span across all columns
  39.  
  40. // Insert the button into the new cell
  41. newCell.appendChild(button);
  42.  
  43. // Function to copy table data
  44. button.addEventListener("click", function() {
  45. var textContent = table.innerText;
  46.  
  47. // Remove unwanted words
  48. var cleanedText = textContent.replace(/EMAIL|Map View|Street View|PHONE|Copy Location Address|Copy Billto Address|Calendar\/Email|/g, "");
  49.  
  50. // Clean extra line breaks
  51. if (formatSingleLine) {
  52. cleanedText = cleanedText.replace(/\n\s*\n/g, " -- ").trim().replace(/\n/g, " -- ");
  53. } else {
  54. cleanedText = cleanedText.replace(/\n\s*\n/g, "\n").trim();
  55. }
  56.  
  57. // Copy cleaned text to clipboard
  58. navigator.clipboard.writeText(cleanedText).then(function() {
  59. alert("Address copied to clipboard!");
  60. }).catch(function(err) {
  61. console.error("Failed to copy table data.", err);
  62. });
  63. });
  64. }
  65. }
  66.  
  67. window.onload = function() {
  68. addCopyButton("location-address-block", "Copy Location Address", "#1565C0");
  69. addCopyButton("location-address-block", "Calendar/Email", "#2E67F8", true);
  70. addCopyButton("billto-address-block", "Copy Billto Address", "#1565C0");
  71. addCopyButton("billto-address-block", "Calendar/Email", "#2E67F8", true);
  72. };
  73. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址