Skip to content

Instantly share code, notes, and snippets.

@cyrusn
Last active February 15, 2022 12:13
Show Gist options
  • Save cyrusn/8c55ff107fc95d31d420340a7b939ddf to your computer and use it in GitHub Desktop.
Save cyrusn/8c55ff107fc95d31d420340a7b939ddf to your computer and use it in GitHub Desktop.
bookmarklet to sort school journal by classcode
javascript:(function(){
let tables = document.getElementsByTagName("table");
for (let table of tables) {
let stores = [];
const rows = table.tBodies[0].children;
for (let row of rows) {
const rowValue = row.children[0].innerText;
const matches = rowValue.match(
/^ +(\S+) +(\S+) +(\S+|\d\S\s{2}\S+) +(\d{1,2}\/\d{1,2}) .+(\d{2}-\d{2}) +(\d{2}:\d{2})$/,
);
if (matches) {
const attendance = matches[4].split("/");
if (attendance[0] !== attendance[1])
row.style.cssText += "background-color: #f2dede;";
const classcode = matches[3];
stores.push([classcode, row]);
}
}
stores.sort(function (x, y) {
return x[0].localeCompare(y[0]);
});
for (var i = 0, len = stores.length; i < len; i++) {
table.appendChild(stores[i][1]);
}
stores = null;
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment