DanielTepesKraus / Old Style PM Notifications

// ==UserScript==
// @name        Old Style PM Notifications
// @namespace   Old Style PM Notifications
// @description Restores the PM Notifications used on the old Derpibooru UI
// @author      DanielTepesKraus || https://www.derpibooru.org/profiles/DanielTepesKraus
// @include     https://*derpibooru.org/*
// @include     *derpibooru.org*
// @include     https://*derpiboo.ru/*
// @include     *derpiboo.ru/*
// @include     https://*trixiebooru.org/*
// @include     *trixiebooru.org/*
// @version     1.0
// @grant       none
// ==/UserScript==

var messages = document.getElementsByClassName("header__link");
for (var i = 0; i < messages.length; i++) {
  if (messages[i].innerHTML.indexOf('fa-embedded--unread-message') > -1 && messages[i].childNodes[1].innerHTML > 0){
    var msgalert = document.createElement("div");
    if (messages[i].childNodes[1].innerHTML > 1){
      msgalert.innerHTML = "<div class='flash flash--warning'>You have " + messages[i].childNodes[1].innerHTML + " unread conversations! Click <a href='" + messages[i].href + "'>here</a> to read them!</div></div>";
    }else{
      msgalert.innerHTML = "<div class='flash flash--warning'>You have " + messages[i].childNodes[1].innerHTML + " unread conversation! Click <a href='" + messages[i].href + "'>here</a> to read it!</div>";
    }
    var div = document.getElementsByClassName("flash flash--warning")[0];
    insertAfter(div, msgalert);
  }
}

function insertAfter(referenceNode, newNode) {
    referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}