Greasy Fork is available in English.

Kanban Your turn Notifier

Notify Kanban in your turn

  1. // ==UserScript==
  2. // @name Kanban Your turn Notifier
  3. // @namespace tequila_j-script
  4. // @version 0.4.2
  5. // @description Notify Kanban in your turn
  6. // @match http://*.boiteajeux.net/jeux/kan/*
  7. // @match https://*.boiteajeux.net/jeux/kan/*
  8. // @match http://www.boiteajeux.net/jeux/kan/*
  9. // @match https://www.boiteajeux.net/jeux/kan/*
  10. // @grant GM_addStyle
  11. // @run-at document-idle
  12. // ==/UserScript==
  13.  
  14. // request permission on page load
  15.  
  16. document.addEventListener('DOMContentLoaded', function () {
  17. if (Notification.permission !== "granted")
  18. Notification.requestPermission();
  19. });
  20.  
  21. (function() {
  22.  
  23. 'use strict';
  24. /*jshint multistr: true */
  25.  
  26.  
  27. var honkSound = new Audio("http://www.soundjay.com/transportation/car-locked-honk-1.mp3");
  28.  
  29. window.setCheckTurn = function(callbackFunc, timing) {
  30. var variableInterval = {
  31. config: timing,
  32. callback: callbackFunc,
  33. stopped: false,
  34. runLoop: function() {
  35. if (variableInterval.stopped) return;
  36. var result = variableInterval.callback.call(variableInterval);
  37. if (typeof result == 'number') {
  38. if (result === 0) return;
  39. variableInterval.interval = result;
  40. };
  41. variableInterval.loop();
  42. },
  43. stop: function() {
  44. this.stopped = true;
  45. console.log("Auto refresh stopped");
  46. window.clearTimeout(this.timeout);
  47. },
  48. start: function() {
  49. this.stopped = false;
  50. console.log("Auto refresh started");
  51. return this.loop();
  52. },
  53. loop: function() {
  54. this.timeout = window.setTimeout(this.runLoop, this.getInterval());
  55. return this;
  56. },
  57. incrementInterval: function() {
  58. var alic = this.getInterval() + this.config.step;
  59. if (alic > this.config.max) {
  60. this.setInterval(this.config.max)
  61. console.log("Interval already set to maximum:" + this.getInterval());
  62. } else {
  63. this.setInterval(this.getInterval() + this.config.step);
  64. console.log("Interval increased to:" + this.getInterval());
  65. }
  66. return this;
  67. },
  68. resetInterval: function() {
  69. this.setInterval(this.config.start)
  70. console.log("Interval reset to:" + this.getInterval());
  71. },
  72. getInterval: function() {
  73. if (sessionStorage.getItem("currentTime") === null) {
  74. sessionStorage.setItem("currentTime", this.config.start);
  75. }
  76. return Number(sessionStorage.getItem("currentTime"));
  77. },
  78. setInterval: function(val) {
  79. sessionStorage.setItem("currentTime", val);
  80. }
  81.  
  82. }
  83. return variableInterval;
  84. };
  85.  
  86.  
  87. var notificationTimeout = {
  88. start: 10000,
  89. max: 60000,
  90. step: 3000,
  91. current: 10000
  92. };
  93.  
  94.  
  95. var gameName = $("#dvBandeauHaut > div:first > div.clTexteFort:nth-child(2)").html();
  96.  
  97. function notify(message) {
  98. if (!Notification) {
  99. console.log('Desktop notifications are not available for your browser.');
  100. return;
  101. }
  102.  
  103. if (Notification.permission !== "granted")
  104. Notification.requestPermission();
  105.  
  106. else {
  107. var notification = new Notification(gameName + ': your turn!', {
  108. icon: 'http://www.boiteajeux.net/jeux/kan/img/sandra_1.png',
  109. body: message,
  110. requireInteraction: true
  111. });
  112. notification.onclick = function () {
  113. window.focus();
  114. };
  115. }
  116. honkSound.play();
  117.  
  118. }
  119.  
  120. var isMyTurn = function() {
  121. var message = $('#dvMessage').html();
  122. return ! message.startsWith("Still twiddling your thumbs");
  123. }
  124.  
  125.  
  126. var turnNotifier = setCheckTurn(function() {
  127. actualiserPage();
  128. }, notificationTimeout
  129. )
  130.  
  131.  
  132. function startNotification() {
  133. turnNotifier.resetInterval();
  134. turnNotifier.start();
  135. }
  136.  
  137.  
  138. //override function so notification can start again when they are clicked
  139. var proxied_finalizeActions = finalizeActions
  140. finalizeActions = function() {
  141. turnNotifier.stop();
  142. proxied_finalizeActions.apply(this, arguments);
  143. startNotification();
  144. }
  145.  
  146.  
  147. var proxied_refreshDisplay = refreshDisplay;
  148. refreshDisplay = function() {
  149. proxied_refreshDisplay.apply( this, arguments );
  150. console.log("Display refreshed");
  151. if (isMyTurn()) {
  152. var message = $('#dvMessage').html();
  153. notify(message);
  154. turnNotifier.stop();
  155. console.log("Auto refresh stop");
  156. } else {
  157. turnNotifier.incrementInterval();
  158. }
  159. }
  160.  
  161. var proxied_passer = passer;
  162. passer = function() {
  163. turnNotifier.stop();
  164. var result = proxied_passer.apply( this, arguments );
  165. startNotification();
  166. }
  167.  
  168. var proxied_actualiserPage = actualiserPage;
  169. actualiserPage = function() {
  170. turnNotifier.stop();
  171. var result = proxied_actualiserPage.apply( this, arguments);
  172. turnNotifier.start();
  173. }
  174.  
  175. var proxied_faire = faire;
  176. faire = function() {
  177. var result = proxied_faire.apply( this, arguments );
  178. //if (arguments[0] == "moveWorker" || arguments[0] == "perfGoal" || arguments[0] == "nextperfgoal" || arguments[0] == "selectDesignInit" || arguments[0] == "selectPosCertifInit") // selectPosCertifInit does not work. It is used by any cert
  179. if (arguments[0] == "moveWorker" || arguments[0] == "perfGoal" || arguments[0] == "nextperfgoal" || arguments[0] == "selectDesignInit" )
  180. startNotification();
  181. return result;
  182. };
  183.  
  184. startNotification();
  185. })() //end of script
  186.  
  187.