GitHub Actions to Nightly.link Redirector

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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);

})();