Skip to content

Instantly share code, notes, and snippets.

@maxnordlund
Last active August 29, 2015 14:13
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 maxnordlund/632f04b423f8fc32c15d to your computer and use it in GitHub Desktop.
Save maxnordlund/632f04b423f8fc32c15d to your computer and use it in GitHub Desktop.
ASDG 2015 Schedule hack
// ==UserScript==
// @match https://gamesdonequick.com/schedule
// ==/UserScript==
(function(style){
var sheet, element = document.createElement("style")
document.head.appendChild(element)
sheet = element.sheet
Object.keys(style).forEach(function insertRule(selector, i) {
var rule = [selector + " {"],
declarations = style[selector]
Object.keys(declarations).forEach(function addDeclaration(property) {
rule.push("\t" + property + ": " + declarations[property] + ";")
})
rule.push("}")
sheet.insertRule(rule.join("\n"), i)
console.info(rule.join("\n"))
})
}) ({
"table tr > td:first-child": {
width: "12em"
},
"table.table tr > td": {
padding: "5px"
},
"thead > tr": {
position: "fixed",
left: 0,
top: 0,
width: "100%"
},
"table.table > tbody > tr > td.aired": {
"background-color": "darkgrey"
}
})
function forEach(selector, fn) {
Array.prototype.forEach.call(document.querySelectorAll(selector), fn)
}
forEach("tbody > tr:nth-child(2) > td", function adjustColumnWidth(td, i) {
var th
if (i === 0) return
th = document.querySelector("thead > tr > td:nth-child("+(i+1)+")")
th.style.width = "" + td.offsetWidth + "px"
console.info(th.textContent, th.offsetWidth)
})
function markAired() {
var now = Date.now()
forEach("tbody td:first-child:not([colspan])", function (td) {
if (new Date(td.textContent) < now) {
td.className = "aired"
}
})
}
markAired()
timer = setInterval(markAired, 5 * 60 * 1000) // Every 5 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment