Skip to content

Instantly share code, notes, and snippets.

@vsemozhetbyt
Last active May 11, 2017 15:07
Show Gist options
  • Save vsemozhetbyt/d21811a61ab35a44f7d8b92e3c46c5ee to your computer and use it in GitHub Desktop.
Save vsemozhetbyt/d21811a61ab35a44f7d8b92e3c46c5ee to your computer and use it in GitHub Desktop.
Check if comment authors in PRs are Node.js collaborators
javascript: {
getCollaboratorsUsernames();
function getCollaboratorsUsernames() {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://github.com/nodejs/node/blob/master/README.md', true);
xhr.responseType = 'document';
xhr.withCredentials = true;
xhr.onload = markAuthorsLinks;
xhr.ontimeout = xhr.onerror = (evt) => { console.log(evt); };
xhr.send(null);
}
function markAuthorsLinks(evt) {
const xhrDoc = evt.target.response;
const collaboratorsUsernames = Array.from(
xhrDoc.body.querySelectorAll('h3 + ul > li > a[href^="https://github.com/"]'),
link => link.textContent.trim()
);
const authorsLinks = [...document.body.querySelectorAll('a[href].author')];
authorsLinks.forEach((link) => {
link.style.backgroundColor =
collaboratorsUsernames.includes(link.textContent.trim()) ?
'LightGreen' : 'LightGray';
});
}
}
@vsemozhetbyt
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment