techlover0010 / Notification On Leave

// ==UserScript==
// @name         Notification On Leave
// @namespace    https://www.brick-hill.com/user?id=5
// @version      1.1
// @description  When going to another tab, it will present how many messages and friends combined into a number.
// @author       Tech
// @match        https://www.brick-hill.com/*
// @grant        none
// @run-at       document-start
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @license      MIT
// @copyright    2018, techlover0010 (https://openuserjs.org//users/techlover0010)
// ==/UserScript==
$(function() {
    var loggedIn = $("a[href='/logout/']").text();
    if (loggedIn == 'Logout') {
        // Get page title
        var pageTitle = $("title").text();
        var messages = $("a.nav[href='/messages/']").text();
        var friends = $("a.nav[href='/friends/']").text();
        var sum = Number(messages) + Number(friends);
        $(window).blur(function() {
            if (sum != 0) {
                document.title = "(" + sum + ") " + pageTitle;
            }
        });
        $(window).focus(function() {
            $("title").text(pageTitle);
        });
    } else {
        console.log("Please log in!");
    }
});