Gandalf

16/02/2023 10:53:21

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Gandalf
// @namespace   Violentmonkey Scripts
// @match       https://gandalf.epitech.eu/*
// @grant       none
// @version     1.0
// @author      Quentin Quéro
// @description 16/02/2023 10:53:21
// @license MIT
// @require     https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js
// ==/UserScript==

let dates  = document.querySelectorAll("table > tbody > tr > td")
let table  = document.querySelector("table")
let passedColor = "#999"
let soonColor = "#e04957"
let futurColor = "#0272bc"

table.style["border-spacing"] = "10px"
table.style["border-collapse"] = "separate"

dates.forEach(date => {

  let formatDate = "ll"

  let cleanDate = date.innerHTML.split(" ")[1];

  if(cleanDate){

    if(cleanDate.includes("<span")){
      cleanDate = cleanDate.replace('<span>', '').replace('<span>', '').replace('<span>', '').replace('<span>', '').replace('<span>', '').replace('<span>', '').replace('<span style="">', '')
      cleanDate = cleanDate.replace('</span>', '').replace('</span>', '').replace('</span>', '').replace('</span>', '').replace('</span>', '').replace('</span>', '')

    }
    if(cleanDate.includes("-")){
     cleanDate = cleanDate.replace(' - ', ' ').replace('h', ':')
      formatDate = 'lll'
    }

    if(cleanDate.includes("<strong>"))
      cleanDate = cleanDate.split("<strong>")[0];
  }

  if(!cleanDate)
    cleanDate = date.innerHTML.split(" ")[1];

  if(!cleanDate){
    cleanDate = date.innerHTML
  }

  if(cleanDate && cleanDate !== "-"){
    cleanDate = cleanDate.replace('<br>', '')
    cleanDate = cleanDate.replace(' ', '').replace(' ', '').replace(' ', '').replace(' ', '')
    let dateMoment = moment(cleanDate)
    if(dateMoment.isValid()) {
      date.style["text-align"] = "left"
      date.style["border-radius"] = "10px"
      date.style.padding = "5px 10px"
      date.style["border"] = "1px solid";

      if(dateMoment.isBefore(moment())){
        date.innerHTML = dateMoment.format(formatDate);
        date.style.color = passedColor;
      } else if(dateMoment.add("7", "d").isBefore(moment())) {
        date.style.color = soonColor;
        date.style["border"] = "3px solid";
        date.innerHTML = dateMoment.format(formatDate) + ' | <strong>' + dateMoment.fromNow() + "</strong>"

      } else {
        date.style.color = futurColor;
        date.style["border"] = "3px solid";
        date.innerHTML = dateMoment.format(formatDate) + ' | ' + dateMoment.fromNow()

      }
    }
  }
})