Last active
June 5, 2022 17:27
-
-
Save NeoHBz/5028c5493fb68cb167235d2c074a138c to your computer and use it in GitHub Desktop.
Tampermoney script to show Fork Status (fork x commits ahead, y commits behind)
This file contains 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 Fork Details | |
// @namespace https://gist.github.com/NeoHBz/5028c5493fb68cb167235d2c074a138c | |
// @version 1.0 | |
// @description Displays if GitHub forks are behind/ahead from the parent fork | |
// @author NeoHBz | |
// @include https://github.com/*/*/network/members | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com | |
// @grant none | |
// ==/UserScript== | |
javascript:(function async() { | |
// lines below from here can also be pasted in Console for same effect | |
javascript:(async () => { | |
const sleep = ms => new Promise(r => setTimeout(r, ms)); | |
/* while on the forks page, collect all the hrefs and pop off the first one (original repo) */ | |
const aTags = [...document.querySelectorAll('div.repo a:last-of-type')].slice(1); | |
for (const aTag of aTags) { | |
/* fetch the forked repo as html, search for the "This branch is [n commits ahead,] [m commits behind]", print it directly onto the web page */ | |
await fetch(aTag.href) | |
.then(x => x.text()) | |
.then(html => aTag.outerHTML += `${html.match(/This branch is.*/).pop().replace('This branch is', '').replace(/([0-9]+ commits? ahead)/, '<font color="#0c0">$1</font>').replace(/([0-9]+ commits? behind)/, '<font color="red">$1</font>')}`) | |
.catch(console.error); | |
await sleep(500); | |
} | |
})(); | |
})(); |
Changelog
20220605:
- added: sleep function to avoid
error 429
; - added: namespace of this gist itself
- refactored: moved sleep function below the comment
PS: although the sleep function works as intended, I randomly entered 500ms duration for sleep, which can be experimented to a lower duration, hence resulting in a faster script;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
originally by p-mcgowan on this StackOverflow post
preview:
![image](https://user-images.githubusercontent.com/56602090/172059394-0fdf7093-6b42-429f-b137-6912b06e3705.png)