Copy Address Information Buttons

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

目前为 2025-02-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Copy Address Information Buttons
  3. // @version 1.93
  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://greasyfork.org/users/1433767
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function addCopyButton(tableId, buttonText, color) {
  16. var table = document.getElementById(tableId);
  17. if (table) {
  18. // Create and style the button
  19. var button = document.createElement("button");
  20. button.innerHTML = buttonText;
  21. button.style.margin = "10px";
  22. button.style.padding = "10px";
  23. button.style.backgroundColor = color;
  24. button.style.color = "white";
  25. button.style.border = "none";
  26. button.style.borderRadius = "5px";
  27. button.style.cursor = "pointer";
  28. button.style.display = "flex";
  29. button.style.justifyContent = "center";
  30. button.style.alignItems = "center";
  31.  
  32. // Create a new table row and cell
  33. var newRow = table.insertRow(-1); // Insert row at the end of the table
  34. var newCell = newRow.insertCell(0);
  35. newCell.colSpan = table.rows[0].cells.length; // Make the cell span across all columns
  36.  
  37. // Insert the button into the new cell
  38. newCell.appendChild(button);
  39.  
  40. // Function to copy table data
  41. button.addEventListener("click", function() {
  42. var textContent = table.innerText;
  43.  
  44. // Remove unwanted words and extra line breaks
  45. var cleanedText = textContent.replace(/EMAIL|Map View|Street View|PHONE/g, "").replace(/\n\s*\n/g, "\n").trim();
  46.  
  47. // Copy cleaned text to clipboard
  48. navigator.clipboard.writeText(cleanedText).then(function() {
  49. alert("Address copied to clipboard!");
  50. }).catch(function(err) {
  51. console.error("Failed to copy table data.", err);
  52. });
  53. });
  54. }
  55. }
  56.  
  57. window.onload = function() {
  58. addCopyButton("location-address-block", "Copy Location Address", "#1565C0");
  59. addCopyButton("billto-address-block", "Copy Billto Address", "#1565C0");
  60. };
  61. })();