Scratch Message Notifier

Notifies every message, checks every 2 seconds (Deprecated)

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Scratch Message Notifier
// @author       Hans5958
// @namespace    Hans5958
// @description  Notifies every message, checks every 2 seconds (Deprecated)
// @include      http*://scratch.mit.edu/*
// @version      1.3.1.2
// @grant        none
// @icon         https://raw.githubusercontent.com/Hans5958/userscripts/master/Scratch/Message%20Notifier/icon.png
// @run-at       document-idle
// @license      MIT
// @homepageURL  https://github.com/Hans5958/userscripts
// @supportURL   https://github.com/Hans5958/userscripts/issues
// ==/UserScript==

function MSGLog(log) {
    console.log("[MSG] " + log);
}
MSGLog("Preparing...");
var originalTitle = document.title;
var originalCount = 0;
var count = 0;
var player = document.createElement('audio');
player.src = 'https://raw.githubusercontent.com/Hans5958/message-notifier/master/Message%20Notifier/notificationsound.wav';

function getCount() {
    try {
        return $('.notificationsCount').html();
    } catch (e) {
        return document.getElementsByClassName("message-count")[0].innerHTML;
    }
}

var ico = $('<link id="favicon" rel="icon" type="image/x-icon" href="/favicon.ico" />');
ico.appendTo(document.head);

function createIcon() {
    var canvas = document.createElement('canvas'),
        ctx,
        img = document.createElement('img');
    canvas.height = canvas.width = 32;
    ctx = canvas.getContext('2d');
    img.onload = function () {
        ctx.drawImage(this, 0, 0);
        ctx.font = 'bold 21px "helvetica", sans-serif';
        ctx.strokeStyle = 'black';
        ctx.lineWidth = 3;
        if (count > 99) {
            ctx.strokeText('99+', 0, 31);
            ctx.fillStyle = '#FFFFFF';
            ctx.fillText('99+', 0, 31);
        } else {
            ctx.strokeText(count + '', 0, 31);
            ctx.fillStyle = '#FFFFFF';
            ctx.fillText(count + '', 0, 31);
        }
        ico.attr({
            'type': 'image/png',
            'href': canvas.toDataURL('image/png')
        });
    };
    img.src = '/favicon.ico';
}

if (getCount() !== undefined) {
    MSGLog("Starting...");
    setInterval(function () {
            count = getCount();
            if (count == 0) {
                document.title = originalTitle;
                ico.attr({
                    'type': 'image/x-icon',
                    'href': '/favicon.ico'
                });
                originalCount = 0;
            } else {
                if (originalCount != count) {
                    document.title = '(' + count + ') New message!';
                    player.play();
                    originalCount = count;
                    createIcon();
                } else {
                    document.title = '(' + count + ') ' + originalTitle;
                }
            }
        },
        2000);
} else {
    MSGLog("User not logged in.");
}