Skip to content

Instantly share code, notes, and snippets.

@ktaragorn
Last active July 5, 2017 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktaragorn/fb39382a87d0fa19342967f5c4433269 to your computer and use it in GitHub Desktop.
Save ktaragorn/fb39382a87d0fa19342967f5c4433269 to your computer and use it in GitHub Desktop.
Desktop Notifications for YourTurnMyTurn
// ==UserScript==
// @name Desktop Notifications for YourTurnMyTurn
// @namespace ktaragorn
// @include https://www.yourturnmyturn.com/status.php
// @description Desktop Notifications for YourTurnMyTurn.com overview page when it is your turn
// @version 6
// @grant none
// ==/UserScript==
function refresh()
{
if(!is_your_turn()){
console.log("refreshing")
location.reload();
}
}
function is_your_turn(){
var search_for="It is not your turn right now."
return (
document.documentElement.textContent || document.documentElement.innerText
).indexOf(search_for) === -1
}
function notify(){
var notification = new Notification("Its your turn", {
sticky: true,
icon:"https://www.yourturnmyturn.com/favicon.ico",
requireInteraction: true})
alert("Your turn") // stop gap fix until firefox fixes the requireinteraction feature
}
function setup_notifications() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== "denied") {
Notification.requestPermission();
}
}
$(function(){if(is_your_turn()) notify();})
setup_notifications()
var refreshTime = 15;
window.setTimeout(refresh,refreshTime * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment