Appeal date to local time

Changes the date of the infraction to the local timezone.

当前为 2020-06-12 提交的版本,查看 最新版本

// ==UserScript==
// @name        Appeal date to local time
// @namespace   Violentmonkey Scripts
// @match       https://appeals.cubecraft.net/find_appeals/*
// @grant       none
// @version     1.2
// @author      Caliditas
// @description Changes the date of the infraction to the local timezone.
// ==/UserScript==

var infractions = document.getElementsByClassName("col-sm-8");
var amountOfInfractions = infractions[0].children.length;

for (var i = 0; i < amountOfInfractions; i++) {
  replaceDate(infractions[0].children[i].firstElementChild);
}

function replaceDate(element) {
  var contentString = element.innerHTML;
  dateStringOld = contentString.slice(contentString.indexOf(" at ") + 3, contentString.indexOf(" for")) + " UTC";
  var dateOldMs = Date.parse(dateStringOld);
  var dateOld = new Date(dateOldMs);
  var contentStringChanged = contentString.slice(0, contentString.indexOf(" at ") + 4) + dateOld.toString().slice(4, 10) + "," + dateOld.toString().slice(10, 25) + initials(new Date().toString().match(/\(([A-Za-z\s].*)\)/)[1])
  contentStringChanged += contentString.slice(contentString.indexOf(" for"));
  element.innerHTML = contentStringChanged;
}

function initials(words) {
  if (words.includes(" ")) {
    var wordsArray = words.split(" ");
    var initials = "";
    for (var i = 0; i < wordsArray.length; i++) {
      initials += wordsArray[i][0];
    }
    return initials;
  } else {
    return words;
  }  
}