Replace SOON and Update Views

Replaces the text "SOON" with the video duration and updates the view count in the metadata.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Replace SOON and Update Views
// @namespace    http://tampermonkey.net/
// @version      0.81
// @description  Replaces the text "SOON" with the video duration and updates the view count in the metadata.
// @match        *://www.youtube.com/*
// @grant        none
// @license      none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function updateVideoInfo() {
        // Substituir "EM BREVE" pelo tempo do vídeo
        document.querySelectorAll('ytd-thumbnail-overlay-time-status-renderer').forEach(overlay => {
            const textElement = overlay.querySelector('.badge-shape-wiz__text');
            const spanTextElement = overlay.querySelector('#text');

            if (textElement && textElement.textContent.trim() === 'EM BREVE') {
                const lengthElement = overlay.closest('ytd-rich-grid-media').querySelector('yt-formatted-string#length');

                if (lengthElement) {
                    const videoTime = lengthElement.textContent.trim();
                    textElement.textContent = videoTime;
                    if (spanTextElement) {
                        spanTextElement.textContent = videoTime;
                    }
                }
            }
        });

        // Atualizar visualizações no metadado do vídeo
        document.querySelectorAll('ytd-video-meta-block').forEach(metaBlock => {
            const ariaLabel = metaBlock.querySelector('yt-formatted-string[aria-label]');
            const viewCountElement = metaBlock.querySelector('span.inline-metadata-item.style-scope.ytd-video-meta-block');

            if (ariaLabel && viewCountElement) {
                // Extrai visualizações do aria-label
                const ariaText = ariaLabel.getAttribute('aria-label');
                const viewCountMatch = ariaText.match(/(\d+ visualizações)/);

                if (viewCountMatch) {
                    const viewCount = viewCountMatch[0];
                    // Substitui o texto do metadado com a contagem de visualizações extraída
                    viewCountElement.textContent = viewCount;
                }
            }
        });
    }

    // Execute a função quando o DOM estiver totalmente carregado
    document.addEventListener('DOMContentLoaded', updateVideoInfo);

    // Execute a função também em intervalos regulares para cobrir alterações dinâmicas
    setInterval(updateVideoInfo, 3000); // Executa a cada 3 segundos
})();