Jut.su Achievements UI

Показывает достижения с jut.su которые можно получить в нынешней серии через кнопку-меню

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Jut.su Achievements UI
// @namespace    http://tampermonkey.net/
// @version      2025-04-07
// @description  Показывает достижения с jut.su которые можно получить в нынешней серии через кнопку-меню
// @author       relder1
// @match        https://jut.su/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=jut.su
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';
    if (window.location.pathname === '/') {
        return;
    }
    const blockedPaths = [
        /^https:\/\/jut\.su\/user\//,
        /^https:\/\/jut\.su\/pm\//,
        /^https:\/\/jut\.su\/anime\//,
        /^https:\/\/jut\.su\/rewards\//,
        /^https:\/\/jut\.su\/ninja\//
    ];

    for (const path of blockedPaths) {
        if (window.location.href.match(path)) {
            return;
        }
    }

    function formatTime(seconds) {
        const hours = Math.floor(seconds / 3600);
        const minutes = Math.floor((seconds % 3600) / 60);
        const remainingSeconds = seconds % 60;
        return {"hours": hours, "minutes": minutes, "seconds": remainingSeconds};
}
    function decodeString(str) {
        const bytes = new Uint8Array(str.split('').map(char => char.charCodeAt(0)));
        const decoder = new TextDecoder('utf-8');
        return decoder.decode(bytes);
    }

    const btn = document.createElement('button');
    btn.innerText = '🏆 Достижения';
    btn.style.position = 'fixed';
    btn.style.bottom = '20px';
    btn.style.fontWeight = 'bold';
    btn.style.right = '20px';
    btn.style.zIndex = '9999';
    btn.style.padding = '10px 15px';
    btn.style.background = '#9aa777';
    btn.style.color = '#1f1f1f';
    btn.style.border = 'none';
    btn.style.borderRadius = '10px';
    btn.style.cursor = 'pointer';
    btn.style.boxShadow = '0 2px 6px rgba(0,0,0,0.3)';
    document.body.appendChild(btn);

    const panel = document.createElement('div');
    panel.style.position = 'fixed';
    panel.style.bottom = '70px';
    panel.style.right = '20px';
    panel.style.width = '300px';
    panel.style.maxHeight = '400px';
    panel.style.overflowY = 'auto';
    panel.style.background = '#292828';
    panel.style.border = '1px solid #ccc';
    panel.style.borderRadius = '10px';
    panel.style.boxShadow = '0 4px 12px rgba(0,0,0,0.2)';
    panel.style.padding = '10px';
    panel.style.display = 'none';
    panel.style.zIndex = '10000';
    document.body.appendChild(panel);

    btn.addEventListener('click', () => {
        panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
    });

    const checkInterval = setInterval(function() {
        if (typeof window.some_achiv_str !== 'undefined') {
            clearInterval(checkInterval);

            try {
                const decoded = atob(window.some_achiv_str);

                const achievementsRegex = /this_anime_achievements.push\(\s*({[\s\S]*?})\s*\);/g;
                let match;
                const achievements = [];

                while ((match = achievementsRegex.exec(decoded)) !== null) {
                    let jsonString = match[1];
                    jsonString = jsonString.replace(/(js_preres_url \+ "(.*?)")/g, '"$2"');
                    jsonString = jsonString.replace(/[\r\n]/g, '').trim();
                    achievements.push(eval('(' + jsonString + ')'));
                }

                achievements.forEach(achievement => {
                    achievement.title = decodeString(achievement.title);
                    achievement.description = decodeString(achievement.description);
                });


                panel.innerHTML = '<h3 style="margin-top: 0;">🏆 Достижения которые можно получить</h3>';
                achievements.forEach(a => {
                    const item = document.createElement('div');
                    item.style.marginBottom = '10px';

                    const wheretime = formatTime(a.time_start);

                    const link = `${window.location.origin}${window.location.pathname}?t=${wheretime.hours}h${wheretime.minutes}m${wheretime.seconds}s`;


                    item.innerHTML = `
                        <strong style="color: white">${a.title}</strong><br>
                        <small style="color: white">${a.description}</small><br>
                        ${a.icon ? `<img src="${a.icon}" style="width: 50px; margin-top: 5px;">` : ''}
                        <a href="${link}" style="float: right; font-weight: bold; display: inline-block; margin-top: 10px; padding: 10px 15px; background: #9aa777; color: #1f1f1f; text-decoration: none; border-radius: 5px; text-align: center;">Перейти</a>
                        <hr>
                    `;


                    panel.appendChild(item);

                });

            } catch (error) {
                console.error('Ошибка при декодировании или выполнении кода:', error);
            }
        }
    }, 100);
})();