Created
October 8, 2011 16:42
-
-
Save syranez/1272521 to your computer and use it in GitHub Desktop.
the-kenny braucht Hauptmensa sonst weint er.
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
javascript:var kenny=function(a,b){a=typeof a==="string"&&a.length!==0&&a||"";b=b||false;Date.prototype.monthToDigits=function c(){return this.getMonth()+1<10?"0"+(this.getMonth()+1):this.getMonth()+1};Date.prototype.mcn_getWeekDay=function d(a){return a===undefined?null:new Date(this.getTime()-(this.getDay()-a)*864e5)};Date.prototype.mcn_getWeeksMonday=function e(){return this.mcn_getWeekDay(1)};Date.prototype.mcn_getWeeksFriday=function f(){return this.mcn_getWeekDay(5)};Date.prototype.dayToDigits=function g(){return this.getDate()<10?"0"+this.getDate():this.getDate()};return{getUri:function(){var c=new Date;var d=c.getDay();if(b){if(d===0){c=new Date(c.getTime()+864e5)}else if(d===6){c=new Date(c.getTime()+864e5*2)}}var e=c.mcn_getWeeksMonday();var f=c.mcn_getWeeksFriday();return a+e.dayToDigits()+e.monthToDigits()+"-"+f.dayToDigits()+f.monthToDigits()+".htm"}}}("http://studentenwerk.essen-duisburg.de/speiseplaene/hm_",false);document.location=kenny.getUri(); |
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
var kenny = (function(host, showNextWeek) { | |
host = (typeof host === "string" && host.length !== 0 && host) || ""; | |
showNextWeek = showNextWeek || false; | |
var dayInSeconds = 864e5; | |
Date.prototype.monthToDigits = function monthToDigits () { | |
return ((this.getMonth() + 1) < 10 ? "0" + (this.getMonth() + 1) : (this.getMonth() + 1)); | |
} | |
Date.prototype.mcn_getWeekDay = function mcn_getWeekDay (weekday) { | |
return ((weekday === undefined) ? null : new Date(this.getTime() - ((this.getDay() - weekday) * dayInSeconds))); | |
} | |
Date.prototype.mcn_getWeeksMonday = function getWeeksMonday () { | |
return this.mcn_getWeekDay(1); | |
} | |
Date.prototype.mcn_getWeeksFriday = function getWeeksFriday () { | |
return this.mcn_getWeekDay(5); | |
} | |
Date.prototype.dayToDigits = function dayToDigits () { | |
return (this.getDate() < 10 ? "0" + this.getDate() : this.getDate()); | |
} | |
return { | |
getUri: function () { | |
var date = new Date(); | |
if (showNextWeek) { | |
var day = date.getDay(); | |
if (day === 0) { | |
date = new Date(date.getTime() + dayInSeconds); | |
} else if (day === 6) { | |
date = new Date(date.getTime() + (dayInSeconds*2)); | |
} | |
} | |
var monday = date.mcn_getWeeksMonday(); | |
var friday = date.mcn_getWeeksFriday(); | |
return host + monday.dayToDigits() + monday.monthToDigits() + "-" + friday.dayToDigits() + friday.monthToDigits() + ".htm"; | |
} | |
}; | |
})("http://studentenwerk.essen-duisburg.de/speiseplaene/hm_", false); |
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
<html> | |
<head> | |
<script src="https://gist.github.com/raw/1272521/6d4e9afdac5b3fac768a481458ed5a213995d9f0/gistfile1.js"></script> | |
<script type="text/javascript"> | |
function test () { | |
var result = kenny.getUri(); | |
document.getElementById("result").textContent = result; | |
}; | |
</script> | |
</head> | |
<body> | |
<span onclick="test()">Click Me or I will kill someones kitten!</span> | |
<span id="result"></span> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use it with
document.location = kenny.getUri();
as bookmarklet.