Created
October 20, 2010 07:22
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
go to http://www.woot.com and paste the bookmarklet into your browser navigation bar (or, just use it as a bookmark).