精简链接复制按钮

在淘宝、天猫和京东网页添加一个按钮,点击后复制当前精简后的网页链接,并显示提示信息,但不会修改地址栏链接

  1. // ==UserScript==
  2. // @name 精简链接复制按钮
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description 在淘宝、天猫和京东网页添加一个按钮,点击后复制当前精简后的网页链接,并显示提示信息,但不会修改地址栏链接
  6. // @author KaidQiao
  7. // @match *://*.taobao.com/*
  8. // @match *://*.tmall.com/*
  9. // @match *://*.jd.com/*
  10. // @grant GM_setClipboard
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // 创建按钮元素
  18. let button = document.createElement('button');
  19. button.innerText = '复制精简链接';
  20. button.style.position = 'fixed';
  21. button.style.bottom = '20px';
  22. button.style.right = '20px';
  23. button.style.zIndex = '1000';
  24. button.style.padding = '10px';
  25. button.style.backgroundColor = 'rgba(169, 169, 169, 0.6)';
  26. button.style.color = 'white';
  27. button.style.border = 'none';
  28. button.style.borderRadius = '5px';
  29. button.style.cursor = 'pointer';
  30. button.style.backdropFilter = 'blur(10px)';
  31. button.style.transition = 'background-color 0.3s';
  32.  
  33. // 鼠标经过效果
  34. button.addEventListener('mouseover', function() {
  35. button.style.backgroundColor = 'rgba(9, 187, 7, 0.8)';
  36. });
  37.  
  38. // 鼠标离开效果
  39. button.addEventListener('mouseout', function() {
  40. button.style.backgroundColor = 'rgba(169, 169, 169, 0.6)';
  41. });
  42.  
  43. // 获取精简链接的函数
  44. function getCleanUrl() {
  45. var site = window.location.href.match(/^http(s)?:\/\/[^?]*/);
  46. var params = ['id', 'wd', 'q', 'skuId']; // 保留 id, wd, q, 和 skuId
  47. var newUrl = site[0];
  48. var queryString = '';
  49.  
  50. params.forEach(function(param) {
  51. var value = new URLSearchParams(window.location.search).get(param);
  52. if (value) {
  53. queryString += (queryString ? '&' : '?') + param + '=' + value;
  54. }
  55. });
  56.  
  57. return newUrl + queryString;
  58. }
  59.  
  60. // 按钮点击事件
  61. button.onclick = function() {
  62. let cleanUrl = getCleanUrl();
  63. GM_setClipboard(cleanUrl, 'text'); // 将精简后的链接复制到剪贴板
  64.  
  65. // 显示提示信息
  66. let tooltip = document.createElement('div');
  67. tooltip.innerText = '精简链接已复制';
  68. tooltip.style.position = 'fixed';
  69. tooltip.style.bottom = '60px';
  70. tooltip.style.right = '20px';
  71. tooltip.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
  72. tooltip.style.color = 'white';
  73. tooltip.style.padding = '5px 10px';
  74. tooltip.style.borderRadius = '3px';
  75. tooltip.style.zIndex = '1001';
  76. document.body.appendChild(tooltip);
  77.  
  78. // 3秒后移除提示信息
  79. setTimeout(function() {
  80. tooltip.remove();
  81. }, 3000);
  82. };
  83.  
  84. // 将按钮添加到页面
  85. document.body.appendChild(button);
  86. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址