Skip to content

Instantly share code, notes, and snippets.

@tripflex
Forked from azoff/autodj.bookmarklet.js
Created August 1, 2011 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/1118655 to your computer and use it in GitHub Desktop.
Save tripflex/1118655 to your computer and use it in GitHub Desktop.
Turntable.fm DJ Script
javascript:(function(g,d,f){if(f)d.info("Session found:",f);else return d.warn("No session found!");var h={check:10,wait:500},b=g.autodj={api:g[f],available:function(a){return b.api.taken_dj_map[a]<0},spot:function(){return b.api.become_dj.data("spot")},become:function(a){b.api.callback("become_dj",a)},waiter:function(a){return function(){return b.available(a)?(b.become(a),a):(d.info("Waiting..."),-1)}},seated:function(a){return b.api.djs[a]&&b.api.djs[a][0]===b.api.myuserid},wait:function(a,c){var e=c!==void 0,
a=a||h.check,c=c||b.spot();b.seated(c)?d.warn("Spot",c,"taken!"):(e&&d.error("Spot",c,"missed. Restarting..."),d.info("Polling @",a,"ms"),b.check(a,b.waiter(c)))},check:function(a,c){setTimeout(function(){var e=c.call(b);e>0?(d.warn("Spot",e,"open..."),setTimeout(function(){b.wait(a,e)},h.wait)):b.check(a,c)},a)}}})(window,console,function(g,d,f,h,b,a,c,e,i,j,k){try{return g(d)[f](h)[b][a][c][e]()[i](j)[k]}catch(l){return null}}(jQuery,".invite_dj","data","events","click",0,"handler","toString","match",
/\{\s*(.+)\./,1));autodj.wait();
/*global window, console, jQuery */
(function(global, out, session){
if (!session) {
return out.warn("No session found!");
} else {
out.info("Session found:", session);
}
var config = { check: 10, wait: 500 },
dj = global.autodj = {
api: global[session],
available: function(spot) {
return dj.api.taken_dj_map[spot] < 0;
},
spot: function() {
return dj.api.become_dj.data("spot");
},
become: function(spot) {
dj.api.callback("become_dj", spot);
},
waiter: function(spot) {
return function() {
if (dj.available(spot)) {
dj.become(spot);
return spot;
} else {
out.info("Waiting...");
return -1;
}
};
},
seated: function(spot) {
return dj.api.djs[spot] && dj.api.djs[spot][0] === dj.api.myuserid;
},
wait: function(interval, spot) {
var reload = spot !== undefined;
interval = interval || config.check;
spot = spot || dj.spot();
if (dj.seated(spot)) {
out.warn("Spot", spot, "taken!");
} else {
if (reload) {
out.error("Spot", spot, "missed. Restarting...");
}
out.info("Polling @", interval, "ms");
dj.check(interval, dj.waiter(spot));
}
},
check: function(interval, waiter) {
setTimeout(function(){
var spot = waiter.call(dj);
if (spot > 0) {
out.warn("Spot", spot, "open...");
setTimeout(function(){
dj.wait(interval, spot);
}, config.wait);
} else {
dj.check(interval, waiter);
}
}, interval);
}
};
})(window, console, (function($,_t,u,r,n,t,a,b,l,e,fm){
try { return $(_t)[u](r)[n][t][a][b]()[l](e)[fm]; }
catch(fail) { return null; }
})(jQuery, ".invite_dj", "data", "events", "click", 0,
"handler", "toString", "match", /\{\s*(.+)\./, 1));
(function(g, d, f) {
if(f) d.info("Session found:", f);
else return d.warn("No session found!");
var h = {
check: 10,
wait: 500
},
b = g.autodj = {
api: g[f],
available: function(a) {
return b.api.taken_dj_map[a] < 0
},
spot: function() {
return b.api.become_dj.data("spot")
},
become: function(a) {
b.api.callback("become_dj", a)
},
waiter: function(a) {
return function() {
return b.available(a) ? (b.become(a), a) : (d.info("Waiting..."), -1)
}
},
seated: function(a) {
return b.api.djs[a] && b.api.djs[a][0] === b.api.myuserid
},
wait: function(a, c) {
var e = c !== void 0,
a = a || h.check,
c = c || b.spot();
b.seated(c) ? d.warn("Spot", c, "taken!") : (e && d.error("Spot", c, "missed. Restarting..."), d.info("Polling @", a, "ms"), b.check(a, b.waiter(c)))
},
check: function(a, c) {
setTimeout(function() {
var e = c.call(b);
e > 0 ? (d.warn("Spot", e, "open..."), setTimeout(function() {
b.wait(a, e)
}, h.wait)) : b.check(a, c)
}, a)
}
}
})(window, console, function(g, d, f, h, b, a, c, e, i, j, k) {
try {
return g(d)[f](h)[b][a][c][e]()[i](j)[k]
} catch(l) {
return null
}
}(jQuery, ".invite_dj", "data", "events", "click", 0, "handler", "toString", "match", /\{\s*(.+)\./, 1));
@pulleyrocks
Copy link

Looks like this is broken as of 8/16/11. Had been using the bookmarklet for the past couple weeks with Chrome and it worked like a dream. Starting this morning, it doesn't work. Nothing in my configuration or extensions has changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment