GitHub Actions to Nightly.link Redirector

Redirect GitHub Actions run pages to nightly.link for easy artifact downloads

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         GitHub Actions to Nightly.link Redirector
// @namespace    https://scirex.me
// @homepage     https://greasyfork.org/en/scripts/564578-github-actions-to-nightly-link-redirector
// @license      GPLv3
// @version      1.0
// @description  Redirect GitHub Actions run pages to nightly.link for easy artifact downloads
// @author       scirex
// @match        https://github.com/*/actions/runs/*
// @match        https://github.com/*/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    let lastUrl = '';
    let redirected = false;

    function checkAndRedirect() {
        const currentUrl = window.location.href;

        if (redirected) return;

        const actionsRunMatch = currentUrl.match(/^https:\/\/github\.com\/([^\/]+\/[^\/]+)\/actions\/runs\/(\d+)/);

        if (actionsRunMatch) {

            const repoPath = actionsRunMatch[1];
            const runId = actionsRunMatch[2];
            const nightlyUrl = `https://nightly.link/${repoPath}/actions/runs/${runId}`;
            redirected = true;
            window.location.replace(nightlyUrl);
        }
    }

    setTimeout(checkAndRedirect, 100);
    setTimeout(checkAndRedirect, 500);
    setTimeout(checkAndRedirect, 1000);
    setTimeout(checkAndRedirect, 2000);

    const observer = new MutationObserver(() => {
        const currentUrl = window.location.href;
        if (currentUrl !== lastUrl) {
            lastUrl = currentUrl;
            redirected = false;
            setTimeout(checkAndRedirect, 100);
            setTimeout(checkAndRedirect, 500);
        }
    });

    if (document.body) {
        observer.observe(document.body, { childList: true, subtree: true });
    } else {
        setTimeout(() => {
            if (document.body) {
                observer.observe(document.body, { childList: true, subtree: true });
            }
        }, 1000);
    }

    setInterval(() => {
        const currentUrl = window.location.href;
        if (currentUrl !== lastUrl && currentUrl.includes('/actions/runs/')) {
            lastUrl = currentUrl;
            redirected = false;
            checkAndRedirect();
        }
    }, 1000);

})();