TTN notify on change

Notifies when the content changes on TTN.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name       TTN notify on change
// @namespace  http://mathemaniac.org/
// @version    1.0.1
// @description  Notifies when the content changes on TTN.
// @match        https://www.treesnetwork.com/*
// @copyright  2018, Sebastian Paaske Tørholm
// @require    https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';

$(function () {
    var last_name = undefined;
    function checkForChange() {
        var title = $('div span span[class*="name"]').text();
        if (! last_name) last_name = title;

        if (title !== last_name) {
            last_name = title;
            if (document.hidden && title !== "Off The Air" && title !== "The Trees Network") {
                var n = new Notification("Now playing on TTN: " + title, { "tag": "ttn_now_playing", "requireInteraction": true, "silent": false } );
            }
        }
    }
    setInterval(checkForChange, 1000);
});