Boosty Tag Formatter

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

当前为 2024-07-24 提交的版本,查看 最新版本

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

(function() {
    'use strict';

    function formatTags() {
        const tagContainers = document.querySelectorAll('.PostTags_root_K_e6Z');

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

            const tags = tagContainer.querySelectorAll('.PostTag_title_GxOeW');
            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 });
})();