Created
December 31, 2014 19:28
-
-
Save WouterG/5ab6961371ad87419114 to your computer and use it in GitHub Desktop.
top2000
This file contains 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
// ==UserScript== | |
// @name My Fancy New Userscript | |
// @namespace http://your.homepage/ | |
// @version 0.1 | |
// @description enter something useful | |
// @author You | |
// @match http://www.radio2.nl/top2000* | |
// @grant none | |
// ==/UserScript== | |
var Scroller = function() { | |
this.started = false; | |
this.scrollGoal = -1; | |
this.speed = 50; | |
this.scrollGoalPos = -1; | |
this.ospeed = 1; | |
var that = this; | |
this.getToGo = function() { | |
if (that.scrollGoal == -1) { | |
return 0; | |
} | |
return Math.abs(that.scrollGoal - window.scrollY); | |
}; | |
this.updateSpeed = function() { | |
if (that.scrollGoal != -1) { | |
if (that.getToGo() >= 200) { | |
if (that.getToGo() > 1000) { | |
if (that.ospeed < 10) { | |
that.ospeed += 1; | |
} | |
if (that.speed > 5) { | |
that.speed -= 5; | |
} else if (that.speed > 1) { | |
that.speed -= 1; | |
} | |
} else if (that.speed > 1) { | |
that.speed -= 0.25; | |
} | |
} | |
if (that.getToGo() < 200) { | |
if (that.speed < 50) { | |
that.speed += 0.25; | |
} | |
if (that.getToGo() < 500 && that.ospeed > 1) { | |
that.ospeed -= 1; | |
} | |
} | |
} else { | |
that.speed = 50; | |
} | |
}; | |
this.update = function() { | |
if (that.scrollGoal != -1) { | |
that.updateSpeed(); | |
if (that.scrollGoal < window.scrollY) { | |
window.scrollBy(0, -that.ospeed); | |
} else if (that.scrollGoal > window.scrollY) { | |
window.scrollBy(0, that.ospeed); | |
} else { | |
that.scrollGoal = -1; | |
} | |
} | |
setTimeout(that.update, that.speed); | |
}; | |
this.start = function() { | |
if (that.started) { | |
return; | |
} | |
that.started = true; | |
that.update(); | |
} | |
this.scrollToPosition = function(p) { | |
var elements = $('.t2klist.fn-itemcontainer')[0].children; | |
var found = false; | |
that.scrollGoalPos = p; | |
for (var i = 0; i < elements.length; i++) { | |
if (elements[i].getAttribute('index') != p && elements[i].children[0].className == 'grey') { | |
elements[i].children[0].className = ''; | |
} else if (elements[i].getAttribute('index') == p && elements[i].children[0].className != 'grey') { | |
elements[i].children[0].className = 'grey'; | |
if (i < 10) { | |
var scroll = 38 * (10 - i) * -1; | |
that.scrollGoal = window.scrollY + scroll; | |
} | |
found = true; | |
} | |
} | |
if (!found) { | |
var lowest = parseInt(elements[0].getAttribute('index')); | |
var g = parseInt(p); | |
var scroll = 38 * Math.abs(lowest - g); | |
if (g < lowest) { | |
scroll*=-1; | |
} | |
that.scrollGoal = (window.scrollY + scroll) - 380; | |
} | |
}; | |
}; | |
window.scroller = new Scroller(); | |
window.scroller.start(); | |
setInterval(function() { | |
$.getJSON('http://www.radio2.nl/data/t2k_lists/nowplaying.json', function(d) { | |
var currentNr = parseInt(d[1][2014]); | |
var current = (currentNr - 1).toString(); | |
window.current = current; | |
window.scroller.scrollToPosition(current); | |
}); | |
}, 5000); | |
window.getTimeleftString = function() { | |
function fix(v, l) { | |
while (v.length < l) { | |
v = '0' + v; | |
} | |
return v; | |
}; | |
var hotelCaliforniaLength = /* (((6 * 60) + 30) * 1000) */ 0; | |
var end = new Date('January 1, 2015 00:00:00'); | |
end.setTime(end.getTime() - hotelCaliforniaLength); | |
var diff = end.getTime() - (new Date()).getTime(); | |
var days = Math.floor(diff / (1000 * 60 * 60 * 24)); | |
diff -= days * (1000 * 60 * 60 * 24); | |
var hours = Math.floor(diff / (1000 * 60 * 60)); | |
diff -= hours * (1000 * 60 * 60); | |
var mins = Math.floor(diff / (1000 * 60)); | |
diff -= mins * (1000 * 60); | |
var seconds = Math.floor(diff / (1000)); | |
diff -= seconds * (1000); | |
var milliseconds = diff; | |
return days.toString() + ":" + | |
fix(hours.toString(), 2) + ":" + | |
fix(mins.toString(), 2) + ":" + | |
fix(seconds.toString(), 2); | |
} | |
var timebox = document.createElement('div'); | |
window.timebox = timebox; | |
$(timebox) | |
.css('left', '50%') | |
.css('bottom', '0px') | |
.css('margin-left', '-150px') | |
.css('position', 'fixed') | |
.css('background','rgb(0, 0, 0)') | |
.css('width', '300px') | |
.css('height', '56px') | |
.css('color', '#CCC') | |
.css('text-align', 'center') | |
.css('font-size', '60px'); | |
document.getElementsByTagName('body')[0].appendChild(timebox); | |
setInterval(function() { | |
var s = window.getTimeleftString(); | |
window.timebox.innerHTML = '<br />' + s; | |
}, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment