SWC Events Clipboard

Adds an "Copy" button to the SWC Events page, which adds the event details to the clipboard.

  1. // ==UserScript==
  2. // @name SWC Events Clipboard
  3. // @namespace https://www.swcombine.com/
  4. // @version 1.2
  5. // @description Adds an "Copy" button to the SWC Events page, which adds the event details to the clipboard.
  6. // @author code-syl
  7. // @match https://www.swcombine.com/members/events/index.php*
  8. // @icon https://www.swcombine.com/favicon.ico
  9. // @grant none
  10. // @license MIT
  11. // @require https://greasyfork.org/scripts/383527-wait-for-key-elements/code/Wait_for_key_elements.js?version=701631
  12. // ==/UserScript==
  13. /* @require https://code.jquery.com/jquery-3.6.3.min.js /* <-- enable when not using waitForKeyElements.js */
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. const styles = `
  19. .eventmsg:not(:hover) #alani-copy {
  20. display: none;
  21. }
  22.  
  23. .eventmsg:hover #alani-copy,
  24. .eventpriv {
  25. align-self: center;
  26. }
  27. .eventpriv img {
  28. padding-top: 0 !important;
  29. }`;
  30.  
  31. let styleSheet = document.createElement("style");
  32. styleSheet.innerText = styles;
  33. document.head.appendChild(styleSheet);
  34.  
  35. const onCopyClick = (jNode) => {
  36. const swcDateTime = jNode.find('.eventdate')[0].outerText;
  37. const eventText = jNode.find('.eventtext')[0].outerText;
  38.  
  39. navigator.clipboard.writeText(swcDateTime + ' ' + eventText)
  40. .then(() => { console.info('Copied event details to clipboard.'); })
  41. .catch(error => { console.error('Failed to copy event details to clipboard: ', error); });
  42. };
  43.  
  44. const addCopyButton = (jNode) => {
  45. let button = document.createElement('button');
  46. button.id = 'alani-copy';
  47. button.textContent = 'Copy';
  48. button.style.height = '2rem';
  49. button.addEventListener('click', () => onCopyClick(jNode));
  50.  
  51. jNode.find('.eventpriv')
  52. .before(button);
  53. }
  54.  
  55. waitForKeyElements('.eventmsg', addCopyButton);
  56. })();