Created
September 21, 2021 05:54
-
-
Save cyrusn/067dc463cf0482a8456ebe124fdd4ac1 to your computer and use it in GitHub Desktop.
bookmarklet to sort table in e journal system
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:(function sortTable(){ | |
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 date = matches[5]; | |
const time = matches[6]; | |
const year = new Date().getFullYear(); | |
const datetime = new Date(`${year}-${date} ${time}`); | |
stores.push([datetime, row]); | |
} | |
} | |
stores.sort(function(x,y){ | |
return x[0] - 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