Greasy Fork

Greasy Fork is available in English.

Filtro TikTok

Descrição do script

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

// ==UserScript==
// @name       Filtro TikTok
// @namespace  URL única do autor
// @version    1.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;
}

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', // Fixed typo in "position"
          };
          createDom(cfg);
        }
      }
    });
  }
};

// ... (Existing script logic)

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