Update nightly.link buttons to version 1.2.1

- Fix viewing job logs
This commit is contained in:
blankie 2022-10-12 16:14:04 +07:00
parent 59fe815206
commit a0ffce4d6a
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 20 additions and 3 deletions

View File

@ -3,7 +3,7 @@
// @namespace blankie-scripts
// @match http*://github.com/*
// @grant none
// @version 1.2
// @version 1.2.1
// @author blankie
// @run-at document-end
// @description Show buttons to nightly.link on artifacts and build logs
@ -57,18 +57,35 @@ function addArtifactsButtonAndLinks(artifactsDiv) {
return true;
}
// 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) {
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\/*$/, "");
}
function addLogsButton(githubLogsButton, logsHeader) {
let logsUrl = INSTANCE_URL + getGithubJobsPath(logsHeader) + ".txt";
if (githubLogsButton !== null) {
let nightlyLogsButton = document.createElement("a");
nightlyLogsButton.className = "pl-5 dropdown-item btn-link";
nightlyLogsButton.innerText = "View logs on nightly.link";
nightlyLogsButton.href = INSTANCE_URL + location.pathname + ".txt";
nightlyLogsButton.href = logsUrl;
githubLogsButton.parentNode.append(nightlyLogsButton);
return true;
} else if (logsHeader !== null) {
let logsLink = document.createElement("a");
logsLink.innerText = "View on nightly.link";
logsLink.href = INSTANCE_URL + location.pathname + ".txt";
logsLink.href = logsUrl;
logsHeader.append(logsLink);
return true;
}