Greasy Fork is available in English.

WaniKani Links

Adds links to info pages during reviews. Jisho and WaniKani. Click the review item for a popup.

  1. // ==UserScript==
  2. // @name WaniKani Links
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Adds links to info pages during reviews. Jisho and WaniKani. Click the review item for a popup.
  6. // @author You
  7. // @match https://www.wanikani.com/review/session
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13. // Hook into App Store
  14. //try { $('.app-store-menu-item').remove(); $('<li class="app-store-menu-item"><a href="https://community.wanikani.com/t/there-are-so-many-user-scripts-now-that-discovering-them-is-hard/20709">App Store</a></li>').insertBefore($('.navbar .dropdown-menu .nav-header:contains("Account")')); window.appStoreRegistry = window.appStoreRegistry || {}; window.appStoreRegistry[GM_info.script.uuid] = GM_info; localStorage.appStoreRegistry = JSON.stringify(appStoreRegistry); } catch (e) {}
  15. addStyle('#divLinks {' +
  16. ' display: none;' +
  17. ' position: absolute;' +
  18. ' z-index: 10;' +
  19. ' background: #c7c2c2;' +
  20. ' border: black 1px solid;' +
  21. '}' +
  22. '#divLinks a {' +
  23. ' padding: 5px;' +
  24. ' display: inline;' +
  25. '}' +
  26. '#divLinks a:after {' +
  27. ' content:"\\a";' +
  28. ' white-space: pre;' +
  29. ' padding: 5px;' +
  30. '}');
  31. $.jStorage.listenKeyChange('currentItem', function (key, action) {
  32. choiceBox($.jStorage.get('currentItem'));
  33. $('.radicals [lang="ja"]').click(
  34. function(event){
  35. showLinks(event);
  36. }
  37. ).css('cursor','pointer');
  38. $('.kanji [lang="ja"]').click(
  39. function(event){
  40. showLinks(event);
  41. }
  42. ).css('cursor','pointer');
  43. $('.vocabulary [lang="ja"]').click(
  44. function(event){
  45. showLinks(event);
  46. }
  47. ).css('cursor','pointer');
  48. });
  49. }());
  50.  
  51. function choiceBox(data){
  52. $('#divLinks').remove();
  53. var divLinks = $("<div>", {
  54. id: 'divLinks',
  55. title: 'Links',
  56. });
  57. if (data.voc !== undefined) {
  58. $("<a>", {
  59. text: "WaniKani",
  60. title: "WaniKani",
  61. href: "https://www.wanikani.com/vocabulary/" + data.voc,
  62. target: "_blank",
  63. click: function(){hideLinks();}
  64. }).appendTo(divLinks);
  65. $("<a>", {
  66. text: "Jisho",
  67. title: "Jisho",
  68. href: "http://jisho.org/search/" + data.voc,
  69. target: "_blank",
  70. click: function(){hideLinks();}
  71. }).appendTo(divLinks);
  72. } else if (data.kan !== undefined) {
  73. $("<a>", {
  74. text: "WaniKani",
  75. title: "WaniKani",
  76. href: "https://www.wanikani.com/kanji/" + data.kan,
  77. target: "_blank",
  78. click: function(){hideLinks();}
  79. }).appendTo(divLinks);
  80. $("<a>", {
  81. text: "Jisho",
  82. title: "Jisho",
  83. href: "http://jisho.org/search/" + data.kan,
  84. target: "_blank",
  85. click: function(){hideLinks();}
  86. }).appendTo(divLinks);
  87. } else if (data.rad !== undefined) {
  88. $("<a>", {
  89. text: "WaniKani",
  90. title: "WaniKani",
  91. href: "https://www.wanikani.com/radicals/" + data.rad,
  92. target: "_blank",
  93. click: function(){hideLinks();}
  94. }).appendTo(divLinks);
  95. }
  96. $('body').append(divLinks);
  97. }
  98.  
  99. function showLinks(event){
  100. $('#divLinks').css('display','block').css('left',event.pageX).css('top',event.pageY);
  101. }
  102.  
  103. function hideLinks(){
  104. $('#divLinks').css('display','none');
  105. }
  106.  
  107. //-------------------------------------------------------------------
  108. // Add a <style> section to the document.
  109. //-------------------------------------------------------------------
  110. function addStyle(aCss) {
  111. var head, style;
  112. head = document.getElementsByTagName('head')[0];
  113. if (head) {
  114. style = document.createElement('style');
  115. style.setAttribute('type', 'text/css');
  116. style.textContent = aCss;
  117. head.appendChild(style);
  118. return style;
  119. }
  120. return null;
  121. }