I have a problem when doing reviews… Often I’ll switch tabs or windows in the middle of a review session, and I get distracted. And this will lead to me wasting loads of time doing things forgetting that I’m in the middle of a review session. In fact, that’s exactly what I’m doing right now:
I don’t know if this is a common issue, but I’d love it if someone was able to make a script which would ping you with a notification if your review window is inactive for more than, say, a minute or two. That is if it’s even possible .
I don’t think a script could ping you. I just checked what an alert would do when you are in a different tab. On Chrome at least it just puts a blue dot in the favicon. Run this code in the console and then switch tabs to see what I mean:
Here’s something quick and dirty (and tested for a few minutes) inspired by this. It definitely wouldn’t grab my attention, but if nobody has any better ideas maybe it would be worth trying.
let timeout;
window.addEventListener('focus', () => clearTimeout(timeout));
window.addEventListener('blur', () => timeout = setTimeout(() => alert('get back to work!'), 5000));
Change the number to how many milliseconds you want it to wait before alerting you.
I first tried it with GM_notification, but I don’t know if this is a Tampermonkey-exclusive feature. Here is this version:
// ==UserScript==
// @name GetBackToWork
// @namespace getbacktowork
// @version 1.0
// @description Get back to work!
// @author Sinyaven
// @match https://www.wanikani.com/review/session
// @grant GM_notification
// @grant window.focus
// ==/UserScript==
(function() {
"use strict";
// time in milliseconds
let duration = 60000;
let timeout;
let audio = new Audio("https://raw.githubusercontent.com/tofugu/japanese-vocabulary-pronunciation-audio/master/lib/mp3/%E9%B0%90%E8%9F%B9%E3%80%90%E3%82%8F%E3%81%AB%E3%81%8B%E3%81%AB%E3%80%91.mp3");
window.addEventListener("focus", () => clearTimeout(timeout));
window.addEventListener("blur", () => {timeout = setTimeout(showNotification, duration)});
function showNotification() {
GM_notification({text: "You still have WaniKani reviews to do!", title: "Get back to work!", highlight: false, onclick: () => window.focus()});
audio.play();
}
})();
And here is a version using the Notification API that @DaisukeJigen linked:
// ==UserScript==
// @name GetBackToWork
// @namespace getbacktowork
// @version 1.0
// @description Get back to work!
// @author Sinyaven
// @match https://www.wanikani.com/review/session
// ==/UserScript==
(function() {
"use strict";
// time in milliseconds
let duration = 60000;
if (Notification.permission !== "granted" && Notification.permission !== "denied") {
Notification.requestPermission();
}
let timeout;
let audio = new Audio("https://raw.githubusercontent.com/tofugu/japanese-vocabulary-pronunciation-audio/master/lib/mp3/%E9%B0%90%E8%9F%B9%E3%80%90%E3%82%8F%E3%81%AB%E3%81%8B%E3%81%AB%E3%80%91.mp3");
window.addEventListener("focus", () => clearTimeout(timeout));
window.addEventListener("blur", () => {timeout = setTimeout(showNotification, duration)});
function showNotification() {
new Notification("Get back to work!", {body: "You still have WaniKani reviews to do!"});
audio.play();
}
})();
EDIT: now the notification is accompanied by Koichi saying “WaniKani”.