Copy Address Information Buttons

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

目前為 2025-02-10 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Copy Address Information Buttons
  3. // @version 1.7
  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 = "#1565C0";
  24. button.style.color = "white";
  25. button.style.border = "none";
  26. button.style.borderRadius = "5px";
  27. button.style.cursor = "pointer";
  28.  
  29. // Insert the button at the bottom of the table
  30. table.parentNode.insertBefore(button, table.nextSibling);
  31.  
  32. // Function to copy table data
  33. button.addEventListener("click", function() {
  34. var range = document.createRange();
  35. range.selectNode(table);
  36. window.getSelection().removeAllRanges();
  37. window.getSelection().addRange(range);
  38. try {
  39. document.execCommand('copy');
  40. alert(buttonText + " copied to clipboard!");
  41. } catch (err) {
  42. console.error("Failed to copy table data.", err);
  43. }
  44. window.getSelection().removeAllRanges();
  45. });
  46. }
  47. }
  48.  
  49. window.onload = function() {
  50. addCopyButton("location-address-block", "Copy Location Address", "#1565C0");
  51. addCopyButton("billto-address-block", "Copy Billto Address", "#D32F2F");
  52. };
  53. })();