-
-
Save Melonbwead/5a3e05024dce1aa704b45bc0a690cb5c to your computer and use it in GitHub Desktop.
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:%28function%28%29%7Bfunction e%28e%2Ct%29%7Bvar n%3Dnew Date%280%29%3Breturn n.setHours%28e%29%2Cn.setMinutes%28t%29%2Cn%7Dfunction t%28e%2Ct%2Cn%29%7Bfunction a%28e%29%7Bvar t%3Breturn Math.floor%28Math.abs%28e%2F60%29%29%2B"%3A"%2B%28%28t%3DMath.floor%28Math.abs%28e%29%2560%29%29<10%3F"0"%2Bt.toString%28%29%3At.toString%28%29%29%7Dvar r%3D0%3Bfor%28i%3D0%3Bi%2B1<e.length%3Bi%2B%3D2%29%7Bvar l%3De%5Bi%5D%3Br%2B%3D%28%28s%3De%5Bi%2B1%5D%29.getTime%28%29-l.getTime%28%29%29%2F6e4%7Dvar o%3D0%3Bfor%28i%3D1%3Bi%2B1<e.length%3Bi%2B%3D2%29%7Bvar s%3De%5Bi%5D%3Bo%2B%3D%28%28l%3De%5Bi%2B1%5D%29.getTime%28%29-s.getTime%28%29%29%2F6e4%7Do<30%26%26%28r-%3D30-o%2Co%3D30%29%3Bvar c%3D450-r%2Cg%3D%28c>0%3F"-"%3A"%2B"%29%2Ba%28c%29%2Cu%3D"Leave at%3A "%2Bnew Date%28t.getTime%28%29%2B6e4%2Ac%29.toLocaleTimeString%28"en-GB"%2C%7Bhour%3A"2-digit"%2Cminute%3A"2-digit"%7D%29%2B" %28"%2Bg%2B"%29"%2Cm%3Dn-c%3Breturn%7BnewBalanceString%3A%28m>-.001%3F""%3A"-"%29%2Ba%28m%29%2CnewClockingsString%3Au%7D%7Dfunction n%28e%2Ct%2Cn%29%7B%7Dvar a%3Ddocument.getElementsByClassName%28"ace-balance__flexi-today"%29%5B0%5D.innerText%2Cr%3Da.replace%28%2FToday%3A %7CIn%3A%7COut%3A%2Fg%2C""%29.split%28" "%29%2Cl%3D%5B%5D%3Br.forEach%28t%3D>%7Bvar n%3Dt.split%28"%3A"%29%2Ca%3De%28n%5B0%5D%2Cn%5B1%5D%29%3Bl.push%28a%29%7D%29%3Bvar o%3Dnew Date%3Bl.push%28e%28o.getHours%28%29%2Co.getMinutes%28%29%29%29%3Bvar s%3Ddocument.getElementsByClassName%28"ace-balance__flexi-balance"%29%5B0%5D.innerText%2Cc%3Ds.split%28"%3A"%29%2Cg%3D60%2A%2Bc%5B0%5D%2B %2Bc%5B1%5D%2C%7BnewBalanceString%3Au%2CnewClockingsString%3Am%7D%3Dt%28l%2Co%2Cg%29%3Bdocument.getElementsByClassName%28"ace-balance__flexi-balance"%29%5B0%5D.innerText%3Du%2Cdocument.getElementsByClassName%28"ace-balance__flexi-today"%29%5B0%5D.innerText%3Dm%3B%7D%29%28%29%3B | |
javascript: (function () { | |
function makeDate(hours, mins) { | |
var date = new Date(0); | |
date.setHours(hours); | |
date.setMinutes(mins); | |
return date; | |
} | |
function calculateFlexitime(times, now, currentBalanceMins) { | |
function toTimeString(mins) { | |
function pad(d) { | |
return (d < 10) ? '0' + d.toString() : d.toString(); | |
} | |
var hoursString = Math.floor(Math.abs(mins / 60)); | |
var minsString = pad(Math.floor(Math.abs(mins) % 60)); | |
return hoursString + ":" + minsString; | |
} | |
var minsWorked = 0; | |
for (i = 0; i + 1 < times.length; i += 2) { | |
var timeIn = times[i]; | |
var timeOut = times[i + 1]; | |
minsWorked += (timeOut.getTime() - timeIn.getTime()) / (60 * 1000); | |
} | |
var minsOnBreak = 0; | |
for (i = 1; i + 1 < times.length; i += 2) { | |
var timeOut = times[i]; | |
var timeIn = times[i + 1]; | |
minsOnBreak += (timeIn.getTime() - timeOut.getTime()) / (60 * 1000); | |
} | |
if (minsOnBreak < 30) { | |
var wastedBreak = 30 - minsOnBreak; | |
minsWorked -= wastedBreak; | |
minsOnBreak = 30; | |
//console.log("break Wasted:" + new Date(wastedBreak)) | |
} | |
var minsLeft = (7 * 60 + 30) - minsWorked; | |
var timeLeftsignedString = (minsLeft > 0 ? "-" : "+") + toTimeString(minsLeft) | |
//debugger; | |
var leaveAt = new Date(now.getTime() + (minsLeft) * (60 * 1000)) | |
//var leaveAtString = leaveAt.getHours() + ":" + pad(Math.round(leaveAt.getMinutes())) | |
var newClockingsString = "Leave at: " + leaveAt.toLocaleTimeString("en-GB", { hour: '2-digit', minute: '2-digit' }) + " (" + timeLeftsignedString + ")" | |
var newBalanceMins = currentBalanceMins - minsLeft | |
var newBalanceString = (newBalanceMins > -0.001 ? "" : "-") + toTimeString(newBalanceMins) | |
return { newBalanceString, newClockingsString }; | |
} | |
function assertEquals(actual, expected, line) { | |
if (expected != actual) { | |
console.log(line + "\nexpected: \"" + expected + "\"\nactual : \"" + actual + "\""); | |
} | |
} | |
var timeText = document.getElementsByClassName("ace-balance__flexi-today")[0].innerText; | |
var timeStrings = timeText.replace(/Today: |In:|Out:/g, "").split(" "); | |
var times = []; | |
timeStrings.forEach(timeString => { | |
var timeParts = timeString.split(':'); | |
var time = makeDate(timeParts[0], timeParts[1]); | |
times.push(time); | |
}); | |
var now = new Date(); | |
times.push(makeDate(now.getHours(), now.getMinutes())); | |
var currentBalanceString = document.getElementsByClassName("ace-balance__flexi-balance")[0].innerText; | |
var currentBalanceStringParts = currentBalanceString.split(":"); | |
var currentBalanceMins = +currentBalanceStringParts[0] * 60 + +currentBalanceStringParts[1]; | |
//debugger; | |
var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// console.log(newBalanceString) | |
// console.log(newClockingsString) | |
document.getElementsByClassName("ace-balance__flexi-balance")[0].innerText = newBalanceString | |
document.getElementsByClassName("ace-balance__flexi-today")[0].innerText = newClockingsString | |
// var now = makeDate(17, 00); | |
// // var times = [makeDate(9,0), makeDate(12,0), now] | |
// var times = [makeDate(9, 00), makeDate(12, 00), makeDate(12, 30), now] | |
// currentBalanceMins = 0 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 17:00 (+0:00)", "newClockingsString: 9 till 5") | |
// assertEquals(newBalanceString, "0:00", "newBalanceString: 9 till 5") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(9, 01), makeDate(12, 00), makeDate(12, 00), now] | |
// currentBalanceMins = 0 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 17:01 (-0:01)", "newClockingsString: 9:01 start") | |
// assertEquals(newBalanceString, "-0:01", "newBalanceString: 9:01 start") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(8, 59), makeDate(12, 00), makeDate(12, 00), now] | |
// currentBalanceMins = 0 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 16:59 (+0:01)", "newClockingsString: 8:59 start") | |
// assertEquals(newBalanceString, "0:01", "newBalanceString: 8:59 start") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(9, 00), makeDate(12, 01), makeDate(12, 30), now] | |
// currentBalanceMins = 0 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 17:00 (+0:00)", "newClockingsString: 12:01 lunch") | |
// assertEquals(newBalanceString, "0:00", "newBalanceString: 12:01 lunch") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(9, 00), makeDate(11, 59), makeDate(12, 30), now] | |
// currentBalanceMins = 0 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 17:01 (-0:01)", "newClockingsString: 11:59 lunch") | |
// assertEquals(newBalanceString, "-0:01", "newBalanceString: 11:59 lunch") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(9, 00), makeDate(12, 00), makeDate(12, 31), now] | |
// currentBalanceMins = 0 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 17:01 (-0:01)", "newClockingsString: 12:31 lunch end") | |
// assertEquals(newBalanceString, "-0:01", "newBalanceString: 12:31 lunch end") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(9, 00), makeDate(12, 00), makeDate(12, 29), now] | |
// currentBalanceMins = 0 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 17:00 (+0:00)", "newClockingsString: 12:29 lunch end") | |
// assertEquals(newBalanceString, "0:00", "newBalanceString: 12:29 lunch end") | |
// var now = makeDate(17, 01); | |
// var times = [makeDate(9, 00), makeDate(12, 00), makeDate(12, 30), now] | |
// currentBalanceMins = 0 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 17:00 (+0:01)", "newClockingsString: 17:01 now") | |
// assertEquals(newBalanceString, "0:01", "newBalanceString: 17:01 now") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(9, 00), makeDate(12, 00), makeDate(12, 00), now] | |
// currentBalanceMins = 0 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 17:00 (+0:00)", "newClockingsString: no lunch") | |
// assertEquals(newBalanceString, "0:00", "newBalanceString: no lunch") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(9, 00), makeDate(12, 00), makeDate(14, 00), now] | |
// currentBalanceMins = 0 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 18:30 (-1:30)", "newClockingsString: 2 hr lunch") | |
// assertEquals(newBalanceString, "-1:30", "newBalanceString: 2 hr lunch") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(9, 00), makeDate(12, 00), makeDate(12, 30), now] | |
// currentBalanceMins = 90 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 17:00 (+0:00)", "newClockingsString: 1:30 existing balance") | |
// assertEquals(newBalanceString, "1:30", "newBalanceString: 1:30 existing balance") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(9, 00), makeDate(12, 00), makeDate(12, 30), now] | |
// currentBalanceMins = -90 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 17:00 (+0:00)", "newClockingsString: -1:30 existing balance") | |
// assertEquals(newBalanceString, "-1:30", "newBalanceString: -1:30 existing balance") | |
// var now = makeDate(17, 00); | |
// var times = [makeDate(8, 59), makeDate(12, 00), makeDate(12, 30), now] | |
// currentBalanceMins = 90 | |
// var { newBalanceString, newClockingsString } = calculateFlexitime(times, now, currentBalanceMins); | |
// assertEquals(newClockingsString, "Leave at: 16:59 (+0:01)", "newClockingsString: 1:30 existing balance 8:59 start") | |
// assertEquals(newBalanceString, "1:31", "newBalanceString: 1:30 existing balance 8:59 start") | |
})(); | |
//https://skalman.github.io/UglifyJS-online/ | |
//https://www.urlencoder.org/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment