Skip to content

Instantly share code, notes, and snippets.

@azoff
Created October 20, 2010 07:22
Show Gist options
  • Save azoff/635953 to your computer and use it in GitHub Desktop.
Save azoff/635953 to your computer and use it in GitHub Desktop.
A WootOff Watcher that uses AJAX and alerts to run right in your browser
javascript:(function(win,domain,$){var w={config:{interval:3000,alertOnNew:true,selector:".leadIn"},homePage:"http://"+domain+"/default.aspx ",init:function(){w.element=$(w.config.selector);w.fragment=w.homePage+w.config.selector;w.update();win.WootWatcher=w},getProduct:function(){return w.element.find("h2.fn").html()},isNewProduct:function(item){return w.lastProduct&&w.lastProduct!==item},update:function(){w.element.load(w.fragment,w.parse)},enqueue:function(){w.timeout=setTimeout(w.update,w.config.interval)},dequeue:function(){if(w.timeout){clearTimeout(w.timeout)}},parse:function(newProduct){newProduct=w.getProduct();if(w.isNewProduct(newProduct)){if(w.config.alertOnNew){alert(newProduct)}else{if(console){console.log(newProduct)}}}w.lastProduct=newProduct;w.enqueue()}};$(w.init)})(window,document.domain,jQuery);
/*global window, alert, jQuery, console */
(function (win, domain, $) {
var w = {
config: {
interval: 3000,
alertOnNew: true,
selector: '.leadIn'
},
homePage: 'http://' + domain + '/default.aspx ',
init: function () {
w.element = $(w.config.selector);
w.fragment = w.homePage + w.config.selector;
w.update();
win.WootWatcher = w;
},
getProduct: function () {
return w.element.find("h2.fn").html();
},
isNewProduct: function (item) {
return w.lastProduct && w.lastProduct !== item;
},
update: function () {
w.element.load(w.fragment, w.parse);
},
enqueue: function () {
w.timeout = setTimeout(w.update, w.config.interval);
},
dequeue: function () {
if (w.timeout) {
clearTimeout(w.timeout);
}
},
parse: function (newProduct) {
newProduct = w.getProduct();
if (w.isNewProduct(newProduct)) {
if (w.config.alertOnNew) {
alert(newProduct);
} else if (console) {
console.log(newProduct);
}
}
w.lastProduct = newProduct;
w.enqueue();
}
};
$(w.init);
})(window, document.domain, jQuery);
@azoff
Copy link
Author

azoff commented Nov 30, 2010

go to http://www.woot.com and paste the bookmarklet into your browser navigation bar (or, just use it as a bookmark).

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