Update nightly.link buttons to 1.1
SPA-like page navigation is now handled
This commit is contained in:
parent
e2acd5235b
commit
35c7f30c14
|
@ -1,10 +1,9 @@
|
|||
// ==UserScript==
|
||||
// @name nightly.link buttons
|
||||
// @namespace blankie-scripts
|
||||
// @match http*://github.com/*/*/runs/*
|
||||
// @match http*://github.com/*/*/actions/runs/*
|
||||
// @match http*://github.com/*
|
||||
// @grant none
|
||||
// @version 1.0
|
||||
// @version 1.1
|
||||
// @author blankie
|
||||
// @run-at document-end
|
||||
// @description Show buttons to nightly.link on artifacts and build logs
|
||||
|
@ -12,12 +11,11 @@
|
|||
|
||||
const INSTANCE_URL = "https://nightly.link";
|
||||
|
||||
function pageUpdated() {
|
||||
console.log("awo");
|
||||
let artifactsDiv = document.evaluate(
|
||||
"//div[@class = 'mx-0 mx-md-1'][h4[@class = 'text-bold']][div[@class = 'color-fg-muted text-small']]", document)
|
||||
.iterateNext();
|
||||
if (artifactsDiv !== null) {
|
||||
function addArtifactsButton(artifactsDiv) {
|
||||
if (artifactsDiv === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let artifactsButton = document.createElement("a");
|
||||
artifactsButton.className = "btn";
|
||||
// https://stackoverflow.com/a/17228764
|
||||
|
@ -25,23 +23,49 @@ function pageUpdated() {
|
|||
artifactsButton.innerText = "View on nightly.link";
|
||||
artifactsButton.href = INSTANCE_URL + location.pathname;
|
||||
artifactsDiv.prepend(artifactsButton);
|
||||
}
|
||||
|
||||
let githubLogsButton = document.querySelector("a.js-steps-dropdown-raw-logs");
|
||||
let logsHeader = document.querySelector("div.js-checks-log-toolbar");
|
||||
return true;
|
||||
}
|
||||
|
||||
function addLogsButton(githubLogsButton, logsHeader) {
|
||||
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";
|
||||
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";
|
||||
logsHeader.append(logsLink);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function handleNewPage() {
|
||||
let artifactsDiv = document.body.querySelector("div#artifacts div.mx-0.mx-md-1");
|
||||
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);
|
||||
};
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: function properly on SPA-like navigation
|
||||
pageUpdated();
|
||||
let observer = new MutationObserver(observerCallback);
|
||||
observer.observe(document.body.parentNode, {childList: true});
|
Loading…
Reference in New Issue