您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Notify Kanban in your turn
当前为
// ==UserScript== // @name Kanban Your turn Notifier // @namespace tequila_j-script // @version 0.0.1 // @description Notify Kanban in your turn // @match http://*.boiteajeux.net/jeux/kan/* // @match https://*.boiteajeux.net/jeux/kan/* // @grant GM_addStyle // @run-at document-idle // ==/UserScript== // request permission on page load document.addEventListener('DOMContentLoaded', function () { if (Notification.permission !== "granted") Notification.requestPermission(); }); //window.setVariableInterval based from user gnarf (http://stackoverflow.com/users/91914/gnarf) window.setVariableInterval = function(callbackFunc, timing) { var variableInterval = { interval: timing, callback: callbackFunc, stopped: false, runLoop: function() { if (variableInterval.stopped) return; var result = variableInterval.callback.call(variableInterval); if (typeof result == 'number') { if (result === 0) return; variableInterval.interval = result; } variableInterval.loop(); }, stop: function() { this.stopped = true; window.clearTimeout(this.timeout); }, start: function() { this.stopped = false; return this.loop(); }, loop: function() { this.timeout = window.setTimeout(this.runLoop, this.interval); console.log(this.interval); return this; }, incrementInterval: function(increment) { this.interval = this.interval + increment; return this; } } return variableInterval; }; var notificationTimeout = { start: 10000, max: 60000, step: 2000, current: 10000 }; function resetTimeout() { notificationTimeout.current = notificationTimeout.start; } function increaseTimeout() { if (notificationTimeout.current >= notificationTimeout.max) { return; } notificationTimeout.current = notificationTimeout.current + notificationTimeout.step; } var gameName = $("#dvBandeauHaut > div:first > div.clTexteFort:nth-child(2)").html(); function notify(message) { if (!Notification) { console.log('Desktop notifications are not available for your browser.'); return; } if (Notification.permission !== "granted") Notification.requestPermission(); else { var notification = new Notification(gameName + ':your turn!', { icon: 'http://www.boiteajeux.net/jeux/kan/img/sandra_1.png', body: message, }); } } var isMyTurn = function() { var message = $('#dvMessage').html(); return ! message.startsWith("Still twiddling your thumbs"); } var turnNotifier = setVariableInterval(function() { var message = $('#dvMessage').html(); if (isMyTurn()) { notify(message); this.stop(); } else { orig_actualiserPage(); if (this.interval <= notificationTimeout.max) this.incrementInterval(notificationTimeout.step) } }, notificationTimeout.current ) function startNotification() { turnNotifier.interval = notificationTimeout.start; turnNotifier.start(); } //override function so notification can start again when they are clicked var orig_finalizeActions = finalizeActions finalizeActions = function() { startNotification(); orig_finalizeActions(); } var orig_passer = passer; passer = function() { startNotification(); orig_finalizeActions(); } var orig_actualiserPage = actualiserPage; actualiserPage = function() { turnNotifier.stop(); orig_actualiserPage(); if (! isMyTurn()) startNotification(); } //end of override functions startNotification();