Skip to content

Instantly share code, notes, and snippets.

@OlegIlyenko
Created September 24, 2013 14:25
Show Gist options
  • Save OlegIlyenko/6685576 to your computer and use it in GitHub Desktop.
Save OlegIlyenko/6685576 to your computer and use it in GitHub Desktop.
Highlights rows and cells as well as sums clicked cells
var src = 'https:' == location.protocol ? 'https':'http', script = document.createElement('script');
script.src = src+'://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
script.onload = function () {
var $ = jQuery;
var elem = $('<div>').text("0").css({position: 'fixed', top: 0, left: 0, width: 250, height: 40, backgroundColor: '#006699', borderBottomRightRadius: 7, color: 'white', padding: 9, fontWeight: 'bold', fontSize: '30px', boxShadow: "0 0px 20px 2px black"}).appendTo(document.body);
var sum = 0;
var count = 0;
$("table td").click(function () {
var cell = $(this);
try {
var num = parseInt(cell.text());
if (!cell.data('used')) {
sum = sum + num;
count = count + 1;
elem.text(sum + " (" + count + ")");
cell.css({backgroundColor: '#FFD9FF'});
cell.parent().css({fontWeight: 'bold', color: '#DA6EE6', textShadow: "1px 1px 5px rgba(150, 150, 150, 0.5)"});
cell.data('used', true)
} else {
sum = sum - num;
count = count - 1;
elem.text(sum + " (" + count + ")");
cell.css({backgroundColor: 'white'});
cell.parent().css({fontWeight: 'normal', color: 'black', textShadow: "none"});
cell.data('used', false);
}
} catch (e) {}
});
};
document.getElementsByTagName('body')[0].appendChild(script);
// Bookmark
// javascript:var src = 'https:' == location.protocol ? 'https':'http', script = document.createElement('script'); script.src = src+'://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'; script.onload = function () { var $ = jQuery; var elem = $('<div>').text("0").css({position: 'fixed', top: 0, left: 0, width: 250, height: 40, backgroundColor: '#006699', borderBottomRightRadius: 7, color: 'white', padding: 9, fontWeight: 'bold', fontSize: '30px', boxShadow: "0 0px 20px 2px black"}).appendTo(document.body); var sum = 0; var count = 0; $("table td").click(function () { var cell = $(this); try { var num = parseInt(cell.text()); if (!cell.data('used')) { sum = sum + num; count = count + 1; elem.text(sum + " (" + count + ")"); cell.css({backgroundColor: '#FFD9FF'}); cell.parent().css({fontWeight: 'bold', color: '#DA6EE6', textShadow: "1px 1px 5px rgba(150, 150, 150, 0.5)"}); cell.data('used', true) } else { sum = sum - num; count = count - 1; elem.text(sum + " (" + count + ")"); cell.css({backgroundColor: 'white'}); cell.parent().css({fontWeight: 'normal', color: 'black', textShadow: "none"}); cell.data('used', false); } } catch (e) {} }); }; document.getElementsByTagName('body')[0].appendChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment