snaptik tiktok button

8/28/2024

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला 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();
  });
})();