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