Choose a Word

Notifies you whenever it's your turn to draw. Notifications must be allowed.

目前為 2020-06-27 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          Choose a Word
// @namespace     https://greasyfork.org/users/281093
// @match         https://sketchful.io/*
// @grant         none
// @version       1.0.1
// @author        Bell
// @description   Notifies you whenever it's your turn to draw. Notifications must be allowed.
// jshint esversion: 6
// ==/UserScript==

(function requestPermission() {
    if (Notification.permission === "granted") {
        console.log("Notifications allowed");
    } else {
        Notification.requestPermission()
            .then(result => {
                console.log(result);
            });
    }
})();

let tabFocused = true;

window.onfocus = () => {
    tabFocused = true;
};
window.onblur = () => {
    tabFocused = false;
};

const checkSticky = function(mutationsList, observer) {
    for (let mutation of mutationsList) {
        if (mutation.addedNodes[0].innerHTML && mutation.addedNodes[0].innerHTML.includes("Choose")) {
            if (!tabFocused) {
                notify();
            }
        }
    }
};

const playerList = document.querySelector("#gameSticky");
const observer = new MutationObserver(checkSticky);
const config = {
    attributes: false,
    childList: true,
    subtree: true
};

observer.observe(playerList, config);

function notify() {
    if (Notification.permission === "granted") {
        let notification = new Notification("Your Turn", {
            icon: "https://sketchful.io/res/logo/pencils%20optimized.png",
            body: "Click the notification to return to the game.",
            requireInteraction: true,
        });

        notification.onclick = function() {
            window.focus();
            notification.close();
        };
    } else {
        console.log("Notifications are blocked.");
    }
}