🏠 Home 

蝦皮短網址

縮短蝦皮網址

  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. (function() {
  13. 'use strict';
  14. var ShortURL
  15. // Create a button
  16. var CopyButton = document.createElement('button');
  17. CopyButton.className = 'CopyButton'; // Add your custom class tSCitv
  18. CopyButton.setAttribute('aria-label', 'Copy');
  19. CopyButton.textContent = 'Short URL';
  20. // 设置按钮样式
  21. CopyButton.style.backgroundColor = 'white';
  22. CopyButton.style.border = 'none';
  23. CopyButton.style.fontSize = '15px';
  24. CopyButton.style.lineHeight = '0px';
  25. CopyButton.style.cursor = 'pointer';
  26. // Add button click event
  27. CopyButton.addEventListener('click', function() {
  28. navigator.clipboard.writeText(ShortURL);
  29. CopyButton.textContent = 'Copied!';
  30. setTimeout(function() {
  31. CopyButton.textContent = 'Short URL';
  32. }, 1000);
  33. });
  34. function MainFun() {
  35. var flexContainer = document.querySelector('.flex.items-center.idmlsn');// Find the target flex container
  36. if (flexContainer) {// Check if the flex container exists
  37. flexContainer.appendChild(CopyButton);//注入按鈕
  38. var URL=decodeURIComponent(location.href)
  39. if (/product/.test(URL)) {
  40. ShortURL=URL.replace(/^https:\/\//, '')
  41. }else{
  42. ShortURL = 'shopee.tw' + URL
  43. .replace(/^https:\/\/shopee.tw/, '')
  44. .replace(/\/.*-i\./, '/product/')
  45. .replace(/\?\S*/, '')
  46. .replace(/\./g, '/')
  47. }
  48. }
  49. }
  50. //第一次執行
  51. setTimeout(function() {
  52. MainFun()
  53. },3000);
  54. //循環
  55. var mz = location.href;
  56. setInterval(function () {
  57. if (mz != location.href) {
  58. mz=location.href;
  59. MainFun();
  60. }
  61. },5000);
  62. })();