moneymuseum.by: PDP: add button to copy a title without spaces

This is bad to have spaces in file names

  1. // ==UserScript==
  2. // @name moneymuseum.by: PDP: add button to copy a title without spaces
  3. // @namespace Violentmonkey Scripts
  4. // @match https://moneymuseum.by/*
  5. // @version 1.2
  6. // @author Vitaly Zdanevich
  7. // @description This is bad to have spaces in file names
  8. // @supportURL https://gitlab.com/vitaly-zdanevich-userscripts/copy-title-without-spaces
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12.  
  13. (function() {
  14. if (document.querySelector('.product-item-detail-slider-image').length === 0) {
  15. return // This is not a PDP
  16. }
  17.  
  18. const h1 = document.querySelector('h1')
  19.  
  20. const span = document.createElement('span')
  21. span.style='margin:10px; font-style:italic; color:green; cursor:pointer'
  22. span.onclick=function() {
  23. this.remove()
  24. const text = h1.innerText
  25. .replaceAll('1/2 %', 'half_percent')
  26. .replace(/%/g, 'percent')
  27. .replace(/\s/g, '_')
  28. .replaceAll(',', '')
  29. navigator.clipboard.writeText(text)
  30. }
  31. span.innerText = 'copy'
  32.  
  33. h1.append(span)
  34. })()