2022-07-02 08:25:24 +00:00
|
|
|
// ==UserScript==
|
|
|
|
// @name nightly.link buttons
|
|
|
|
// @namespace blankie-scripts
|
2022-09-01 13:28:33 +00:00
|
|
|
// @match http*://github.com/*
|
2022-07-02 08:25:24 +00:00
|
|
|
// @grant none
|
2022-10-12 09:20:22 +00:00
|
|
|
// @version 1.2.2
|
2022-07-02 08:25:24 +00:00
|
|
|
// @author blankie
|
|
|
|
// @run-at document-end
|
|
|
|
// @description Show buttons to nightly.link on artifacts and build logs
|
|
|
|
// ==/UserScript==
|
|
|
|
|
2022-09-02 16:13:41 +00:00
|
|
|
"use strict";
|
|
|
|
|
2022-07-02 08:25:24 +00:00
|
|
|
const INSTANCE_URL = "https://nightly.link";
|
|
|
|
|
2022-09-02 16:13:41 +00:00
|
|
|
function addArtifactsButtonAndLinks(artifactsDiv) {
|
2022-09-01 13:28:33 +00:00
|
|
|
if (artifactsDiv === null) {
|
|
|
|
return false;
|
2022-07-02 08:25:24 +00:00
|
|
|
}
|
2022-09-02 16:13:41 +00:00
|
|
|
let header = artifactsDiv.querySelector("div.mx-0.mx-md-1");
|
|
|
|
if (header === null) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-02 08:25:24 +00:00
|
|
|
|
2022-09-01 13:28:33 +00:00
|
|
|
let artifactsButton = document.createElement("a");
|
|
|
|
artifactsButton.className = "btn";
|
|
|
|
// https://stackoverflow.com/a/17228764
|
|
|
|
artifactsButton.style.float = "right";
|
|
|
|
artifactsButton.innerText = "View on nightly.link";
|
|
|
|
artifactsButton.href = INSTANCE_URL + location.pathname;
|
2022-09-02 16:13:41 +00:00
|
|
|
header.prepend(artifactsButton);
|
|
|
|
|
|
|
|
for (let artifactDiv of artifactsDiv.querySelectorAll("tbody > tr > td > div")) {
|
|
|
|
let artifactIcon = artifactDiv.querySelector("span.mr-2");
|
|
|
|
let artifactNode = artifactDiv.querySelector("span.text-bold");
|
|
|
|
if (artifactIcon === null || artifactNode === null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let artifactName = artifactNode.textContent.trim();
|
|
|
|
let artifactUrl = INSTANCE_URL + location.pathname + "/" + artifactName + ".zip";
|
|
|
|
|
|
|
|
let newArtifactLink = document.createElement("a");
|
|
|
|
newArtifactLink.text = artifactName;
|
|
|
|
newArtifactLink.href = artifactUrl;
|
|
|
|
newArtifactLink.className = "text-bold no-underline Link--primary";
|
|
|
|
artifactNode.replaceWith(newArtifactLink);
|
|
|
|
|
|
|
|
let newArtifactIcon = document.createElement("a");
|
|
|
|
newArtifactIcon.className = artifactIcon.className;
|
|
|
|
newArtifactIcon.href = artifactUrl;
|
|
|
|
for (let child of artifactIcon.children) {
|
|
|
|
newArtifactIcon.appendChild(child);
|
|
|
|
}
|
|
|
|
artifactIcon.replaceWith(newArtifactIcon);
|
|
|
|
}
|
2022-09-01 13:28:33 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-10-12 09:14:04 +00:00
|
|
|
// https://github.com/EbookFoundation/free-programming-books/actions/runs/3213752190/jobs/5253657996
|
|
|
|
// https://github.com/kotatogram/kotatogram-desktop/actions/runs/3231502508/jobs/5291098845
|
|
|
|
function getGithubJobsPath(logsHeader) {
|
2022-10-12 09:20:22 +00:00
|
|
|
if (logsHeader === null) {
|
|
|
|
// https://github.com/the-blank-x/furry-guide/actions/runs/2613813876
|
|
|
|
return location.pathname;
|
|
|
|
}
|
2022-10-12 09:14:04 +00:00
|
|
|
let timestampElement = logsHeader.querySelector(".CheckRun-header-timestamp");
|
|
|
|
if (timestampElement === null) {
|
|
|
|
return location.pathname;
|
|
|
|
}
|
|
|
|
let headerUrl = timestampElement.getAttribute("data-url");
|
|
|
|
if (headerUrl === null) {
|
|
|
|
return location.pathname;
|
|
|
|
}
|
|
|
|
let jobLogsUrl = new URL(headerUrl, location);
|
|
|
|
return jobLogsUrl.pathname.replace(/\/header\/*$/, "");
|
|
|
|
}
|
|
|
|
|
2022-09-01 13:28:33 +00:00
|
|
|
function addLogsButton(githubLogsButton, logsHeader) {
|
2022-10-12 09:14:04 +00:00
|
|
|
let logsUrl = INSTANCE_URL + getGithubJobsPath(logsHeader) + ".txt";
|
|
|
|
|
2022-07-02 08:25:24 +00:00
|
|
|
if (githubLogsButton !== null) {
|
|
|
|
let nightlyLogsButton = document.createElement("a");
|
|
|
|
nightlyLogsButton.className = "pl-5 dropdown-item btn-link";
|
|
|
|
nightlyLogsButton.innerText = "View logs on nightly.link";
|
2022-10-12 09:14:04 +00:00
|
|
|
nightlyLogsButton.href = logsUrl;
|
2022-07-02 08:25:24 +00:00
|
|
|
githubLogsButton.parentNode.append(nightlyLogsButton);
|
2022-09-01 13:28:33 +00:00
|
|
|
return true;
|
2022-07-02 08:25:24 +00:00
|
|
|
} else if (logsHeader !== null) {
|
|
|
|
let logsLink = document.createElement("a");
|
|
|
|
logsLink.innerText = "View on nightly.link";
|
2022-10-12 09:14:04 +00:00
|
|
|
logsLink.href = logsUrl;
|
2022-07-02 08:25:24 +00:00
|
|
|
logsHeader.append(logsLink);
|
2022-09-01 13:28:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleNewPage() {
|
2022-09-02 16:13:41 +00:00
|
|
|
let artifactsDiv = document.body.querySelector("div#artifacts");
|
2022-09-01 13:28:33 +00:00
|
|
|
let githubLogsButton = document.body.querySelector("a.js-steps-dropdown-raw-logs");
|
|
|
|
let logsHeader = document.body.querySelector("div.js-checks-log-toolbar");
|
2022-09-02 16:13:41 +00:00
|
|
|
addArtifactsButtonAndLinks(artifactsDiv) || addLogsButton(githubLogsButton, logsHeader);
|
2022-09-01 13:28:33 +00:00
|
|
|
};
|
|
|
|
handleNewPage();
|
|
|
|
|
|
|
|
function observerCallback(mutationList, observer) {
|
|
|
|
for (mutation of mutationList) {
|
|
|
|
if (mutation.type !== "childList") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (node of mutation.addedNodes) {
|
|
|
|
if (node.nodeName === "BODY") {
|
|
|
|
handleNewPage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-07-02 08:25:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 13:28:33 +00:00
|
|
|
let observer = new MutationObserver(observerCallback);
|
|
|
|
observer.observe(document.body.parentNode, {childList: true});
|