Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name WaniKani Time-Spent
- // @namespace rfindley
- // @description Keep track of your time spend on WaniKani.
- // @version 1.0.0
- // @include https://www.wanikani.com/*
- // @copyright 2015+, Robin Findley
- // @license MIT; http://opensource.org/licenses/MIT
- // @run-at document-end
- // @grant none
- // ==/UserScript==
- wktimespent = {};
- (function(gobj) {
- var start_time, stats, active={};
- var categories = {
- all: ['*'],
- dashboard: ['/dashboard'],
- forums: ['/chat/*'],
- forum_api: ['/chat/api-and-third-party-apps*'],
- forum_campfire: ['/chat/campfire*'],
- forum_kanji: ['/chat/kanji-and-japanese*'],
- forum_wanikani: ['/chat/wanikani*'],
- lessons: ['/lesson*'],
- reviews: ['/review*'],
- study: ['/level*','/radical*','/kanji*','/vocabulary*']
- };
- function save_stats() {
- var stop_time = Math.round(new Date().getTime()/1000);
- $.each(active, function(category,value){
- var catname = 'timespent_'+category;
- var timespent = Number(localStorage.getItem(catname) || 0);
- timespent += (stop_time - start_time);
- localStorage.setItem(catname, timespent);
- });
- }
- function main() {
- start_time = Math.round(new Date().getTime()/1000);
- // Figure out what timers we need to increment.
- var page = window.location.pathname;
- $.each(categories, function(category, urls){
- $.each(urls, function(idx, url){
- var criteria = '^'+url.replace('\*','.*')+'$';
- if (page.match(criteria) != null)
- active[category] = 1;
- });
- });
- $(window).unload(save_stats);
- }
- // Run startup() after window.onload event.
- if (document.readyState === 'complete')
- main();
- else
- window.addEventListener("load", main, false);
- }(wktimespent));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement