Skip to content

Instantly share code, notes, and snippets.

@alexey-sh
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexey-sh/c4ced1e023e037298f1a to your computer and use it in GitHub Desktop.
Save alexey-sh/c4ced1e023e037298f1a to your computer and use it in GitHub Desktop.
awesome salary features
var awesomeScripts = [
'https://cdn.rawgit.com/alexey-sh/c4ced1e023e037298f1a/raw/86e493d5607c81bc2bab7c51cbd9ae8bb7f238ef/gistfile1.js',
'https://cdn.rawgit.com/alexey-sh/c4ced1e023e037298f1a/raw/3c2af38c2a0acadf94a032c506b7292c390468c7/gistfile1.js'
];
awesomeScripts.forEach(function (src) {
$('body').append($('<script>').attr('src', src));
});
(function () {
if (location.href.indexOf('com/wage') === -1 || location.search) {
return;
}
script = document.createElement('script');
script.onload = render;
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js';
document.querySelector('body').appendChild(script);
function render () {
$('.widget-content .table-detail-view').each(function () {
var table = $(this);
var canvas = $('<canvas>');
canvas.css({
width: table.width() / 2 + 'px',
height: table.width() / 4 + 'px',
display: 'block',
margin: '1em auto'
})
table.after(canvas);
var labels = [];
table.find('th a').each(function () { labels.push($(this).text());})
var wages = [];
table.find('td').each(function () { wages.push(parseFloat($(this).text()));});
var overage = wages.reduce(function (a,b) { return a + b; }, 0) / wages.length;
table.find('thead th').append($('<div>').text('~ ' + overage.toFixed(2)))
var data = {
labels: labels.reverse(),
datasets: [
{
label: "",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: wages.reverse()
}
]
};
var chat = new Chart(canvas.get(0).getContext("2d")).Line(data);
});
}
})();
(function () {
function parseTime(el) {
var time = $.trim(el.text().replace('/', '')).split(':');
return {
hours: parseInt(time[0], 10),
minutes: parseInt(time[1], 10)
};
}
function fillZero(x) {
x = x.toString();
if (x.length === 1) {
x = '0' + x;
}
return x;
}
function prettyTime() {
var items = [].map.call(arguments, function (arg) {
return fillZero(arg.hours) + ':' + fillZero(arg.minutes)
});
return items.join(' / ');
}
function featurizeTime() {
$('.offlinetime:not(.featurized)').each(function () {
var el = $(this);
var cell = el.parent();
var offline = parseTime(el);
var online = parseTime(cell);
var total = {
hours: offline.hours + online.hours,
minutes: offline.minutes + online.minutes
};
if (total.minutes >= 60) {
total.hours += Math.floor(total.minutes / 60);
total.minutes = total.minutes % 60;
}
var txt = prettyTime(online, offline, total);
cell.text(txt).addClass('featurized');
});
}
var target = document.querySelector('.table-container');
if (!target) {
return;
}
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length !== 0) {
setTimeout(featurizeTime, 0);
}
});
});
var config = {childList: true};
observer.observe(target, config);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment