Skip to content

Instantly share code, notes, and snippets.

@jasonkeene
Last active December 30, 2015 20:39
Show Gist options
  • Save jasonkeene/7882292 to your computer and use it in GitHub Desktop.
Save jasonkeene/7882292 to your computer and use it in GitHub Desktop.
A simple bookmarklet to add an alert feature to bitcoinwisdom.com :)
interval_id = high = low = null
ticker = $ '#price'
alert_url = 'http://www.angelfire.com/ut/jlpicard/images/picalert.wav'
start = ->
do nodes.stop.show
do nodes.start.hide
interval_id = setInterval ->
current_price = parseFloat do ticker.text
unless high > current_price > low
window.open alert_url
do stop
console.log "current: #{current_price}, high: #{high}, low: #{low}"
, 1000
stop = ->
do nodes.stop.hide
do nodes.start.show
if interval_id?
clearInterval interval_id
interval_id = null
update_values = ->
high = parseFloat do nodes.high.val
low = parseFloat do nodes.low.val
alert_url = do nodes.alert.val
nodes = do ->
left_bar = $ '#leftbar'
context = $ """<div style="padding: 3px 7px;">
High: <input type="text" id="high" style="width: 45px;">
Low: <input type="text" id="low" style="width: 45px;"><br>
Alert URL: <input type="text" id="alert_url" style="width: 100px;"><br>
<input type="button" id="start" value="&#9654; Start">
<input type="button" id="stop" value="&#9724; Stop">
</div>"""
nodes =
high: $ '#high', context
low: $ '#low', context
alert: $ '#alert_url', context
start: $ '#start', context
stop: $ '#stop', context
# init values
current_price = parseFloat do ticker.text
nodes.high.val high ? current_price * 1.05
nodes.low.val low ? current_price * 0.95
nodes.alert.val alert_url
do nodes.stop.hide
# event handlers
nodes.start.click start
nodes.start.click update_values
nodes.stop.click stop
nodes.high.change update_values
nodes.low.change update_values
nodes.alert.change update_values
# write to the dom
do left_bar.empty
left_bar.append context
nodes
javascript:(function(){var e,t,n,r,i,s,o,u,a;n=t=r=null;u=$("#price");e="http://www.angelfire.com/ut/jlpicard/images/picalert.wav";s=function(){i.stop.show();i.start.hide();return n=setInterval(function(){var n;n=parseFloat(u.text());if(!(t>n&&n>r)){window.open(e);o()}return console.log("current: "+n+", high: "+t+", low: "+r)},1e3)};o=function(){i.stop.hide();i.start.show();if(n!=null){clearInterval(n);return n=null}};a=function(){t=parseFloat(i.high.val());r=parseFloat(i.low.val());return e=i.alert.val()};i=function(){var n,f,l;l=$("#leftbar");n=$('<div style="padding: 3px 7px;">\n High: <input type="text" id="high" style="width: 45px;">\n Low: <input type="text" id="low" style="width: 45px;"><br>\n Alert URL: <input type="text" id="alert_url" style="width: 100px;"><br>\n <input type="button" id="start" value="&#9654; Start">\n <input type="button" id="stop" value="&#9724; Stop">\n</div>');i={high:$("#high",n),low:$("#low",n),alert:$("#alert_url",n),start:$("#start",n),stop:$("#stop",n)};f=parseFloat(u.text());i.high.val(t!=null?t:f*1.05);i.low.val(r!=null?r:f*.95);i.alert.val(e);i.stop.hide();i.start.click(s);i.start.click(a);i.stop.click(o);i.high.change(a);i.low.change(a);i.alert.change(a);l.empty();l.append(n);return i}()}).call(this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment