Filtro Tiktok

Descrição do script

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name       Filtro Tiktok
// @namespace  URL única do autor
// @version    2.0
// @description  Descrição do script
// @match      http://www.tiktok.com/*
// @match      https://www.tiktok.com/*
// @license    MIT
// ==/UserScript==

// Add the following helper function to extract the number of interactions from a TikTok video URL
function extractInteractions(url) {
  const match = url.match(/\/stat\/item\/(\d+)/);
  return match ? parseInt(match[1]) : 0;
}

// Add the following function to redirect the video link to Shopee
function redirectToShopee(link) {
  // Replace the following URL with your Shopee store URL
  const shopeeURL = 'https://shopee.com/';
  window.location.href = shopeeURL + encodeURIComponent(link);
}

const init = () => {
  // ... (Existing init function code)

  if (hostname === "www.tiktok.com") {
    window.addEventListener('mouseover', ({ target }) => {
      if (target.tagName == 'VIDEO') {
        const src = target.src;
        const parent = target.parentElement;
        const interactions = extractInteractions(src); // Get the number of interactions from the video URL

        // Define the threshold for the minimum number of interactions to show the download button
        const interactionsThreshold = 1000; // Adjust this value as desired

        if (interactions >= interactionsThreshold) {
          const link = src;
          const style = 'left: 10px; top: 10px;';
          const cfg = {
            parent,
            link,
            style,
            target,
            name: lastItem(src.split('?')[0].split('/').filter(x => x)),
            position: 'beforeEnd',
          };
          createDom(cfg);

          // Add the event listener for the download button to redirect to Shopee
          const downloadButton = parent.querySelector('.download-button');
          downloadButton.addEventListener('click', () => {
            redirectToShopee(link);
          });
        }
      }
    });
  }
};

// ... (Existing script logic)

// Código executável começa aqui
(function() {
    init();
})();