Permalink
Browse files

commit whole extension

  • Loading branch information...
1 parent fdaa179 commit 449f2e5f3f55d8edcdc9cc39d6714e19d3245510 Fran committed Aug 20, 2011
Showing with 200 additions and 0 deletions.
  1. +18 −0 background.html
  2. BIN icon.png
  3. +19 −0 manifest.json
  4. +163 −0 mark.js
View
18 background.html
@@ -0,0 +1,18 @@
+<html>
+ <head>
+ <script>
+ // Called when the url of a tab changes.
+ function checkForValidUrl(tabId, changeInfo, tab) {
+ var gr_exp = /google.*\/reader/;
+ // If the user is viewing GReader
+ if (gr_exp.test(tab.url)) {
+ // show the page action.
+ chrome.pageAction.show(tabId);
+ }
+ }
+
+ // Listen for any changes to the URL of any tab.
+ chrome.tabs.onUpdated.addListener(checkForValidUrl);
+ </script>
+ </head>
+</html>
View
BIN icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
19 manifest.json
@@ -0,0 +1,19 @@
+{
+ "name": "Mark as read",
+ "version": "1.0",
+ "description": "To mark as read individual items on GReader",
+ "background_page": "background.html",
+ "page_action": {
+ "default_icon": "icon.png",
+ "default_title": "Mark As Read for Google Reader",
+ },
+ "permissions": [
+ "tabs", "http://*/*"
+ ],
+ "content_scripts": [
+ {
+ "matches": ["http://www.google.es/reader/*","http://www.google.com/reader/*"],
+ "js": ["mark.js"]
+ }
+ ]
+}
View
163 mark.js
@@ -0,0 +1,163 @@
+
+/*
+ Mark As Read for Google Reader (Chrome Extension)
+ @author franverona (adapted from Greasemonkey script developed by Dmity Rodiontsev)
+ @version 1.0
+*/
+
+/*
+
+ Version history:
+ Agoust 2011 - Extension created and also added "Invert selection" button
+
+*/
+
+var buttonText = "Mark as Read";
+var buttonId = "mark-selected-as-read";
+var articles = new Array();
+
+var buttonTextInv = "Invert Selection";
+var buttonIdInv = "invert-select";
+var articlesInv = 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\">&nbsp;</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);
+
+ var buttonInv = document.createElement("div");
+ buttonInv.className = "goog-button goog-button-base unselectable goog-inline-block goog-button-float-left goog-button-tight scour-disabled viewer-buttons";
+ buttonInv.id = buttonId;
+ buttonInv.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\">&nbsp;</div>"
+ + "<div class=\"goog-button-base-content\">"
+ + "<div class=\"goog-button-body\">" + buttonTextInv + "</div>"
+ + "</div>"
+ + "</div>"
+ + "</div>"
+ + "</div>";
+ buttonInv.addEventListener("click", invertSelection, false);
+ divVewerTopControls.insertBefore(buttonInv, 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.initKeyboardEvent("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 invertSelection(){
+ var container = document.getElementById("entries");
+ for (var i = 0; i < articles.length; i++) {
+ var article = articles[i];
+ var checkbox = article.getElementsByTagName("input")[0];
+ checkbox.checked = !checkbox.checked;
+ }
+}
+
+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")) {
+ simulateClick(articleIcon);
+ console.info('match_expanded: '+i);
+ }
+ }
+ checkbox.checked = false;
+ }
+ }
+ container.style.display = "block";
+}

0 comments on commit 449f2e5

Please sign in to comment.