Greasy Fork

Greasy Fork is available in English.

Filtro Tiktok

Descrição do script

当前为 2023-08-06 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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();
})();