This repository has been archived by the owner on Feb 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWanikani_for_Vimperator.user.js
88 lines (74 loc) · 2.53 KB
/
Wanikani_for_Vimperator.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ==UserScript==
// @name Wanikani for Vimperator
// @namespace rr-@sakuya.pl
// @description Improves Wanikani navigation on Vimperator
// @include https://www.wanikani.com/review/session
// @include https://www.wanikani.com/lesson/session
// @version 1
// @grant none
// ==/UserScript==
function convertLinks($targetItems, innerSelector)
{
$targetItems.each(function(i, item)
{
var $item = $(item);
// link already added?
if ($item.find('a').length > 0)
return;
var $target = $item;
if (typeof(innerSelector) !== 'undefined')
$target = $target.find(innerSelector);
$target.wrapInner(
$('<a/>')
.css({color: $target.css('color')})
.click(function(e)
{
e.preventDefault();
$item.click();
// prevent firing event listeners that Wanikani might attach
// at later point in time
e.stopPropagation();
}));
});
}
$(function()
{
$('body').bind('DOMSubtreeModified', function()
{
// buttons under the main input
convertLinks($('#additional-content li'), 'span');
// top tabs
convertLinks($('#supplement-nav li'));
// bottom kanji buttons
convertLinks($('#batch-items li'));
// big left/right arrows
convertLinks($('#prev-btn, #next-btn'));
// summary links
convertLinks($('#screen-quiz-ready li'));
convertLinks($('#screen-lesson-ready li'));
convertLinks($('#screen-lesson-done li'));
// show all information
convertLinks($('#all-info'));
// add user synonym button
convertLinks($('.user-synonyms-add-btn'));
// add hidden text to arrows so that they're accessible with standard
// names
$('#next-btn a, i.icon-chevron-right').each(function(i, item)
{
var $item = $(item);
if ($item.find('span').length > 0)
return;
$item.wrapInner($('<span>Next</span>').hide());
});
$('#prev-btn a, i.icon-chevron-left').each(function(i, item)
{
var $item = $(item);
if ($item.find('span').length > 0)
return;
$item.wrapInner($('<span>Previous</span>').hide());
});
// hide useless cruft in footer
$('footer #hotkeys').remove();
$('footer #report-errors').remove();
});
});