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

This is bad to have spaces in file names

当前为 2024-08-21 提交的版本,查看 最新版本

  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.1
  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. .replace(/%/g, 'percent')
  26. .replace(/\s/g, '_')
  27. .replaceAll(',', '')
  28. navigator.clipboard.writeText(text)
  29. }
  30. span.innerText = 'copy'
  31.  
  32. h1.append(span)
  33. })()