benfoxall / benfoxall.github.com

BLOG!
benjaminbenben.com
6 stars 6 forks source link

Alert Ben when he's on the wrong Github account #70

Closed omgmog closed 3 years ago

omgmog commented 3 years ago

I couldn't think of a good place to home this issue, so this is where it now lives.

@benfoxall said:

Oh man 🤦 I really need some plugin that tells me "You're @benfoxbotica"

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?

omgmog commented 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');

What does this do???

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: image

omgmog commented 3 years ago

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:

benfoxall commented 3 years ago

image

… coming at you from @benfoxall 💥

💅 like a professional person

@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?

omgmog commented 3 years ago

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