-
Notifications
You must be signed in to change notification settings - Fork 0
/
fluid_dock_badge_for_tumblr.js
43 lines (39 loc) · 1.12 KB
/
fluid_dock_badge_for_tumblr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// ==UserScript==
// @name Fluid Dock Badge for Tumblr
// @namespace http://fluidapp.com
// @description Display a dock badge for the Tumblr Dashboard with the number of new posts (works with Tumblr v5)
// @include *.tumblr.com/dashboard
// @author Benjamin Stein
// ==/UserScript==
if (!window.fluid) {
return;
}
try {
doBadgeUpdates(60000);
} catch(e) {
window.console.log(e);
}
/****************
This is the HTML from the Dashboard we need to parse
<div id="new_post_notice_container">
<a class="new_post_notice" title="3 new posts" href="/dashboard">
3
<img alt="" src="/images/new_post_alert_arrow.png"/>
</a>
</div>
*************/
function doBadgeUpdates(timeout) {
//just regex for a digit. easy!
updateBadge("new_post_notice_container", /(\d+)/);
setTimeout(doBadgeUpdates, timeout);
}
function updateBadge(id, new_post_regex) {
notice_divs = document.getElementById(id).getElementsByTagName('a');
if (notice_divs.length > 0) {
new_post_html = notice_divs[0].innerHTML;
count = new_post_regex.exec(new_post_html)[0];
window.fluid.dockBadge = count;
} else {
window.fluid.dockBadge = "";
}
}