Wanikani Open Framework
Github early access
Early access to the Open Framework. \o/
Installation
I don’t have documentation yet, but the sample_client.js
should be useful in finding your way around.
To install:
- Copy the contents of
Core.js
into a new script in TamperMonkey (or whatever)
- Move the script to slot #1 in TamperMonkey so it will run before any client scripts that use it.
- Add the Update URL in TamperMonkey if you want to keep up to date during development:
https://raw.githubusercontent.com/rfindley/wanikani-open-framework/master/Core.js
(This won’t be the permanent address. Releases will be on GreasyFork to take advantage of the ‘Install’ button, statistics, and simpler diffing)
Installing the sample_client.js:
- Copy the contents of
sample_client.js
into a new script in TamperMonkey (or whatever)
- Make sure the sample client is set to run after the
Wanikani Open Framework
script (Core.js
).
- You probably don’t want to auto-update this one, otherwise you may overwrite any changes you make while exploring the framework.
Getting started
The main thing to know is that the framework is exposed through window.wkof
. From the Javascript console, you can explore what functions and modules are loaded and available:
The modules Apiv2
, Menu
, and Settings
are loaded by the sample_client script. If no script includes any modules, you’ll only see the functions from Core.js
.
Core.js
The Core.js contains:
file_cache // Some functions for caching files in indexeddb.
dir {} // An object containing a list of files stored in indexeddb.
clear() // Clear the file_cache.
load() // Save a file to file_cache.
save() // Load a file from file_cache.
delete() // Delete a file from file_cache
include() // Include a module for use with your script (Apiv2, Menu, Settings).
ready() // Returns a promise that resolves when the specified module is ready to be used.
get_state() // Get the current state of a state variable.
set_state() // Set the state of a state variable.
wait_state() // Returns a promise that resolves when a state variable reaches a specified state.
trigger() // Initiates a framework event.
on() // Specify a function to be called when the specified event is triggered.
load_file() // Loads a file from cache or url. Returns a promise that resolve with the file contents.
load_css() // Loads a css file and installs it into the document.
load_script() // Loads a javascript file and installs it into the document.
Apiv2 module
I don’t recommend using these functions in your scripts yet. While they are useful, and you may want to explore them now, I’m currently working on a higher-level interface for managing data.
fetch_endpoint() // Fetch an API endpoint from the WK server. Supports filters,
// and automatically fetches all pages of the returned result.
get_endpoint() // Fetches endpoint data from cache first, then retrieves only
// updates from the WK server.
get_apikey() // For internal use only. Will probably be removed.
// Use wkof.Apiv2.key instead.
is_valid_apikey_format() // Makes sure a string fits the APIv2 format.
print_apikey() // Remnant of early development. Will probably be removed.
key (string) // Contains the apiv2 key that the framework is currently using.
user (string) // Contains the username that the framework is currently using.
The cached endpoint data is stored in wkof.file_cache
. After fetching an endpoint, you will see the cached data appear in the cache (note that it takes about 15 seconds to fetch /subjects
the first time):
If you want to use a different API key for testing:
localStorage.apiv2_key_override = 'someone_elses_key_here';
Then refresh the page. It will automatically clear cached API data (except /subjects
, which is not user-specific), so you know you’ll only be getting the data you want.
Menu module
This only has one function:
insert_script_link() // see sample_client.js for example usage
Settings module
This module only has a class constructor that returns a dialog box object:
wkof.Settings() // see sample_client.js for example usage
More coming soon…
I’m currently working on the higher-level data interface. It consists of:
- A set of functions for interlinking the various APIv2 endpoints
(e.g. /subjects, /assignments, /reviews, etc)
- A toolbox of predefined filters for narrowing down the data you want to look at.
- An interface for registering your own filters, so other scripts can make use of them.
- An interface for registering 3rd-party data items, like kana-only vocab, core-10k vocab, etc.
Scripts will be able to look at the registered filters and data sources, and maybe allow a user to choose what data and filters they want to use in your script… for example, the Self-Study Quiz script will allow the user to create a preset that selects only leeches, or maybe items that the user failed in review during the last 24 hours.
Tags…
@valeth, @DaisukeJigen, @hitechbunny, @acm2010, @seanblue, @Subversity