Update nightly.link buttons to version 1.2

- Links to artifact files can now be retrieved without leaving the page
- Use Javascript's strict mode
This commit is contained in:
blankie 2022-09-02 23:13:41 +07:00
parent 35c7f30c14
commit b535a4aeeb
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 35 additions and 5 deletions

View File

@ -3,18 +3,24 @@
// @namespace blankie-scripts // @namespace blankie-scripts
// @match http*://github.com/* // @match http*://github.com/*
// @grant none // @grant none
// @version 1.1 // @version 1.2
// @author blankie // @author blankie
// @run-at document-end // @run-at document-end
// @description Show buttons to nightly.link on artifacts and build logs // @description Show buttons to nightly.link on artifacts and build logs
// ==/UserScript== // ==/UserScript==
"use strict";
const INSTANCE_URL = "https://nightly.link"; const INSTANCE_URL = "https://nightly.link";
function addArtifactsButton(artifactsDiv) { function addArtifactsButtonAndLinks(artifactsDiv) {
if (artifactsDiv === null) { if (artifactsDiv === null) {
return false; return false;
} }
let header = artifactsDiv.querySelector("div.mx-0.mx-md-1");
if (header === null) {
return false;
}
let artifactsButton = document.createElement("a"); let artifactsButton = document.createElement("a");
artifactsButton.className = "btn"; artifactsButton.className = "btn";
@ -22,7 +28,31 @@ function addArtifactsButton(artifactsDiv) {
artifactsButton.style.float = "right"; artifactsButton.style.float = "right";
artifactsButton.innerText = "View on nightly.link"; artifactsButton.innerText = "View on nightly.link";
artifactsButton.href = INSTANCE_URL + location.pathname; artifactsButton.href = INSTANCE_URL + location.pathname;
artifactsDiv.prepend(artifactsButton); 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);
}
return true; return true;
} }
@ -46,10 +76,10 @@ function addLogsButton(githubLogsButton, logsHeader) {
} }
function handleNewPage() { function handleNewPage() {
let artifactsDiv = document.body.querySelector("div#artifacts div.mx-0.mx-md-1"); let artifactsDiv = document.body.querySelector("div#artifacts");
let githubLogsButton = document.body.querySelector("a.js-steps-dropdown-raw-logs"); let githubLogsButton = document.body.querySelector("a.js-steps-dropdown-raw-logs");
let logsHeader = document.body.querySelector("div.js-checks-log-toolbar"); let logsHeader = document.body.querySelector("div.js-checks-log-toolbar");
addArtifactsButton(artifactsDiv) || addLogsButton(githubLogsButton, logsHeader); addArtifactsButtonAndLinks(artifactsDiv) || addLogsButton(githubLogsButton, logsHeader);
}; };
handleNewPage(); handleNewPage();