📜 ⬆️ ⬇️

"Durov, return the wall" or "Habrahabr + Geektimes + Megamind" in one tape



When Roskomnadzor raged and Habr divided for compelling reasons, a “younger brother” appeared who was not sorry for - Geektimes. I did not like this separation and I made for local use a small browser extension that displays Geektimes posts on Habré in one tape.

Yesterday, another division happened, Habr has a “cousin humanities” - Megamind. To add his tape to the general tape on Habré It was not difficult for me. Having seen the mood of users from all these divisions, I decided to share this extension, perhaps you will also find it more convenient to read Habr (in the old fashioned way).
')

The extension works only on tabs:

For registered "everything" - http://habrahabr.ru/feed/all/
For unregistered "best for the day" - http://habrahabr.ru/posts/top/daily/

The work is quite simple, when entering, two additional GET requests for geektimes and megamozg are made, posts are obtained and inserted between existing ones on Habré, sorted by time.

Synchronization with geektimes everything is pretty beautifully shown, and with megamozg while there are problems, due to the fact that there are quite a few posts per day, I soon think that everything will change.

Add to browser:



Who is interested in the source, here:

View code
var habr = { init: function() { var last = document.createElement('div'), published = document.createElement('div'); last.setAttribute('id', 'last_id'); last.setAttribute('class', 'post shortcuts_item'); last.setAttribute('style', 'display:none;'); published.setAttribute('class', 'published'); published.innerText = '20  2015  00:01'; last.appendChild(published); document.getElementsByClassName('posts')[0].appendChild(last); habr.feed('geektimes.ru'); }, feed: function(host) { var href = location.href; href = href.replace('habrahabr.ru/posts/top/daily/',host + '/interesting/'); href = href.replace('habrahabr.ru/feed',host); var xhr = new XMLHttpRequest(); xhr.open("GET", href, true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { var html = document.createElement('div'); html.innerHTML = xhr.responseText; var posts = html.getElementsByClassName('post'); for (var i = 0; i < posts.length; i++) { var post = document.createElement('div'); post.innerHTML = posts[i].innerHTML; var date = post.getElementsByClassName('published')[0].innerText; var postDate = habr.getDate(date); post.getElementsByClassName('title')[0].setAttribute('style','padding-right:71px;'); post.getElementsByClassName('favorite')[0].parentNode.removeChild(post.getElementsByClassName('favorite')[0]); post.getElementsByClassName('plus')[0].parentNode.removeChild(post.getElementsByClassName('plus')[0]); post.getElementsByClassName('minus')[0].parentNode.removeChild(post.getElementsByClassName('minus')[0]); habr.addChild(post.innerHTML, postDate, host, posts[i].id); if (i == posts.length-1 && host == 'geektimes.ru') { habr.feed('megamozg.ru'); } } } }; xhr.send(null); }, addChild: function(data, time, host, id) { var posts = document.getElementsByClassName('post'); for (var i = 0; i < posts.length; i++) { var date = posts[i].getElementsByClassName('published')[0].innerText; var postDate = habr.getDate(date); var postAdd = document.createElement('div'); postAdd.setAttribute('class', 'post shortcuts_item'); postAdd.setAttribute('id', id); postAdd.setAttribute('style', 'background:url("http://' + host + '/images/logo.svg") right top no-repeat; background-size: 71px;'); postAdd.innerHTML = data; if (time >= postDate) { document.getElementsByClassName('posts')[0].insertBefore(postAdd, document.getElementById(posts[i].id)); break; } } }, getDate: function(date) { var d = new Date(), dateYear, dateMonth, dateDay, dateHour, dateMin, dateMinSec, parseDate; if (date.indexOf('') + 1) { date = date.replace('  ', ''); dateMinSec = date.split(':'); dateYear = d.getFullYear(); dateMonth = d.getMonth(); dateDay = d.getDate(); dateHour = dateMinSec[0]; dateMin = dateMinSec[1]; } else if (date.indexOf('') + 1) { date = date.replace('  ', ''); dateMinSec = date.split(':'); dateYear = d.getFullYear(); dateMonth = d.getMonth(); dateDay = d.getDate()-1; dateHour = dateMinSec[0]; dateMin = dateMinSec[1]; } else { parseDate = /([0-9]{1,2})\s(|||||||||||)\s([0-9]{4})\s\s([0-9]{2}):([0-9]{2})/gi.exec(date); if (!parseDate) { parseDate = /([0-9]{1,2})\s(|||||||||||)\s\s([0-9]{2}):([0-9]{2})/gi.exec(date); dateYear = d.getFullYear(); dateDay = parseDate[1]; dateHour = parseDate[3]; dateMin = parseDate[4]; } else { dateYear = parseDate[3]; dateDay = parseDate[1]; dateHour = parseDate[4]; dateMin = parseDate[5]; } switch (parseDate[2]) { case '': dateMonth = 0; break; case '': dateMonth = 1; break; case '': dateMonth = 2; break; case '': dateMonth = 3; break; case '': dateMonth = 4; break; case '': dateMonth = 5; break; case '': dateMonth = 6; break; case '': dateMonth = 7; break; case '': dateMonth = 8; break; case '': dateMonth = 9; break; case '': dateMonth = 10; break; case '': dateMonth = 11; break; default : dateMonth = 0; } } return new Date(dateYear, dateMonth, dateDay, dateHour, dateMin); } }; habr.init(); 



PS: The author of extensionsapp is not a member of the Merry and Resourceful Club, because anyone who is generous with invites will always be happy to receive it and tell you about one rather interesting extension in one place.
Thank you, ragequit .

Sources on GitHub:
github.com/extensionsapp/habrahabr-chrome
github.com/extensionsapp/habrahabr-firefox

UPD 03/13/15: The link to Habré has changed. Everything has been fixed and works.
Now it works on 3 links:
http://habrahabr.ru/feed/interesting/ - interesting from your subscriptions.
http://habrahabr.ru/feed/all/ - everything from your subscriptions.
http://habrahabr.ru/all/ - everything.

If you want to read only Habrahabr and Geektimes, go to Megamind and uncheck all the hubs. Similar manipulations for the humanities.

UPD 09/09/15:
Installation of a monkey:
Violent monkey [Opera] , Greasemonkey [Firefox] , Tampermonkey [Chrome] , GreaseKit [Safari]

Then install the extension:
Click Row -> https://gist.github.com/extensionsapp/946a14d5c820d57ac7c4
or
Install Install -> https://openuserjs.org/scripts/extensionsapp/habrahabruserscript

UPD 08.16.17: Update script after redesign Habra.

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


All Articles