Script Request - Review session reminder

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:

image

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 :thinking:.

9 Likes

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:

setTimeout(() => alert('test'), 5000)
1 Like

Hmmmmm… It works, but it’s definitely not ‘in my face’ enough :thinking:

It’s something at least, thanks!

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.

3 Likes

Also guilty. :raised_hand:

4 Likes

Can pop a notification on bottom right corner of screen no matter what you’re doing.

2 Likes

Plays a bell sound every second until you focus the page again

var timeout;
var interval = 0;
var audio = new Audio("https://files.catbox.moe/8vae5p.mp3");
window.addEventListener('focus', () => {
	clearTimeout(timeout);
	clearInterval(interval);
});
window.addEventListener('blur', () => {
	timeout = setTimeout(() => {
		interval = setInterval(()=>{
			audio.play();
		}, 1000);
	}, 5000);
});
6 Likes

Nice. Can we find a recording of Koichi saying “Go do your reviews!” to use instead?

12 Likes

@koichi The community needs you. ;3

4 Likes

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”.

15 Likes

I completely forgot notifications in browsers are a thing because I always block them immediately.

8 Likes

I had wondered about this because it seemed obvious to me. But I despise them with the same fervent passion so I thought nothing of it :rofl:

:clap:

6 Likes

@Wantitled Did the world a service by creating this thread

6 Likes

I’ll be sure to credit all of you in my level 60 thread… When that eventually happens…

Seriously all thank you so much, this is amazing

3 Likes