Last active
February 26, 2024 07:37
-
-
Save SimDing/826f9fcfb897e89bcd24 to your computer and use it in GitHub Desktop.
Gibt ein Blinksignal in der Tableiste, wenn eine neue Nachricht empfangen wurde.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Proxer Message Info | |
// @namespace de.simonding.proxer | |
// @author Simon Ding (0ger) | |
// @description Gibt ein Blinksignal in der Tableiste, wenn eine neue Nachricht empfangen wurde. | |
// @include http://proxer.me/* | |
// @include https://proxer.me/* | |
// @include http://www.proxer.me/* | |
// @include https://www.proxer.me/* | |
// @version 0.4 | |
// @require https://greasyfork.org/scripts/12981-proxer-userscript-anker/code/Proxer-Userscript-Anker.js?version=80716 | |
// set/get für Anker | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant unsafeWindow | |
// ==/UserScript== | |
/* ============ Einstellungen ============ */ | |
var checkInterval = 30; // Wartezeit zwischen dem abrufen von Nachrichten (Sekunden) | |
var blinkInterval = 700; // Wartezeit zwischen dem Blinken im Titel (Millisekunden) | |
/* ======================================= */ | |
var titleBlinkerTimeout; | |
var idleListenerInterval; | |
var newMessages = false; | |
var originalTitle = document.title; | |
var blink = false; | |
addAnkerMember('messageBlinker', 'Nachrichten Info', true, messageBlinkerToggle, 'messageBlinker', 0); | |
function messageBlinkerToggle(change) { | |
if (change === true) { | |
if (GM_getValue('messageBlinker', 0) === 0) { | |
clearInterval(idleListenerInterval); | |
} else { | |
idleMessageListener(); | |
} | |
} else { | |
idleMessageListener(); | |
} | |
} | |
// Start blinking in title, stops when newMessages is <= 0 | |
function titleBlinker() { | |
clearTimeout(titleBlinkerTimeout); | |
if (newMessages === true) { | |
blink = !blink; | |
titleBlinkerTimeout = setTimeout(titleBlinker, blinkInterval); | |
} else { | |
blink = false; | |
} | |
if (blink) { | |
document.querySelector('link[rel="icon"]').href = "https://proxer.me/templates/proxer14/images/notification_2.png"; | |
} else { | |
document.querySelector('link[rel="icon"]').href = "https://proxer.me/images/favicon.ico"; | |
} | |
} | |
// Slightly changed version of the original MessageListener that is active without focus | |
function idleMessageListener() { | |
if (window.location.pathname.split('/')[1] !== 'messages' || GM_getValue('messageBlinker', 0) === 0){ | |
return; | |
} | |
if (unsafeWindow.isActive) { | |
window.addEventListener("blur", function () { | |
idleListenerInterval = setInterval(idleMessageListener, checkInterval * 1000); | |
}); | |
} else { | |
unsafeWindow.getNewMessages(); | |
} | |
} | |
function testLastMid() { | |
var lastid = unsafeWindow.lastMid; | |
var interval = setInterval(function () { | |
if (unsafeWindow.lastMid !== lastid) { | |
newMessages = true; | |
clearInterval(interval); | |
titleBlinker(); | |
} | |
}, 500); | |
window.addEventListener("focus", function(){ | |
clearInterval(interval); | |
newMessages = false; | |
}); | |
} | |
window.addEventListener("blur", function(){ | |
if (GM_getValue('messageBlinker', 0) === 1) | |
testLastMid(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment