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

This is bad to have spaces in file names

当前为 2024-06-11 提交的版本,查看 最新版本

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