Last active
February 8, 2018 16:52
-
-
Save Eruperu/30354d89f56c49793ee6d4595e187f85 to your computer and use it in GitHub Desktop.
Adds weekdays to date column in rbkwebs 2018 fixtures page
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.2.0.4 | |
// @description Legg til ukedager i rbkweb.no sin kampoversikt | |
// @author Sinna mann | |
// @match http://www.rbkweb.no/kamper2018.php | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
//create an array of weekdays. | |
var weekdays= ["Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør"]; | |
var docs = document.getElementsByClassName("kamp"); //Find the elements in our table with the class name used for dates and tv information. | |
//Iterate over all elements | |
for (var i = 0; i < docs.length;i++){ | |
var mynode = docs[i].innerHTML; | |
//Check if the element contains a date, by investigating if the first character is a number. | |
if(!isNaN(mynode[0])) { | |
var datenode=mynode.split("/"); //Split the result by / to separate day from month. | |
var day = ""; | |
var month=""; | |
// Add a zero to one digit days and months. | |
if (datenode[0].length<2){ | |
day = "0" + datenode[0];} | |
else{ | |
day = datenode[0]; | |
} | |
if (datenode[1].length<2){ | |
month = "0" +datenode[1];} | |
else{ | |
month = datenode[1]; | |
} | |
var mydatestring = "2018-" + month + "-" + day; //Concatinate year, month and day to create a valid date. | |
var date = new Date(mydatestring);//convert date string to a date object | |
var myday = date.getDay();//Get week day value from date object | |
docs[i].innerHTML = weekdays[myday] +" "+ mynode; // Get weekday name from weekdays array and concatinate to beginning of date in table. | |
} | |
} | |
} | |
)(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment