RunPod Show Stop Pod Button. RunPod Larger Logs

RunPod 添加 Stop Pod 按钮。RunPod Log 页面放大

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         RunPod Show Stop Pod Button. RunPod Larger Logs
// @namespace    http://tampermonkey.net/
// @version      2024-12-24
// @description  RunPod 添加 Stop Pod 按钮。RunPod Log 页面放大
// @author       Ganlv
// @match        https://www.runpod.io/console/*
// @icon         https://www.runpod.io/favicon.ico
// @grant        GM_addStyle
// @grant        unsafeWindow
// @license      MIT
// ==/UserScript==
 
(function () {
    'use strict';
 
    GM_addStyle(`
.css-fm445e {
    align-items: initial;
}
body > div.MuiDialog-root.MuiModal-root > div.MuiDialog-container.MuiDialog-scrollPaper > div.css-1f59w55 {
    max-width: initial;
    height: 100%;
}
#modal-root .w-full.sm\\:max-w-\\[40rem\\] {
    max-width: 120rem;
}
#modal-root .sm\\:min-h-\\[60dvh\\] {
    min-height: 95dvh;
}
`);
 
    setInterval(() => {
        document.querySelectorAll('span[aria-label="More Actions"][id^="pod-button-"]').forEach((el) => {
            const podId = el.id.replace('pod-button-', '');
            if (el?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement?.querySelector('.MuiLabel-success') && el?.parentElement?.parentElement?.lastElementChild?.textContent !== 'Stop Pod') {
                const span = document.createElement('span');
                span.textContent = 'Stop Pod';
                span.classList.add('custom-stop-pod-button');
                span.style.display = 'flex';
                span.style.marginLeft = '9px';
                span.style.padding = '6px 13.5px';
                span.style.alignItems = 'center';
                span.style.color = '#ffffff';
                span.style.backgroundColor = '#ff0000';
                span.style.borderRadius = '10px';
                span.style.fontWeight = 'bold';
                span.style.fontSize = '0.8125rem';
                span.style.fontFamily = 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"';
                span.style.lineHeight = '1.5';
                span.style.textDecoration = 'none';
                span.style.cursor = 'pointer';
                span.addEventListener('click', () => {
                    if (confirm(`Are you sure to stop pod ID: ${podId}?`)) {
                        fetch('https://api.runpod.io/graphql', {
                            method: 'POST',
                            headers: {
                                'Authorization': `Bearer ${unsafeWindow.Clerk.session.lastActiveToken.jwt.claims.__raw}`,
                                'Content-Type': 'application/json',
                                'X-Team-Id': unsafeWindow.localStorage.getItem('selectedTeam'),
                            },
                            body: JSON.stringify({
                                operationName: 'stopPod',
                                query: 'mutation stopPod($input: PodStopInput!) { podStop(input: $input) { id desiredStatus lastStatusChange } }',
                                variables: {
                                    input: {
                                        podId: podId,
                                    }
                                },
                            }),
                            referrer: 'https://www.runpod.io/',
                            referrerPolicy: 'strict-origin-when-cross-origin',
                            mode: 'cors'
                        }).then(res => res.json()).then(res => {
                            console.log(res);
                            document.querySelector('button[aria-label="Refresh"]')?.click();
                        });
                    }
                });
                el?.parentElement?.parentElement?.insertAdjacentElement('beforeend', span);
            }
        });
    }, 1000);
})();