[Userscript] Review Cache

Only for use in other scripts

This script does not provide any user-facing functionality.

What is it?

This script manages a cache of all the user’s reviews. Review data in the API essentially stores only five independent pieces of information: creation date, subject id, starting srs stage, incorrect meaning answers, and incorrect reading answers. This script minifies this data and stores it the WKOF file cache. I needed this for the Heatmap script, and thought I might as well make it accessible to everyone.

How to use

First of all this script requires WKOF, so you need to make sure the user has that installed. Other than that, put it in your script as a @require and it will expose two functions in window.review_cache. The two functions are get_reviews() which loads and updates the cache then returns it, and reload() which clears the cache then repopulates it with data from the API.

The function get_reviews() returns the review data as an array of reviews, in which every review has the structure [creation date (unix timestamp), subject id, starting srs stage, incorrect meaning answers, incorrect reading answers]. The timestamp here is only accurate to the closest minute in order to save storage space. This info is all you need in order to know exactly how the review went. Item data can be retrieved by cross referencing with the subject ID, as in the example below.

Example: getting kanji reviews from the last 24 hours

// Get reviews
let reviews = await window.review_cache.get_reviews();
// Filter for last 24 hours
let today = reviews.filter(a => a[0] > Date.now()-24*60*60*1000); // a[0] is creation date
// Since review cache only stores the review data, we need to cross reference the subject ID for item data
let wk_items = await wkof.ItemData.get_items();
let by_id = wkof.ItemData.get_index(wk_items, 'subject_id');
let kanji_today = today.filter(a => by_id[a[1]].object === "kanji"); // a[1] is subject id
kanji_today 
// [[1601334840000, 1801, 6, 0, 2], [1601390400000, 1864, 8, 0, 0], [1601390460000, 8862, 6, 0, 0], ...]

Found at

The Cookie Cache

15 Likes