Game Jolt Notification Filter Preserver

Preserves and restores selected filters on the notifications page of Game Jolt.

// ==UserScript==
// @name           Game Jolt Notification Filter Preserver
// @name:ru        Сохранение фильтров уведомлений Game Jolt
// @namespace      http://tampermonkey.net/
// @version        0.1
// @icon           https://s.gjcdn.net/img/favicon.png
// @description    Preserves and restores selected filters on the notifications page of Game Jolt.
// @description:ru Восстанавливает выбранные фильтры на странице уведомлений Game Jolt.
// @author         Deflecta, GKProduction
// @match          https://gamejolt.com/*
// @match          https://*.gamejolt.com/*
// @grant          none
// @license        MIT
// ==/UserScript==

(function() {
    // Задаём переменные
    const notifPageUrl = 'https://gamejolt.com/notifications';

    // Сохраняем фильтры
    function saveFilters()
        {
            const urlParams = new URLSearchParams(window.location.search);
            const filters = urlParams.get('f');
            if (filters)
                {
                    localStorage.setItem('gjNotifFilters', filters);
                }
        }

    // Загружаем фильтры
    function loadFilters()
        {
            return localStorage.getItem('gjNotifFilters');
        }

    // Проверяем факт нажатия
    document.addEventListener('click', (event) =>
        {
            const viewAllButton = event.target.closest('a.button.-trans.-block');
            if (viewAllButton && viewAllButton.textContent.trim() === ('View all' || 'Посмотреть всё'))
                {
                    const filters = loadFilters();
                    if (filters)
                        {
                            event.preventDefault();
                            window.location.href = `${notifPageUrl}?f=${filters}`;
                        }
                }
        });

    // Запоминаем фильтры в нужный момент с MutationObserver
    const observer = new MutationObserver(() =>
        {
            if (window.location.href.startsWith(notifPageUrl))
                {
                    saveFilters();
                }
        });

    // Запускаем MutationObserver
    observer.observe(document.body,
        {
            childList: true, subtree: true 
        });

    // Сохраняем фильтры, если мы в уведомлениях
    if (window.location.href.startsWith(notifPageUrl))
        {
            saveFilters();
        }
})();

QingJ © 2025

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