蝦皮短網址

縮短蝦皮網址

  1. // ==UserScript==
  2. // @name 蝦皮短網址
  3. // @namespace https://greasyfork.org/zh-TW/scripts/479591
  4. // @match *shopee.tw/*
  5. // @author czh/XPRAMT
  6. // @icon https://www.google.com/s2/favicons?sz=64&domain=shopee.tw
  7. // @run-at document-start
  8. // @license GNU GPLv3
  9. // @description 縮短蝦皮網址
  10. // @version 1.3
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. var ShortURL
  17.  
  18. // Create a button
  19. var CopyButton = document.createElement('button');
  20. CopyButton.className = 'CopyButton'; // Add your custom class tSCitv
  21. CopyButton.setAttribute('aria-label', 'Copy');
  22. CopyButton.textContent = 'Short URL';
  23.  
  24. // 设置按钮样式
  25. CopyButton.style.backgroundColor = 'white';
  26. CopyButton.style.border = 'none';
  27. CopyButton.style.fontSize = '15px';
  28. CopyButton.style.lineHeight = '0px';
  29. CopyButton.style.cursor = 'pointer';
  30.  
  31. // Add button click event
  32. CopyButton.addEventListener('click', function() {
  33. navigator.clipboard.writeText(ShortURL);
  34. CopyButton.textContent = 'Copied!';
  35. setTimeout(function() {
  36. CopyButton.textContent = 'Short URL';
  37. }, 1000);
  38. });
  39.  
  40. function MainFun() {
  41. var flexContainer = document.querySelector('.flex.items-center.idmlsn');// Find the target flex container
  42. if (flexContainer) {// Check if the flex container exists
  43. flexContainer.appendChild(CopyButton);//注入按鈕
  44.  
  45. var URL=decodeURIComponent(location.href)
  46.  
  47. if (/product/.test(URL)) {
  48. ShortURL=URL.replace(/^https:\/\//, '')
  49. }else{
  50. ShortURL = 'shopee.tw' + URL
  51. .replace(/^https:\/\/shopee.tw/, '')
  52. .replace(/\/.*-i\./, '/product/')
  53. .replace(/\?\S*/, '')
  54. .replace(/\./g, '/')
  55. }
  56. }
  57. }
  58.  
  59. //第一次執行
  60. setTimeout(function() {
  61. MainFun()
  62. },3000);
  63. //循環
  64. var mz = location.href;
  65. setInterval(function () {
  66. if (mz != location.href) {
  67. mz=location.href;
  68. MainFun();
  69. }
  70. },5000);
  71.  
  72. })();