📜 ⬆️ ⬇️

Separating the wheat from the chaff in Google Reader


Greasemonkey At work, I try not to read Habr and other thematic sites, they are too slow. You can spend all day reading articles, and at work so do nothing. But I also don’t want to miss something new and interesting, so I subscribe to various RSS feeds. After work, and more often on weekends, I open Google Reader and look through the entire list of accumulated posts. Some of them are written on topics of interest to me, others are not. It reminds me of reading emails, only incoming emails and spam fall into one folder.

At first I put up with it, but this weekend, using the Greasemonkey script, corrected the situation.


Google Reader Screenshot
')
A new button appeared in Google Reader: “Mark selected as read”, and each article has a checkbox.

Now, looking through the list of posts, I immediately mark the uninteresting for me and “read” them with one button. There are only those that deserve further careful study.

If you like the idea, you can install the Greasemonkey script. It requires Mozilla Firefox and the Greasemonkey extension.

Among the shortcomings worth noting the impossibility of the script in Google Chrome. The reason for this is the browser's error in handling the generated KeyboardEvent.

Just in case, publish the source code of the script:
// ==UserScript==
// @name Google Reader - Mark selected items as read
// @namespace twitter.com/rodiontsev
// @description This script adds a button "Mark selected as read" and checkbox for each item.
// @include htt*://www.google.tld/reader/view/*
// ==/UserScript==

/*
Version history

1.0 on 10/01/2009:
- Initial version.
*/

var buttonText = "Mark selected as read" ;
var buttonId = "mark-selected-as-read" ;
var articles = new Array();

document .addEventListener( "DOMNodeInserted" , function ( event ){nodeInserted( event );}, true );

function nodeInserted( event ) {
var entries = document .getElementById( "entries" );
if (entries && matchClass(entries, "list" )) {
var button = document .getElementById(buttonId);
if (!button) {
articles = new Array();
appendButton();
}

var element = event .target;
if (element. className && element.className.match(/entry\s+entry-\d+/) != null ) {
articles.push(element);

var checkbox = document .createElement( "input" );
checkbox.type = "checkbox" ;
checkbox.className = "mark-selected-as-read-checkbox-class" ;
checkbox.style.marginRight = "9px" ;
checkbox.style.verticalAlign = "top" ;
checkbox.addEventListener( "click" , function ( event ) { event .stopPropagation();}, true );
var entrySecondary = element.getElementsByClassName( "entry-secondary" )[0];
entrySecondary.insertBefore(checkbox, entrySecondary.firstChild);
}
}
}

function appendButton() {
var viewerTopControlsId = "viewer-top-controls" ;
var markAllAsReadId = "mark-all-as-read-split-button" ;

var divVewerTopControls = document .getElementById(viewerTopControlsId);
var btnMarkAllAsRead = document .getElementById(markAllAsReadId);

if ((divVewerTopControls != null ) && (btnMarkAllAsRead != null )) {
var button = document .createElement( "div" );
button.className = "goog-button goog-button-base unselectable goog-inline-block goog-button-float-left goog-button-tight scour-disabled viewer-buttons" ;
button.id = buttonId;
button.innerHTML = "<div class=\"goog-button-base-outer-box goog-inline-block\">"
+ "<div class=\"goog-button-base-inner-box goog-inline-block\">"
+ "<div class=\"goog-button-base-pos\">"
+ "<div class=\"goog-button-base-top-shadow\"> </div>"
+ "<div class=\"goog-button-base-content\">"
+ "<div class=\"goog-button-body\">" + buttonText + "</div>"
+ "</div>"
+ "</div>"
+ "</div>"
+ "</div>" ;
button.addEventListener( "click" , markSelectedAsRead, false );
divVewerTopControls.insertBefore(button, btnMarkAllAsRead);
}
}

function matchClass (element, sClassName) {
return (sClassName
&& element.className
&& element.className.length
&& element.className.match( new RegExp( "(^|\\s+)(" + sClassName + ")($|\\s+)" )));
}

function simulateClick(node) {
var event = node.ownerDocument.createEvent( "MouseEvents" );
event .initMouseEvent( "click" , true , true , window, 1, 0, 0, 0, 0, false , false , false , false , 0, null );
node.dispatchEvent( event );
}

function simulateKeypress(node, keyCode) {
var event = node.ownerDocument.createEvent( "KeyboardEvent" );
event .initKeyEvent( "keypress" , true , true , null , false , false , false , false , keyCode, 0);
node.dispatchEvent( event );
}

function simulateRead(node) {
simulateKeypress(node, 77); //"m" button - mark entry as read.
}

function simulateCollapse(node) {
simulateKeypress(node, 79); //"o" button - expand/collapse entry.
}

function getArticleIcon(article) {
var divs = article.getElementsByTagName( "div" );
for ( var i = 0; i < divs.length; i++) {
var div = divs[i];
if (matchClass(div, "entry-icons" )) return div;
}
return null ;
}

function markSelectedAsRead() {
var container = document .getElementById( "entries" );
container.style.display = "none" ;
for ( var i = 0; i < articles.length; i++) {
var article = articles[i];
var checkbox = article.getElementsByTagName( "input" )[0];
if (checkbox. checked ) {
if (!(matchClass(article, "read" ))) {
var articleIcon = getArticleIcon(article);
simulateClick(articleIcon);
if (!(matchClass(article, "read" ))) {
simulateRead(articleIcon);
}
if (matchClass(article, "expanded" )) {
simulateCollapse(articleIcon);
}
}
checkbox. checked = false ;
}
}
container.style.display = "block" ;
}

* This source code was highlighted with Source Code Highlighter .

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


All Articles