Boosty Tag Formatter

Форматирование тегов на Boosty в одну строку

目前為 2024-07-25 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Boosty Tag Formatter
// @namespace   http://tampermonkey.net/
// @version     1.11
// @description Форматирование тегов на Boosty в одну строку
// @author      ChatGPT
// @match       https://boosty.to/*
// @grant       none
// ==/UserScript==

(function() {
    'use strict';

    function formatTags() {
        // Используем селектор, который ищет элементы с классом, содержащим 'PostTags_root_'
        const tagContainers = document.querySelectorAll('[class*="PostTags_root_"]');

        tagContainers.forEach(tagContainer => {
            if (tagContainer.dataset.formatted) return; // Проверка, чтобы не форматировать повторно

            // Используем селектор, который ищет элементы с классом, содержащим 'PostTag_title_'
            const tags = tagContainer.querySelectorAll('[class*="PostTag_title_"]');
            if (!tags.length) return;

            const tagArray = Array.from(tags).map(tag => tag.textContent.trim());
            const formattedTags = tagArray.map(tag => `${tag}`).join(', ');

            const tagsString = `Теги: ${formattedTags}`;
            const tagStringElement = document.createElement('div');
            tagStringElement.innerHTML = tagsString;
            tagStringElement.style.marginBottom = '10px';

            tagContainer.insertAdjacentElement('beforebegin', tagStringElement);
            tagContainer.dataset.formatted = 'true'; // Отметка, что контейнер уже был обработан
        });
    }

    // Запуск функции после загрузки страницы
    window.addEventListener('load', formatTags);

    // Запуск функции при динамической подгрузке контента (например, при AJAX запросах)
    const observer = new MutationObserver((mutations) => {
        mutations.forEach(mutation => {
            if (mutation.addedNodes.length) {
                formatTags();
            }
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址