Last active
January 7, 2026 02:29
-
-
Save shtrom/20aeb11b6b6c07f9b392786b4d01067b to your computer and use it in GitHub Desktop.
GitHub Lando linker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name GitHub Lando linker | |
| // @version 1 | |
| // @author Olivier Mehani <omehani@mozilla.com> | |
| // @downloadURL https://gist.github.com/shtrom/20aeb11b6b6c07f9b392786b4d01067b | |
| // @grant none | |
| // @match https://github.com/mozilla-firefox/firefox/* | |
| // @match https://github.com/mozilla-conduit/lando/* | |
| // @run-at document-idle | |
| // ==/UserScript== | |
| const logName = "GreaseMonkey GLL"; | |
| let debugLog = function() {} ; | |
| //debugLog = console.debug; | |
| const buttonLabels = [ | |
| "Squash and merge", | |
| "Merge pull request", | |
| ] | |
| function updateMergeButton() { | |
| let xpath = document.evaluate( | |
| '//button//span[contains(text(), "Squash and merge") \ | |
| or contains(text(), "Merge pull request") \ | |
| ]/ancestor::button', | |
| document, | |
| null, | |
| XPathResult.ANY_UNORDERED_NODE_TYPE, | |
| null); | |
| if (!xpath.singleNodeValue) { | |
| debugLog(logName + ": no button found"); | |
| return; | |
| } | |
| const mergeButton = xpath.singleNodeValue; | |
| // This is a Lando-supported repo. Disable in any case. | |
| mergeButton.disabled = true; | |
| xpath = document.evaluate( | |
| '//a[contains(text(), "View this pull request in Lando")]/@href', | |
| document, | |
| null, | |
| XPathResult.STRING_TYPE, | |
| null); | |
| if (!xpath.stringValue) { | |
| console.warning(logName + ": no Lando URL found"); | |
| return; | |
| } | |
| const landoURL = xpath.stringValue; | |
| const landoButton = document.createElement("button"); | |
| landoButton.classList = mergeButton.classList; | |
| landoButton.onclick= function() { window.open(landoURL); }; | |
| landoButton.textContent = "View in Lando"; | |
| landoButton.style.backgroundColor="orange"; | |
| //landoButton.style.color="black"; | |
| mergeButton.replaceWith(landoButton); | |
| } | |
| function callback (mutations) { | |
| updateMergeButton(); | |
| } | |
| let observer = new MutationObserver(callback); | |
| let observerOptions = { | |
| childList: true, | |
| subtree: true | |
| }; | |
| updateMergeButton(); | |
| observer.observe(document.body, observerOptions); | |
| console.info(logName + ": ready"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment