Tmall Page URL and Title Copier with Enhanced UI

Adds a stylish button to copy the H1 text and cleaned URL to the clipboard with auto-hide notification.

当前为 2023-12-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Tmall Page URL and Title Copier with Enhanced UI
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.3
  5. // @description Adds a stylish button to copy the H1 text and cleaned URL to the clipboard with auto-hide notification.
  6. // @author max5555
  7. // @license MIT
  8. // @match https://detail.tmall.com/item.htm*
  9. // @grant GM_setClipboard
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Create the floating button with enhanced style
  16. var floatingButton = document.createElement('button');
  17. floatingButton.innerText = 'Copy H1 & URL';
  18. floatingButton.style.position = 'fixed';
  19. floatingButton.style.bottom = '60px';
  20. floatingButton.style.right = '20px';
  21. floatingButton.style.padding = '10px';
  22. floatingButton.style.backgroundColor = '#4CAF50';
  23. floatingButton.style.color = 'white';
  24. floatingButton.style.border = 'none';
  25. floatingButton.style.borderRadius = '5px';
  26. floatingButton.style.cursor = 'pointer';
  27. floatingButton.style.zIndex = '1000';
  28. document.body.appendChild(floatingButton);
  29.  
  30. // Function to clean the URL and return the essential part
  31. function cleanURL(url) {
  32. const urlObj = new URL(url);
  33. return urlObj.origin + urlObj.pathname + '?id=' + urlObj.searchParams.get('id');
  34. }
  35.  
  36. // Function to create and auto-hide notification
  37. function showNotification(message, duration) {
  38. var notification = document.createElement('div');
  39. notification.innerText = message;
  40. notification.style.position = 'fixed';
  41. notification.style.bottom = '50px';
  42. notification.style.right = '20px';
  43. notification.style.backgroundColor = '#4CAF50';
  44. notification.style.color = 'white';
  45. notification.style.padding = '10px';
  46. notification.style.borderRadius = '5px';
  47. notification.style.zIndex = '1001';
  48. document.body.appendChild(notification);
  49.  
  50. setTimeout(function() {
  51. notification.remove();
  52. }, duration);
  53. }
  54.  
  55. // Event listener for the button
  56. floatingButton.addEventListener('click', function() {
  57. const h1Text = document.querySelector('h1').innerText;
  58. const cleanedURL = cleanURL(window.location.href);
  59. const textToCopy = h1Text + ' ' + cleanedURL;
  60. GM_setClipboard(textToCopy);
  61. showNotification('H1 text and URL copied to clipboard!', 3000); // Notification for 3 seconds
  62. });
  63. })();