snaptik tiktok button

8/28/2024

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name        snaptik tiktok button
// @namespace   Violentmonkey Scripts
// @match       https://www.tiktok.com/*
// @grant       none
// @version     1.3
// @author      minnie
// @description 8/28/2024
// ==/UserScript==

(function () {
  let isButtonAdded = false;

  function addSnaptikButton(targetElement) {
    if (targetElement.querySelector('.snaptik-btn')) return; // Prevent duplicate buttons

    let snaptikBtn = document.createElement('button');
    snaptikBtn.className = 'snaptik-btn';
    snaptikBtn.innerHTML = 'Snaptik';
    snaptikBtn.style.cssText = `
      box-sizing: border-box;
      appearance: none;
      min-width: 96px;
      display: inline-flex;
      justify-content: center;
      align-items: center;
      position: relative;
      border-style: solid;
      border-width: 1px;
      border-radius: 2px;
      font-family: var(--tux-fontFamilyParagraph);
      font-weight: var(--tux-fontWeightSemibold);
      text-decoration: none;
      cursor: pointer;
      background-clip: padding-box;
      font-size: 15px;
      height: 36px;
      padding-inline: 15px;
      color: var(--tux-colorConstTextInverse);
      background-color: var(--tux-colorPrimary);
      border-color: var(--tux-colorPrimary);
      margin-left: 10px;
    `;

    snaptikBtn.addEventListener('click', () => {
      let currentLink = window.location.href;
      navigator.clipboard
        .writeText(currentLink)
        .then(() => {
          console.log('Link copied to clipboard');
          window.open('https://snaptik.app/en1', '_blank');
        })
        .catch((err) => {
          console.error('Could not copy text: ', err);
        });
    });

    targetElement.appendChild(snaptikBtn);
  }

  // MutationObserver callback
  function observeChanges() {
    const targetWrapper = document.querySelector('.css-r4iroe-DivBtnWrapper.evv7pft7');
    if (targetWrapper) {
      addSnaptikButton(targetWrapper);
    }
  }

  // Set up a MutationObserver
  const observer = new MutationObserver(() => {
    observeChanges();
  });

  // Start observing the document body for changes
  observer.observe(document.body, { childList: true, subtree: true });

  // Optional: Disconnect the observer if the page is unloaded to prevent memory leaks
  window.addEventListener('beforeunload', () => {
    observer.disconnect();
  });
})();