Permalink
Browse files

Adding the chrome extension.

  • Loading branch information...
1 parent c0b2f1f commit dec6e4509a8b752b8a87bac59a601d7a3f670ab8 @sherbondy committed May 28, 2011
View
@@ -1,10 +1,8 @@
Tumblr Notifier
================
-This is an Extension for Safari 5.
-If you want to see its guts, check out global.html.
-latest_post.js is an injected script that simply extracts the ID of the most recent post in your Tumblr Dashboard when you visit the site. The rest of the time, Notifier just queues Tumblr's [Dashboard API](http://www.tumblr.com/docs/en/api#api_dashboard).
+This is a browser Extension for Safari and Google Chrome.
+If you want to see its guts, check out global.html in either folder.
+latest_post.js/contentscript.js is an injected script that simply extracts the script location that Tumblr's abacus uses to check for new posts.
-Email addresses and passwords are stored as secure settings.
-
-If you're interested in modifying the extension, I suggest you sign up for the [Safari Developer Program](http://developer.apple.com/safari/) and get a Signing Certificate.
+If you're interested in modifying the extension, I suggest you sign up for the [Safari Developer Program](http://developer.apple.com/safari/) and get a Signing Certificate.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<script type="text/javascript">
+
+const ba = chrome.browserAction;
+const tumblr_url = 'http://www.tumblr.com/dashboard';
+
+// RATE: how frequently the dashboard API is polled (in milliseconds)
+const RATE = 1000*60;
+
+var interval = setInterval(checkForPosts, RATE);
+
+
+function isTumblrUrl(url) {
+ if (url.indexOf(tumblr_url) != 0) return false;
+ return true;
+}
+
+ba.onClicked.addListener(function(tab) {
+ chrome.tabs.getAllInWindow(undefined, function(tabs) {
+ for (var i = 0, tab; tab = tabs[i]; i++) {
+ if (tab.url && isTumblrUrl(tab.url)) {
+ chrome.tabs.update(tab.id, {selected: true});
+ return;
+ }
+ }
+ /* Open Tumblr's dashboard in a new tab
+ when a user clicks the Toolbar Item. */
+
+ chrome.tabs.create({url: tumblr_url});
+
+ });
+});
+
+function update_new_post_count(count) {
+ // check if it's a bona-fide number
+ if (parseFloat(count) == parseInt(count)) {
+ localStorage.unread_count = count;
+ console.log(localStorage.unread_count);
+
+ if (count > 0) {
+ ba.setBadgeText({text:localStorage.unread_count});
+ } else {
+ ba.setBadgeText({text:''});
+ }
+ }
+}
+
+// This almost identical to Tumblr's check_for_new_posts function
+
+function checkForPosts() {
+ if (localStorage.script_src && localStorage.unread_count <= 100) {
+ document.body.innerHTML = '';
+ var script_include = document.createElement('script');
+ script_include.setAttribute('type', 'text/javascript');
+ script_include.setAttribute('src', localStorage.script_src + '?' + new Date().getTime());
+ document.body.appendChild(script_include);
+ } else {
+ localStorage.unread_count = 0;
+ console.log('Must visit Tumblr to set source.');
+ }
+}
+
+chrome.extension.onRequest.addListener(function(the_src, sender, sendResponse) {
+ if (the_src.length > 0) {
+ localStorage.script_src = the_src;
+ console.log('Script src set to: ' + localStorage.script_src);
+ update_new_post_count(0);
+ }
+});
+
+</script>
+
+</head>
+<body>
+ <script type="text/javascript">
+ // Called in the body to ensure the dom is ready.
+ checkForPosts();
+ </script>
+</body>
+</html>
+
@@ -0,0 +1,7 @@
+var content = document.getElementById('content');
+var the_script = content.getElementsByTagName('script')[0];
+var re = new RegExp('(http://.+.js)');
+var the_src = re.exec(the_script.innerHTML);
+if (the_src) {
+ chrome.extension.sendRequest(the_src[1]);
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,20 @@
+{
+ "name": "Tumblr Notifier",
+ "version": "1.0",
+ "description": "Find out when new posts appear in your Tumblr Dashboard.",
+ "permissions": [
+ "tabs",
+ "http://www.tumblr.com/dashboad"
+ ],
+ "background_page": "background.html",
+ "browser_action": {
+ "default_icon": "t.png",
+ "default_title": "Tumblr Notifier"
+ },
+ "content_scripts": [
+ {
+ "matches": ["http://www.tumblr.com/dashboard"],
+ "js": ["contentscript.js"]
+ }
+ ]
+}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dec6e45

Please sign in to comment.