Last active
February 12, 2018 13:22
-
-
Save havremunken/f2692a113d5f8d5eb85fab4d17515700 to your computer and use it in GitHub Desktop.
Et forsøk på litt fargehysteri
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
// ==UserScript== | |
// @name Fixrbkweb | |
// @version 1.0 | |
// @description Legg til ukedager i rbkweb.no sin kampoversikt | |
// @author Sinna mann | |
// @match http://www.rbkweb.no/kamper*.php | |
// @require http://code.jquery.com/jquery-latest.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Your code here... | |
var weekdays= ["Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør"]; | |
// Endre for å matche dine preferanser her | |
const colorResults = true, | |
colorNextMatch = true, | |
nextMatchColor = 'lightgreen', | |
winColor = '#AAFFAA', | |
drawColor = '#FFFFAA', | |
lossColor = '#FFAAAA'; | |
// Sannsynligvis ikke behov for å tukle med noe under denne linja | |
// Tegn vi vil bytte ut for å slippe å introdusere kjipe linjeskift | |
var replacements = { | |
' ': ' ', | |
'-': '‑' | |
}; | |
var year = document.URL.match(/rbkweb\.no\/kamper(\d\d\d\d)\.php/)[1]; | |
var now = new Date(); | |
var foundNext = false; | |
$("center > table > tbody > tr").has("td.kamp").each(function() { | |
var match = $(this).children("td:first-child").html().match(/(\d*)\/(\d*)/); | |
var myDateString = year + "-" + match[2] + "-" + match[1]; | |
var date = new Date(myDateString); | |
var myday = date.getDay(); | |
$(this).children("td:first-child").html(weekdays[myday] +" "+match[1]+"/"+match[2]); | |
var timeString = $(this).children("td").eq(3).text().match(/(\d\d):(\d\d)/); | |
if(colorNextMatch && timeString) { | |
var kampStart = new Date(myDateString + " " + timeString[1]+":"+timeString[2]); | |
var kampSlutt = new Date(kampStart); | |
kampSlutt.setMinutes(kampStart.getMinutes() + 105); | |
if(!foundNext && kampSlutt >= now) { | |
foundNext = true; | |
$(this).children("td").css('background-color', nextMatchColor); | |
} | |
} else if(colorResults) { | |
// Fargelegg resultater | |
var resultColor = "grey"; | |
var homeMatch = $(this).children("td").eq(1).text().startsWith("Rosenborg"); | |
var goals = $(this).children("td").eq(3).text().match(/(\d+)-(\d*)/); | |
if(goals) { | |
if(goals[1]==goals[2]) | |
resultColor = drawColor; | |
if(goals[1]>goals[2]) { | |
resultColor = homeMatch ? winColor : lossColor; | |
} | |
if(goals[1]<goals[2]) { | |
resultColor = homeMatch ? lossColor : winColor; | |
} | |
$(this).children("td").eq(3).css('background-color', resultColor); | |
} | |
} | |
// Fiks så ingen tabell-celler går over mer enn én linje. | |
$(this).children("td").each(function(){ | |
var element = $(this); | |
if(element.children("a").length > 0) | |
element = element.children("a"); | |
var content = element.html(); | |
for(var rep in replacements) { | |
content = content.replace(new RegExp(rep, "g"), replacements[rep]); | |
} | |
element.html(content); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jQueryfied quite a bit more, now doing updates for all table cells in a loop, and using object properties to define the replacement characters. Such clever.