📜 ⬆️ ⬇️

Karma extension for Google Chrome

Hello to all!



Immediately link to the impatient: http://bit.ly/habrauser
')
The popup opens by clicking, you can go to the user’s page either by clicking the middle button (opens in the background tab) or on the username in the popup.

Under the cut there are some details for those interested.

Prehistory


I have been reading Habr for a long time, about 6 years, and it always remained for me something like this ... a high light. I didn’t have my own account, because registration was by invitation only, I didn’t know anyone and therefore I felt small and insignificant.

However, once I had accumulated some knowledge that I couldn’t find in Runet and I decided that it was a good reason to try my luck on a habr. I was warmly received, though not fervently. I deserve an invite, shared knowledge, hurray! I was a little surprised that I can vote only a limited number of times and therefore I carefully hid the appeared couple of votes.

As time went on, articles became more and more, I increasingly read Habr logged in. And then I noticed that my voices were completely gone. I felt sad. “Where do people get their voices from?”, I thought. “So many votes have been spent on comments, on karma! And I am out of this stream, I can’t even click! ”And yes, I did not read the help at that time =)

Not so long ago, I had the opportunity to publish my second post translation. He was somewhat interested in people and I acquired some positive karma. Thank! Together with tsvetkovpa we figured out how it all worked out, smoked man, I realized that the number of votes depends on karma and the restriction is only daily. Well, that clarifies!

I began to show signs of severe hablability.

Hablability


Read Habr I became noticeably harder. I read even most of the comments, watched and voted in the tracker. However, something bothered me a lot. If you can vote for comments so easily, then why can't I vote for karma as easily? Do I have to go to another page? Sorry, this is somehow not human!

I poked into all the existing extensions, found something similar, but it turned out to be karma-readonly, and in general somehow did not make me happy (to the author without offense, this is IMHO).

Maybe I was looking badly, but the thirst for the invention of bicycles took over.

Bicycles


For a couple of evenings, I threw a working code. Since the API has a habrahabra, ahem, let's say, not very rich (the only thing that was found ), I had to have crutches. jQuery, on('click') , voila! It was necessary to pull out the page of a juzverej entirely through GET request (by the way, I didn’t get anywhere from this), cache and isolate pieces of habrainformation on my own, and manage styles. For karma-voting on the Habré, the function is responsible, as you have guessed, karma_vote() and it really needs a user ID, which is not shown anywhere else in this function.

I piled on classes, methods, ayaksovs and already started to even think about backbone.

A little later, I decided to check something: can we do without bicycles? Since I’m pulling so much, why not just insert the entire user header? Oh, how wonderful it was! And with this, and styles, and onclik, everything pulled itself out! Lepot, it's a pity that the habr js is not arranged, it stretches into pieces on demand and the styles / logic of the user page are only on this page and are present. Well, okay, no problem. There are a few styles, I simply banned them and connect them via content-cc; Voting code decided to just inject from the very habr to the bottom of the page.

 var script = document.createElement('script'); script.type = "text/javascript"; script.src = src; document.body.appendChild(script); 

Haha Thumbs up!

This started the optimization.

Optimization


I sawed out all the classes, all the self-made layout. It turned out so little that I was ashamed that for this I force the page to once again execute the jQuery code. How many are there already? Damn it, should every extension in chrome really attract jQuery? Maybe there is some kind of sharpened? It's time to make it built-in! Of course, you can do without it, but do not want to.

Yes, and Habr himself uses jQuery! But ... maybe it can somehow be used?

I dug a little Internet on this topic and realized that I don’t have one, from the extensions with the DOM pages only, and it won't take me a ride on the back of the script loaded with habr = (

Well, okay, move away from the content scripts, what about inject? Since I can touch the DOM with my hands, then why don't I just push the extension core there? And the page will launch it. I tried:

 script.text = "console.log(jQuery().jquery);"; 

Oops, it works! We get rid of jQuery in the package, create a loader and now Habr carefully executes my code!

 (function (chrome) { var request = new XMLHttpRequest(), urlToMain = chrome.extension.getURL('js/main.js'), script; request.open('GET', urlToMain, false); request.send(null); script = document.createElement('script'); script.type = "text/javascript"; script.text = request.responseText; document.body.appendChild(script); }(chrome)); 

Result


Slightly drank styles, compressing them and the output code, I got what you see.




Thank you for reading! I hope the extension is useful to someone else besides myself =)

I apologize to those whom I spotted in the screenshots, I needed experimental subjects! =) I thought that Habr is a country that is still friendly and free, but I can also ignore it, if it really hinders.

At the end I would like to ask a habrakomuyuniti a couple of questions:

Have a nice day!

Source: https://habr.com/ru/post/151589/


All Articles