Closed omgmog closed 3 years ago
Okay you can use this with your userscript manager of choice (e.g. Tampermonkey) and it should work...
((h,i,b,e,n,f)=>{
h.querySelector(i).addEventListener(b, (_) => {
// if we're commenting on something outside of oxbotica...
let checkURL = window.location.href.indexOf(n) == -1;
let checkUser = h.querySelector('[name=octolytics-actor-login]').getAttribute('content') == f;
if (checkURL && checkUser) {
let _d = h.querySelector(`#${e}`);
if (!_d) {
let d = h.createElement('div');
d.id = e;
d.innerText = `You are @${f}!`;
d.setAttribute('style', 'text-align: center; padding: 1em; font-weight: bold; color: red;')
_.target.parentElement.appendChild(d);
}
}
});
})(document,'#new_comment_field','focus','benwarning', 'oxbotica', 'benfoxbotica');
If you're on a repo that is on a URL that doesn't contain oxbotica
, and your username is benfoxbotica
this will add a warning below the comment field when you focus it
Here's sort of how that will look:
This could probably be improved to support all sorts of .comment-form-textarea
to cover PR comments and other inline things, rather than just issue comments :shrug:
@omgmog, this is AWESOME, and so useful!!
Thank you so so much.
The code is beautiful too, I particularly dig the ((h,i,b,e,n,f)=>{
minification.
I installed tampermonkey to run it, are there better options? Do you use userscripts alot?
Yeah Tampermonkey would be my go to.
I used to use userscripts a lot more, then I started moving things over to extensions, then I started using Safari on my MacBook and so don't use anything
I couldn't think of a good place to home this issue, so this is where it now lives.
@benfoxall said:
You could totally do this with a browser extension or userscript!
I'd recommend doing something like looking at the org/user/repo you're about to comment in and see if it mentions a certain redacted org name or not, if it doesn't and you're currently using the wrong account (scrape the DOM to determine this maybe?) then either inject something in the DOM, or fire an alert when you try to submit a comment?