🏠 返回首頁 

Greasy Fork is available in English.

snaptik tiktok button

8/28/2024


安装此脚本?
  1. // ==UserScript==
  2. // @name snaptik tiktok button
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.tiktok.com/*
  5. // @grant none
  6. // @version 1.3
  7. // @author minnie
  8. // @description 8/28/2024
  9. // ==/UserScript==
  10. (function () {
  11. let isButtonAdded = false;
  12. function addSnaptikButton(targetElement) {
  13. if (targetElement.querySelector('.snaptik-btn')) return; // Prevent duplicate buttons
  14. let snaptikBtn = document.createElement('button');
  15. snaptikBtn.className = 'snaptik-btn';
  16. snaptikBtn.innerHTML = 'Snaptik';
  17. snaptikBtn.style.cssText = `
  18. box-sizing: border-box;
  19. appearance: none;
  20. min-width: 96px;
  21. display: inline-flex;
  22. justify-content: center;
  23. align-items: center;
  24. position: relative;
  25. border-style: solid;
  26. border-width: 1px;
  27. border-radius: 2px;
  28. font-family: var(--tux-fontFamilyParagraph);
  29. font-weight: var(--tux-fontWeightSemibold);
  30. text-decoration: none;
  31. cursor: pointer;
  32. background-clip: padding-box;
  33. font-size: 15px;
  34. height: 36px;
  35. padding-inline: 15px;
  36. color: var(--tux-colorConstTextInverse);
  37. background-color: var(--tux-colorPrimary);
  38. border-color: var(--tux-colorPrimary);
  39. margin-left: 10px;
  40. `;
  41. snaptikBtn.addEventListener('click', () => {
  42. let currentLink = window.location.href;
  43. navigator.clipboard
  44. .writeText(currentLink)
  45. .then(() => {
  46. console.log('Link copied to clipboard');
  47. window.open('https://snaptik.app/en1', '_blank');
  48. })
  49. .catch((err) => {
  50. console.error('Could not copy text: ', err);
  51. });
  52. });
  53. targetElement.appendChild(snaptikBtn);
  54. }
  55. // MutationObserver callback
  56. function observeChanges() {
  57. const targetWrapper = document.querySelector('.css-r4iroe-DivBtnWrapper.evv7pft7');
  58. if (targetWrapper) {
  59. addSnaptikButton(targetWrapper);
  60. }
  61. }
  62. // Set up a MutationObserver
  63. const observer = new MutationObserver(() => {
  64. observeChanges();
  65. });
  66. // Start observing the document body for changes
  67. observer.observe(document.body, { childList: true, subtree: true });
  68. // Optional: Disconnect the observer if the page is unloaded to prevent memory leaks
  69. window.addEventListener('beforeunload', () => {
  70. observer.disconnect();
  71. });
  72. })();