Wanikani Scrollbox

Adds a space on the dashboard that displays items randomly to help remember them without seeing them in 'the wild'.

  1. // ==UserScript==
  2. // @name Wanikani Scrollbox
  3. // @namespace wkscrollbox
  4. // @description Adds a space on the dashboard that displays items randomly to help remember them without seeing them in 'the wild'.
  5. // @exclude *.wanikani.com
  6. // @include *.wanikani.com/dashboard*
  7. // @version 0.9.1.3
  8. // @author Samuel H
  9. // @grant none
  10.  
  11. /* This script is licensed under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) license
  12. * Details: http://creativecommons.org/licenses/by-nc/4.0/ */
  13.  
  14. //IMPORTANT: IF THIS IS THE FIRST TIME YOU'VE USED ONE OF MY SCRIPTS THEN YOU NEED TO PUT YOUR API KEY BETWEEN THE DOUBLE QUOTES ON THE LINE BELOW.
  15. apiKey = "";
  16. //Change this to false if you want the scrollbox section above the forum section.
  17. SBPageTop = true;
  18.  
  19. $("head").append('<script src="https://rawgit.com/WaniKani/WanaKana/master/lib/wanakana.min.js" type="text/javascript"></script>' +
  20. '<script src="https://rawgit.com/tobia/Pause/master/jquery.pause.min.js" type="text/javascript"></script>"');
  21.  
  22. function getSBSection() {
  23. var intSectionHeight = SBHeight * 100;
  24. var strSection = '<section id="scroll-box-section" style="width: 100%; height: ' + (intSectionHeight + 30) + 'px; border-radius: 5px; position: relative">' +
  25. '<div class="answer-exception-form" id="info-window" align="center" style="z-index: 101; display: none"></div>' +
  26. '<div id="scroll-box-buttons" style="width: 100%; height: 30px"></div>' +
  27. '<div id="sb-col-sel-tgl" class="Burned" style="border-top-right-radius: 5px; border-bottom-right-radius: 5px; -ms-writing-mode: tb-rl; -webkit-writing-mode: vertical-rl; display: none; color: #fff; text-shadow: none; ' +
  28. '-moz-writing-mode: vertical-rl; -ms-writing-mode: vertical-rl; writing-mode: vertical-rl; width: 15px; height: ' + ((!SBLangJP) ? '55px; padding: 5px 10px 5px 15px' : '35px; padding: 20px 10px 10px 15px') +
  29. '; margin-top: 30px; right: -10px; position: absolute; background-image: linear-gradient(to bottom, #555, #4B4B4B);\"><span lang="jp" style="font-size: 20px; margin-bottom: 0px">' + ((!SBLangJP) ? "Color" : "色") + '</span></div>' +
  30. '<div id="sb-col-sel" class="Burned" style="border-top-right-radius: 5px; border-bottom-right-radius: 5px; right: 0px; background-color: #eee; position: absolute; width: 90px; height: 90px">' +
  31. '</div><div id="scroll-box" style="overflow: hidden; width: 100%; height: ' + intSectionHeight + 'px; border-radius: 5px; position: relative">' +
  32. '<div id="loadingSB" style="background-color: #d4d4d4; width: 100%; height: ' + intSectionHeight + 'px; border-radius: 5px; position: relative; text-align: center; padding-top: ' + (intSectionHeight * 0.375) + 'px"></div>' +
  33. '<div id="scroll-box-bg" style="background-color: #fff; width: 100%; height: ' + intSectionHeight + 'px; border-radius: 5px; position: absolute"></div>' +
  34. '</div></section>';
  35. return strSection;
  36. }
  37.  
  38. function newSBItem() {
  39. var curSBI = -1;
  40. var SBIType = -1;
  41. var SBISrs = -1;
  42. var SBIIndex = -1;
  43. var indexArray = [];
  44. var indexArrayLoc = [];
  45. var iaLen = 0;
  46. if (SBRadicalsEnabled) {
  47. if (SBKanjiEnabled) {
  48. if (SBVocabularyEnabled) {
  49. if (SBApprenticeEnabled) {
  50. indexArray = indexArray.concat(SBIndex.radicals.apprentice, SBIndex.kanji.apprentice, SBIndex.vocabulary.apprentice);
  51. indexArrayLoc.push([0, 0, 0], [0, 1, SBIndexCount.radicals.apprentice], [0, 2, SBIndexCount.radicals.apprentice + SBIndexCount.kanji.apprentice]);
  52. iaLen = indexArray.length;
  53. }
  54. if (SBGuruEnabled) {
  55. indexArray = indexArray.concat(SBIndex.radicals.guru, SBIndex.kanji.guru, SBIndex.vocabulary.guru);
  56. indexArrayLoc.push([1, 0, iaLen], [1, 1, iaLen + SBIndexCount.radicals.guru], [1, 2, iaLen + SBIndexCount.radicals.guru + SBIndexCount.kanji.guru]);
  57. iaLen = indexArray.length;
  58. }
  59. if (SBMasterEnabled) {
  60. indexArray = indexArray.concat(SBIndex.radicals.master, SBIndex.kanji.master, SBIndex.vocabulary.master);
  61. indexArrayLoc.push([2, 0, iaLen], [2, 1, iaLen + SBIndexCount.radicals.master], [2, 2, iaLen + SBIndexCount.radicals.master + SBIndexCount.kanji.master]);
  62. iaLen = indexArray.length;
  63. }
  64. if (SBEnlightenEnabled) {
  65. indexArray = indexArray.concat(SBIndex.radicals.enlighten, SBIndex.kanji.enlighten, SBIndex.vocabulary.enlighten);
  66. indexArrayLoc.push([3, 0, iaLen], [3, 1, iaLen + SBIndexCount.radicals.enlighten], [3, 2, iaLen + SBIndexCount.radicals.enlighten + SBIndexCount.kanji.enlighten]);
  67. iaLen = indexArray.length;
  68. }
  69. if (SBBurnedEnabled) {
  70. indexArray = indexArray.concat(SBIndex.radicals.burned, SBIndex.kanji.burned, SBIndex.vocabulary.burned);
  71. indexArrayLoc.push([4, 0, iaLen], [4, 1, iaLen + SBIndexCount.radicals.burned], [4, 2, iaLen + SBIndexCount.radicals.burned + SBIndexCount.kanji.burned]);
  72. iaLen = indexArray.length;
  73. }
  74. if (SBLockedEnabled) {
  75. indexArray = indexArray.concat(SBIndex.radicals.locked, SBIndex.kanji.locked, SBIndex.vocabulary.locked);
  76. indexArrayLoc.push([5, 0, iaLen], [5, 1, iaLen + SBIndexCount.radicals.locked], [5, 2, iaLen + SBIndexCount.radicals.locked + SBIndexCount.kanji.locked]);
  77. iaLen = indexArray.length;
  78. }
  79. } else {
  80. if (SBApprenticeEnabled) {
  81. indexArray = indexArray.concat(SBIndex.radicals.apprentice, SBIndex.kanji.apprentice);
  82. indexArrayLoc.push([0, 0, 0], [0, 1, SBIndexCount.radicals.apprentice]);
  83. iaLen = indexArray.length;
  84. }
  85. if (SBGuruEnabled) {
  86. indexArray = indexArray.concat(SBIndex.radicals.guru, SBIndex.kanji.guru);
  87. indexArrayLoc.push([1, 0, iaLen], [1, 1, iaLen + SBIndexCount.radicals.guru]);
  88. iaLen = indexArray.length;
  89. }
  90. if (SBMasterEnabled) {
  91. indexArray = indexArray.concat(SBIndex.radicals.master, SBIndex.kanji.master);
  92. indexArrayLoc.push([2, 0, iaLen], [2, 1, iaLen + SBIndexCount.radicals.master]);
  93. iaLen = indexArray.length;
  94. }
  95. if (SBEnlightenEnabled) {
  96. indexArray = indexArray.concat(SBIndex.radicals.enlighten, SBIndex.kanji.enlighten);
  97. indexArrayLoc.push([3, 0, iaLen], [3, 1, iaLen + SBIndexCount.radicals.enlighten]);
  98. iaLen = indexArray.length;
  99. }
  100. if (SBBurnedEnabled) {
  101. indexArray = indexArray.concat(SBIndex.radicals.burned, SBIndex.kanji.burned);
  102. indexArrayLoc.push([4, 0, iaLen], [4, 1, iaLen + SBIndexCount.radicals.burned]);
  103. iaLen = indexArray.length;
  104. }
  105. if (SBLockedEnabled) {
  106. indexArray = indexArray.concat(SBIndex.radicals.locked, SBIndex.kanji.locked);
  107. indexArrayLoc.push([5, 0, iaLen], [5, 1, iaLen + SBIndexCount.radicals.locked]);
  108. iaLen = indexArray.length;
  109. }
  110. }
  111. } else {
  112. if (SBVocabularyEnabled) {
  113. if (SBApprenticeEnabled) {
  114. indexArray = indexArray.concat(SBIndex.radicals.apprentice, SBIndex.vocabulary.apprentice);
  115. indexArrayLoc.push([0, 0, 0], [0, 2, SBIndexCount.radicals.apprentice]);
  116. iaLen = indexArray.length;
  117. }
  118. if (SBGuruEnabled) {
  119. indexArray = indexArray.concat(SBIndex.radicals.guru, SBIndex.vocabulary.guru);
  120. indexArrayLoc.push([1, 0, iaLen], [1, 2, iaLen + SBIndexCount.radicals.guru]);
  121. iaLen = indexArray.length;
  122. }
  123. if (SBMasterEnabled) {
  124. indexArray = indexArray.concat(SBIndex.radicals.master, SBIndex.vocabulary.master);
  125. indexArrayLoc.push([2, 0, iaLen], [2, 2, iaLen + SBIndexCount.radicals.master]);
  126. iaLen = indexArray.length;
  127. }
  128. if (SBEnlightenEnabled) {
  129. indexArray = indexArray.concat(SBIndex.radicals.enlighten, SBIndex.vocabulary.enlighten);
  130. indexArrayLoc.push([3, 0, iaLen], [3, 2, iaLen + SBIndexCount.radicals.enlighten]);
  131. iaLen = indexArray.length;
  132. }
  133. if (SBBurnedEnabled) {
  134. indexArray = indexArray.concat(SBIndex.radicals.burned, SBIndex.vocabulary.burned);
  135. indexArrayLoc.push([4, 0, iaLen], [4, 2, iaLen + SBIndexCount.radicals.burned]);
  136. iaLen = indexArray.length;
  137. }
  138. if (SBLockedEnabled) {
  139. indexArray = indexArray.concat(SBIndex.radicals.locked, SBIndex.vocabulary.locked);
  140. indexArrayLoc.push([5, 0, iaLen], [5, 2, iaLen + SBIndexCount.radicals.locked]);
  141. iaLen = indexArray.length;
  142. }
  143. } else {
  144. if (SBApprenticeEnabled) {
  145. indexArray = indexArray.concat(SBIndex.radicals.apprentice);
  146. indexArrayLoc.push([0, 0, 0]);
  147. iaLen = indexArray.length;
  148. }
  149. if (SBGuruEnabled) {
  150. indexArray = indexArray.concat(SBIndex.radicals.guru);
  151. indexArrayLoc.push([1, 0, iaLen]);
  152. iaLen = indexArray.length;
  153. }
  154. if (SBMasterEnabled) {
  155. indexArray = indexArray.concat(SBIndex.radicals.master);
  156. indexArrayLoc.push([2, 0, iaLen]);
  157. iaLen = indexArray.length;
  158. }
  159. if (SBEnlightenEnabled) {
  160. indexArray = indexArray.concat(SBIndex.radicals.enlighten);
  161. indexArrayLoc.push([3, 0, iaLen]);
  162. iaLen = indexArray.length;
  163. }
  164. if (SBBurnedEnabled) {
  165. indexArray = indexArray.concat(SBIndex.radicals.burned);
  166. indexArrayLoc.push([4, 0, iaLen]);
  167. iaLen = indexArray.length;
  168. }
  169. if (SBLockedEnabled) {
  170. indexArray = indexArray.concat(SBIndex.radicals.locked);
  171. indexArrayLoc.push([5, 0, iaLen]);
  172. iaLen = indexArray.length;
  173. }
  174. }
  175. }
  176. } else if (SBKanjiEnabled) {
  177. if (SBVocabularyEnabled) {
  178. if (SBApprenticeEnabled) {
  179. indexArray = indexArray.concat(SBIndex.kanji.apprentice, SBIndex.vocabulary.apprentice);
  180. indexArrayLoc.push([0, 1, 0], [0, 2, SBIndexCount.kanji.apprentice]);
  181. iaLen = indexArray.length;
  182. }
  183. if (SBGuruEnabled) {
  184. indexArray = indexArray.concat(SBIndex.kanji.guru, SBIndex.vocabulary.guru);
  185. indexArrayLoc.push([1, 1, iaLen], [1, 2, iaLen + SBIndexCount.kanji.guru]);
  186. iaLen = indexArray.length;
  187. }
  188. if (SBMasterEnabled) {
  189. indexArray = indexArray.concat(SBIndex.kanji.master, SBIndex.vocabulary.master);
  190. indexArrayLoc.push([2, 1, iaLen], [2, 2, iaLen + SBIndexCount.kanji.master]);
  191. iaLen = indexArray.length;
  192. }
  193. if (SBEnlightenEnabled) {
  194. indexArray = indexArray.concat(SBIndex.kanji.enlighten, SBIndex.vocabulary.enlighten);
  195. indexArrayLoc.push([3, 1, iaLen], [3, 2, iaLen + SBIndexCount.kanji.enlighten]);
  196. iaLen = indexArray.length;
  197. }
  198. if (SBBurnedEnabled) {
  199. indexArray = indexArray.concat(SBIndex.kanji.burned, SBIndex.vocabulary.burned);
  200. indexArrayLoc.push([4, 1, iaLen], [4, 2, iaLen + SBIndexCount.kanji.burned]);
  201. iaLen = indexArray.length;
  202. }
  203. if (SBLockedEnabled) {
  204. indexArray = indexArray.concat(SBIndex.kanji.locked, SBIndex.vocabulary.locked);
  205. indexArrayLoc.push([5, 1, iaLen], [5, 2, iaLen + SBIndexCount.kanji.locked]);
  206. iaLen = indexArray.length;
  207. }
  208. } else {
  209. if (SBApprenticeEnabled) {
  210. indexArray = indexArray.concat(SBIndex.kanji.apprentice);
  211. indexArrayLoc.push([0, 1, 0]);
  212. iaLen = indexArray.length;
  213. }
  214. if (SBGuruEnabled) {
  215. indexArray = indexArray.concat(SBIndex.kanji.guru);
  216. indexArrayLoc.push([1, 1, iaLen]);
  217. iaLen = indexArray.length;
  218. }
  219. if (SBMasterEnabled) {
  220. indexArray = indexArray.concat(SBIndex.kanji.master);
  221. indexArrayLoc.push([2, 1, iaLen]);
  222. iaLen = indexArray.length;
  223. }
  224. if (SBEnlightenEnabled) {
  225. indexArray = indexArray.concat(SBIndex.kanji.enlighten);
  226. indexArrayLoc.push([3, 1, iaLen]);
  227. iaLen = indexArray.length;
  228. }
  229. if (SBBurnedEnabled) {
  230. indexArray = indexArray.concat(SBIndex.kanji.burned);
  231. indexArrayLoc.push([4, 1, iaLen]);
  232. iaLen = indexArray.length;
  233. }
  234. if (SBLockedEnabled) {
  235. indexArray = indexArray.concat(SBIndex.kanji.locked);
  236. indexArrayLoc.push([5, 1, iaLen]);
  237. iaLen = indexArray.length;
  238. }
  239. }
  240. } else {
  241. if (SBApprenticeEnabled) {
  242. indexArray = indexArray.concat(SBIndex.vocabulary.apprentice);
  243. indexArrayLoc.push([0, 2, 0]);
  244. iaLen = indexArray.length;
  245. }
  246. if (SBGuruEnabled) {
  247. indexArray = indexArray.concat(SBIndex.vocabulary.guru);
  248. indexArrayLoc.push([1, 2, iaLen]);
  249. iaLen = indexArray.length;
  250. }
  251. if (SBMasterEnabled) {
  252. indexArray = indexArray.concat(SBIndex.vocabulary.master);
  253. indexArrayLoc.push([2, 2, iaLen]);
  254. iaLen = indexArray.length;
  255. }
  256. if (SBEnlightenEnabled) {
  257. indexArray = indexArray.concat(SBIndex.vocabulary.enlighten);
  258. indexArrayLoc.push([3, 2, iaLen]);
  259. iaLen = indexArray.length;
  260. }
  261. if (SBBurnedEnabled) {
  262. indexArray = indexArray.concat(SBIndex.vocabulary.burned);
  263. indexArrayLoc.push([4, 2, iaLen]);
  264. iaLen = indexArray.length;
  265. }
  266. if (SBLockedEnabled) {
  267. indexArray = indexArray.concat(SBIndex.vocabulary.locked);
  268. indexArrayLoc.push([5, 2, iaLen]);
  269. iaLen = indexArray.length;
  270. }
  271. }
  272. //alert(Object.keys(indexArray).length)
  273. curSBI = rand(0, Object.keys(indexArray).length - 1);
  274. /*if (SBIType == 0) curSBType = 0;
  275. else {
  276. curSBType = rand(0, 1);
  277. if (SBIType == 1) {
  278. if (SBRadicalsEnabled) curSBI -= Object.keys(SBRadicalData).length;
  279. } else if (SBIType == 2) {
  280. if (SBRadicalsEnabled) {
  281. if (SBKanjiEnabled) curSBI -= (Object.keys(SBRadicalData).length + Object.keys(SBKanjiData).length);
  282. else curSBI -= (Object.keys(SBRadicalData).length);
  283. } else if (SBKanjiEnabled) curSBI -= Object.keys(SBKanjiData).length;
  284. }
  285. }*/
  286. //alert(SBLockedEnabled + " " + SBEnlightenEnabled + " " + SBApprenticeEnabled);
  287. var foundLoc = false;
  288. for (var t = 1; t <= Object.keys(indexArrayLoc).length; t++) {
  289. /*if (t < Object.keys(indexArrayLoc).length && indexArrayLoc[t-1][2] == indexArrayLoc[t][2]) {
  290. indexArrayLoc = indexArrayLoc.splice(t-1);
  291. }*/
  292. if (!foundLoc) {
  293. if (t == Object.keys(indexArrayLoc).length || curSBI < indexArrayLoc[t][2]) {
  294. SBIType = indexArrayLoc[t-1][1];
  295. SBIIndex = indexArray[curSBI];
  296. SBISrs = (SBIType == 0) ? SBRadicalData[SBIIndex].srs : ((SBIType == 1) ? SBKanjiData[SBIIndex].srs : SBVocabData[SBIIndex].srs);
  297. switch(SBISrs) {
  298. case "apprentice":
  299. SBISrs = 0;
  300. break;
  301. case "guru":
  302. SBISrs = 1;
  303. break;
  304. case "master":
  305. SBISrs = 2;
  306. break;
  307. case "enlighten":
  308. SBISrs = 3;
  309. break;
  310. case "burned":
  311. SBISrs = 4;
  312. break;
  313. case null:
  314. SBISrs = 5;
  315. }
  316. if (SBISrs !== indexArrayLoc[t-1][0]) alert("SRS mismatch: " + indexArrayLoc[t-1][0] + " should be " + SBISrs);
  317. foundLoc = true;
  318. }
  319. }
  320. }
  321. var SBISize = rand(14, 49);
  322. var SBISpeed = rand(0.75, 1.25);
  323. var SBIx = 1170;
  324. var SBIy = 0;
  325. SBICount++;
  326. //alert(SBIndex.kanji);
  327. $("#scroll-box").prepend('<a href="https://www.wanikani.com/' + ((SBIType == 0) ? "radicals" : ((SBIType == 1) ? "kanji" : "vocabulary")) + '/' +
  328. ((SBIType == 0) ? SBRadicalData[SBIIndex].meaning : ((SBIType == 1) ? SBKanjiData[SBIIndex].character : SBVocabData[SBIIndex].character)) +
  329. '" target="_blank" id="SBI' + SBICount + '" lang="ja" cc="' + ((SBIType == 0) ? SBIndexBG.radicals[SBIIndex] : ((SBIType == 1) ? SBIndexBG.kanji[SBIIndex] : SBIndexBG.vocabulary[SBIIndex])) +
  330. '">' + ((SBIType == 0) ? SBRadicalData[SBIIndex].character : ((SBIType == 1) ? SBKanjiData[SBIIndex].character : SBVocabData[SBIIndex].character)) + '</a>');
  331. var SBI = $("#SBI" + SBICount);
  332. SBI.css({"font-size": SBISize, "text-decoration": "none", "line-height": (SBISize * 1.25) + "px", "min-width": (SBISize * 1.1) + "px", "text-align": "center", "padding": "0px " + ((SBISize / 35) * 2) + "px 0px " + ((SBISize / 35) * 2) + "px"});
  333. var SBIw = SBI.width();
  334. var SBIh = SBI.height();
  335. //alert(SBIh);
  336. SBIy = rand(0, (SBHeight * 100) - (SBISize * 1.25));
  337. switch (SBISrs) {
  338. case 0:
  339. SBI.addClass("Apprentice");
  340. break;
  341. case 1:
  342. SBI.addClass("Guru");
  343. break;
  344. case 2:
  345. SBI.addClass("Master");
  346. break;
  347. case 3:
  348. SBI.addClass("Enlightened");
  349. break;
  350. case 4:
  351. SBI.addClass("Burned");
  352. break;
  353. case 5:
  354. SBI.addClass("Locked");
  355. }
  356. if (SBI.attr("cc") > 0) SBI.addClass("sbcc" + SBI.attr("cc"));
  357. SBI.css({"color": (((SBI.attr("cc") == 0 && SBISrs < 5) || SBI.attr("cc") > 1) ? "#fff" : (SBI.attr("cc") > 1) ? "#E3E3E3" : "#ccc"), "margin-top": SBIy, "left": SBIx + SBISize, "margin-right": -SBIw * 1.5, "border-radius": (SBISize * 0.15) + "px", "z-index": SBISize, "position": "absolute",
  358. "-webkit-touch-callout": "none", "-webkit-user-select": "none", "-khtml-user-select": "none", "-moz-user-select": "none", "-ms-user-select": "none", "user-select": "none"});
  359. SBI.animate({ "left": -SBIw*1.5}, {"duration": (SBISpeed * Math.pow((SBISize / 17), -1.1)) * 49000 / SBSpeed, "queue": false, "complete": function() {
  360. $(this).remove();
  361. }
  362. }, "linear" ).attr("speed", SBISpeed);
  363. SBI.mouseover(function() {
  364. SBPause = true;
  365. clearInterval(newSBItemTimer);
  366. var SBIP;
  367. for (var p = 1; p <= SBICount; p++) {
  368. SBIP = $("#SBI" + p);
  369. SBIP.pause();
  370. }
  371. if (SBColIndex > -1) $(this).attr("link", $(this).attr("href")).attr("href", "javascript:void(1)");
  372. else if (SBColIndex == 15) SBColIndex = rand(1, 14);
  373. SBSelect($(this), SBIType);
  374. $(this).attr("oldZ", $(this).css("z-index")).css("z-index", 99);
  375. }).mouseout(function() {
  376. SBPause = false;
  377. newSBItemTimer = setInterval(newSBItem, 1500 / SBSpeed);
  378. var SBIR;
  379. for (var r = 1; r <= SBICount; r++) {
  380. SBIR = $("#SBI" + r);
  381. SBIR.resume();
  382. }
  383. SBSelect(null);
  384. $(this).css({"z-index": $(this).attr("oldZ")});
  385. if (SBColIndex > -1) $(this).attr("href", $(this).attr("link")).removeAttr("link");
  386. }).mousedown(function() {
  387. if (SBColIndex > -1) {
  388. if (!$(this).hasClass("Locked")) {
  389. colIndex = (SBColIndex < 15) ? SBColIndex : rand(1, 14);
  390. if ($(this).attr("cctemp") === undefined) {
  391. $(this).attr("cctemp", $(this).attr("cc"));
  392. if ($(this).attr("cc") > 0) $(this).removeClass("sbcc" + $(this).attr("cc"));
  393. if (colIndex > 0) $(this).attr("cc", colIndex).addClass("sbcc" + colIndex);
  394. else $(this).attr("cc", 0).removeClass("sbcc" + $(this).attr("cc"));
  395. if (colIndex == 1) $(this).css("color", "#aaa");
  396. else if ($(this).attr("cctemp") == 1) $(this).css("color", "#fff");
  397. } else {
  398. $(this).attr("cctemp2", $(this).attr("cc"));
  399. if ($(this).attr("cc") > 0) $(this).removeClass("sbcc" + $(this).attr("cc"));
  400. if ($(this).attr("cctemp") > 0) $(this).attr("cc", $(this).attr("cctemp")).addClass("sbcc" + $(this).attr("cctemp"));
  401. else $(this).attr("cc", 0).removeClass("sbcc" + $(this).attr("cctemp"));
  402. if ($(this).attr("cc") == 1) $(this).css("color", "#ccc");
  403. else if ($(this).attr("cctemp2") == 1) $(this).css("color", "#fff");
  404. $(this).attr("cctemp", $(this).attr("cctemp2")).removeAttr("cctemp2");
  405. if (SBColIndex == 15) $(this).removeAttr("cctemp");
  406. }
  407. if ($(this).attr("link").indexOf("/radicals/") > 0) SBIndexBG.radicals[getSBIndex(0, $(this).attr("link").substring($(this).attr("link").indexOf("s/") + 2))] = colIndex;
  408. else if ($(this).attr("link").indexOf("/kanji/") > 0) SBIndexBG.kanji[getSBIndex(1, $(this).attr("link").substring($(this).attr("link").indexOf("i/") + 2))] = colIndex;
  409. else SBIndexBG.vocabulary[getSBIndex(2, $(this).attr("link").substring($(this).attr("link").indexOf("y/") + 2))] = colIndex;
  410. localStorage.setItem("SBIndexBG", JSON.stringify(SBIndexBG));
  411. }
  412. }
  413. /*$("#info-window").html('<span style="display:inline-block;padding:0.5em 0.7em 0.6em;background-color:#a2a2a2;color:#fff;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-box-shadow:3px 3px 0 #e1e1e1;\
  414. -moz-box-shadow:3px 3px 0 #e1e1e1;box-shadow:3px 3px 0 #e1e1e1;position: absolute; width: 560px; height: 410px; margin-top: 0px; margin-left: 30px; top: -200px; bottom: initial; left: initial; z-index: 102">\
  415. <iframe src="' + $(this).attr("link") + '#information" width="550" height="400" style="position: relative; z-index: 103"></iframe></span>').css({"display": "block"}).addClass("animated fadeInUp");*/
  416. }).mouseup(function() {
  417. });
  418. }
  419.  
  420. function getSBIndex(type, id) {
  421. if (type > 0) {
  422. if (type == 2) {
  423. for (var v = 0; v < Object.keys(SBVocabData).length; v++) {
  424. if (SBVocabData[v].character == id) {
  425. return v;
  426. }
  427. }
  428. } else {
  429. for (var k = 0; k < Object.keys(SBKanjiData).length; k++) {
  430. if (SBKanjiData[k].character == id) {
  431. return k;
  432. }
  433. }
  434. }
  435. } else {
  436. for (var r = 0; r < Object.keys(SBRadicalData).length; r++) {
  437. if (SBRadicalData[r].meaning == id) {
  438. return r;
  439. }
  440. }
  441. }
  442. }
  443.  
  444. function getSBRadicalData() {
  445. if (!SBLangJP) $("#loadingSB").html('<h3 style="color: #00a0f1">Retrieving radical data...</h3>');
  446. else $("#loadingSB").html('<h3 style="color: #00a0f1">部首データを検索中…</h3>');
  447. var req = new XMLHttpRequest();
  448. req.open('GET', 'https://www.wanikani.com/api/user/' + apiKey + '/radicals/' + SBLevels, true);
  449. req.onreadystatechange = function() {
  450. if (req.readyState === 4) {
  451. if (req.status >= 200 && req.status < 400) {
  452. SBRadicalData = filterSBRadicalData(req.responseText.split('"character":"'));
  453. localStorage.setItem("SBRadicals", JSON.stringify(SBRadicalData));
  454. getSBKanjiData();
  455. } else {
  456. alert("error");
  457. }
  458. }
  459. };
  460. req.send();
  461. }
  462.  
  463. function getSBKanjiData() {
  464. if (!SBLangJP) $("#loadingSB").html('<h3 style="color: #f100a0">Retrieving kanji data...</h3>');
  465. else $("#loadingSB").html('<h3 style="color: #f100a0">漢字データを検索中…</h3>');
  466. var req = new XMLHttpRequest();
  467. req.open('GET', 'https://www.wanikani.com/api/user/' + apiKey + '/kanji/' + SBLevels , true);
  468. req.onreadystatechange = function() {
  469. if (req.readyState === 4) {
  470. if (req.status >= 200 && req.status < 400) {
  471. SBKanjiData = filterSBKanjiData(req.responseText.split('"character":"'));
  472. localStorage.setItem("SBKanji", JSON.stringify(SBKanjiData));
  473. getSBVocabData(true);
  474. } else {
  475. alert("error");
  476. }
  477. }
  478. };
  479. req.send();
  480. }
  481.  
  482. function getSBVocabData(firstPart) {
  483. if (!SBLangJP) $("#loadingSB").html('<h3 style="color: #a000f1">Retrieving vocabulary data...</h3>');
  484. else $("#loadingSB").html('<h3 style="color: #a000f1">単語データを検索中…</h3>');
  485. var req = new XMLHttpRequest();
  486. req.open('GET', 'https://www.wanikani.com/api/user/' + apiKey + '/vocabulary/' + ((firstPart) ? SBLevels.substring(0, SBLevels.indexOf(",26")) : SBLevels.substring(SBLevels.indexOf("26"))), true);
  487. req.onreadystatechange = function() {
  488. if (req.readyState === 4) {
  489. if (req.status >= 200 && req.status < 400) {
  490. if (!firstPart) {
  491. SBVocabData[1] = req.responseText.split('"character":"');
  492. SBVocabData = filterSBVocabData(SBVocabData);
  493. localStorage.setItem("SBVocab", JSON.stringify(SBVocabData));
  494. localStorage.setItem("SBIndex", JSON.stringify(SBIndex));
  495. localStorage.setItem("SBIndexCount", JSON.stringify(SBIndexCount));
  496. initScrollBox();
  497. } else {
  498. SBVocabData[0] = req.responseText.split('"character":"');
  499. getSBVocabData(false);
  500. }
  501. } else {
  502. alert("error");
  503. }
  504. }
  505. };
  506. req.send();
  507. }
  508.  
  509. function switchSBLang() {
  510. SBLangJP = !SBLangJP;
  511. if (SBLangJP) {
  512. $(".bsbsa span").html("見習い");
  513. $(".bsbsg span").html("尊師");
  514. $(".bsbsm span").html("達人");
  515. $(".bsbse span").html("啓発");
  516. $(".bsbsb span").html("焦げ");
  517. $(".bsbsl span").html("ロック");
  518. $(".bsbtc span").html("キャッシュ").css({"font-size": "14px", "padding-top": "3px"});
  519. $(".bsbts span").html("スタート\nボタン").css({"font-size": "14px"});
  520. $(".bsbmlh").html("高さの乗数").css({"font-size": "14px", "padding": "0px 5px 0px 10px"});
  521. $(".bsbmh").css("margin-top", "0px");
  522. $(".bsbmls").html("速度の乗数").css({"font-size": "14px", "padding-top": "0px"});
  523. $(".bsbms").css("margin-top", "-20px");
  524. $("#sb-col-sel-tgl span").html("色").parent().css({"padding": "20px 10px 10px 15px", "height": "35px"});
  525. } else {
  526. $(".bsbsa span").html("Appr");
  527. $(".bsbsg span").html("Guru");
  528. $(".bsbsm span").html("Master");
  529. $(".bsbse span").html("Enlight");
  530. $(".bsbsb span").html("Burned");
  531. $(".bsbsl span").html("Locked");
  532. $(".bsbtc span").html("Cache").css({"font-size": "inherit", "padding-top": "0px"});
  533. $(".bsbts span").html("Start\nButton").css({"font-size": "12px"});
  534. $(".bsbmlh").html("Height Multiplier").css({"font-size": "9px", "padding": "0px 5px 0px 5px"});
  535. $(".bsbmh").css("margin-top", "5px");
  536. $(".bsbmls").html("Speed Multiplier").css({"font-size": "9px", "padding-top": "8px"});
  537. $(".bsbms").css("margin-top", "-16px");
  538. $("#sb-col-sel-tgl span").html("Color").parent().css({"padding": "5px 10px 5px 15px", "height": "55px"});
  539. }
  540. }
  541.  
  542. function SBResize() {
  543. var intSBHeight = SBHeight * 100;
  544. $("#scroll-box-section").css({"-webkit-transition": "1s ease-in-out",
  545. "-moz-transition": "1s ease-in-out",
  546. "-o-transition": "1s ease-in-out",
  547. "transition": "1s ease-in-out",
  548. "height": (intSBHeight + 30) + "px"});
  549. $("#scroll-box, #scroll-box-bg").css({"-webkit-transition": "1s ease-in-out",
  550. "-moz-transition": "1s ease-in-out",
  551. "-o-transition": "1s ease-in-out",
  552. "transition": "1s ease-in-out",
  553. "height": intSBHeight + "px"});
  554. }
  555.  
  556.  
  557. function getSBWKData() {
  558. if (localStorage.getItem("SBRadicals") === null || localStorage.getItem("SBKanji") === null || localStorage.getItem("SBVocab") === null) getSBRadicalData();
  559. else {
  560. SBRadicalData = JSON.parse(localStorage.getItem("SBRadicals"));
  561. SBKanjiData = JSON.parse(localStorage.getItem("SBKanji"));
  562. SBVocabData = JSON.parse(localStorage.getItem("SBVocab"));
  563. initScrollBox();
  564. }
  565. }
  566.  
  567. function clearSBItemData() {
  568. localStorage.removeItem("SBRadicals");
  569. localStorage.removeItem("SBKanji");
  570. localStorage.removeItem("SBVocab");
  571. localStorage.removeItem("SBIndex");
  572. localStorage.removeItem("SBIndexCount");
  573. SBIndex = {
  574. "radicals": {
  575. "apprentice": [], "guru": [], "master": [], "enlighten": [], "burned": [], "locked": []
  576. }, "kanji": {
  577. "apprentice": [], "guru": [], "master": [], "enlighten": [], "burned": [], "locked": []
  578. }, "vocabulary": {
  579. "apprentice": [], "guru": [], "master": [], "enlighten": [], "burned": [], "locked": []
  580. }
  581. };
  582. SBIndexCount = {
  583. "radicals": {
  584. "apprentice": 0, "guru": 0, "master": 0, "enlighten": 0, "burned": 0, "locked": 0
  585. }, "kanji": {
  586. "apprentice": 0, "guru": 0, "master": 0, "enlighten": 0, "burned": 0, "locked": 0
  587. }, "vocabulary": {
  588. "apprentice": 0, "guru": 0, "master": 0, "enlighten": 0, "burned": 0, "locked": 0
  589. }
  590. };
  591. }
  592.  
  593. function initScrollBox() {
  594. if (Object.keys(SBIndexBG.vocabulary).length === 0) {
  595. for (var r = 0; r < Object.keys(SBRadicalData).length; r++) SBIndexBG.radicals.push(0);
  596. for (var k = 0; k < Object.keys(SBKanjiData).length; k++) SBIndexBG.kanji.push(0);
  597. for (var v = 0; v < Object.keys(SBVocabData).length; v++) SBIndexBG.vocabulary.push(0);
  598. }
  599. $("#loadingSB").remove();
  600. $("head").append("<style type=text/css>\
  601. #scroll-box-section span {\
  602. display: block;\
  603. margin-bottom: 0.5em;\
  604. font-weight: bold;\
  605. line-height: 1.0em;\
  606. }\
  607. .bsbi div, .bsbs div, .bsbt div, .bsbm div div {\
  608. background-color: rgb(49, 49, 49);\
  609. background-image: linear-gradient(to bottom, rgb(67, 67, 67), rgb(49, 49, 49));\
  610. color: #E3E3E3\
  611. -moz-box-shadow: inset 2px 2px 2px rgba(255, 255, 255, .2), inset -2px -2px 2px rgba(0, 0, 0, .2);\
  612. -webkit-box-shadow: inset 2px 2px 2px rgba(255, 255, 255, .2), inset -2px -2px 2px rgba(0, 0, 0, .2);\
  613. box-shadow: inset 2px 2px 2px rgba(255, 255, 255, .2), inset -2px -2px 2px rgba(0, 0, 0, .2);\
  614. }\
  615. .bsbir.on {\
  616. background-color: #00a0f1; background-image: linear-gradient(to bottom, #0af, #0093dd);\
  617. }\
  618. .bsbik.on {\
  619. background-color: #f100a0; background-image: linear-gradient(to bottom, #f0a, #dd0093);\
  620. }\
  621. .bsbiv.on {\
  622. background-color: #a000f1; background-image: linear-gradient(to bottom, #a0f, #9300dd);\
  623. }\
  624. .bsbt .on, .bsbm div .on {\
  625. background-color: #80c100; background-image: linear-gradient(to bottom, #8c0, #73ad00);\
  626. }\
  627. .Apprentice, .bsbsa.on {\
  628. background: #f100a0;\
  629. border-color: #f100a0;\
  630. background-image: linear-gradient(to bottom, #f0a, #dd0093);\
  631. }\
  632. .Guru, .bsbsg.on {\
  633. background: #882d9e;\
  634. border-color: #882d9e;\
  635. background-image: linear-gradient(to bottom, #aa38c6, #882d9e);\
  636. }\
  637. .Master, .bsbsm.on {\
  638. background: #294ddb;\
  639. border-color: #294ddb;\
  640. background-image: linear-gradient(to bottom, #5571e2, #294ddb);\
  641. }\
  642. .Enlightened, .bsbse.on {\
  643. background: #0093dd;\
  644. border-color: #0093dd;\
  645. background-image: linear-gradient(to bottom, #0af, #0093dd);\
  646. }\
  647. .Burned, .bsbsb.on {\
  648. background: #434343;\
  649. border-color: #434343;\
  650. background-image: linear-gradient(to bottom, #555, #434343);\
  651. }\
  652. .Locked, .bsbsl.on {\
  653. background: #868686;\
  654. border-color: #313131;\
  655. background-image: linear-gradient(to bottom, #bbb, #a3a3a3);\
  656. }\
  657. .on {\
  658. color: #FFF\
  659. }\
  660. .SBSelect {\
  661. opacity: 0.5;\
  662. pointer-events: none;\
  663. }\
  664. .sbcc0 {\
  665. background: #434343;\
  666. background-image: linear-gradient(90deg, #f100a0, #882d9e, #0093dd, #434343, #868686);\
  667. }\
  668. .sbcc1 {\
  669. background: #fff;\
  670. background-image: linear-gradient(to bottom, #fff, #e3e3e3);\
  671. }\
  672. .sbcc2 {\
  673. background: #131313;\
  674. background-image: linear-gradient(to bottom, #131313, #000);\
  675. }\
  676. .sbcc3 {\
  677. background: #ff1313;\
  678. background-image: linear-gradient(to bottom, #ff1313, #e30000);\
  679. }\
  680. .sbcc4 {\
  681. background: #f0a;\
  682. background-image: linear-gradient(to bottom, #fa0, #dd9300);\
  683. }\
  684. .sbcc5 {\
  685. background: #fe0;\
  686. background-image: linear-gradient(to bottom, #fe0, #e3d300);\
  687. }\
  688. .sbcc6 {\
  689. background: #28a0228;\
  690. background-image: linear-gradient(to bottom, #28a028, #1a931a);\
  691. }\
  692. .sbcc7 {\
  693. background: #58e058;\
  694. background-image: linear-gradient(to bottom, #58e058, #48d348);\
  695. }\
  696. .sbcc8 {\
  697. background: #00f0fa;\
  698. background-image: linear-gradient(to bottom, #00f0fa, #00e3f0);\
  699. }\
  700. .sbcc9 {\
  701. background: #1313a0;\
  702. background-image: linear-gradient(to bottom, #1378a0, #006093);\
  703. }\
  704. .sbcc10 {\
  705. background: #1313a0;\
  706. background-image: linear-gradient(to bottom, #1313a0, #000093);\
  707. }\
  708. .sbcc11 {\
  709. background: #a858e0;\
  710. background-image: linear-gradient(to bottom, #a858e0, #9a4ad3);\
  711. }\
  712. .sbcc12 {\
  713. background: #ecbcf3;\
  714. background-image: linear-gradient(to bottom, #ecbcf3, #e0b0d6);\
  715. }\
  716. .sbcc13 {\
  717. background: #ec13a3;\
  718. background-image: linear-gradient(to bottom, #ec13a3, ##e00a90);\
  719. }\
  720. .sbcc14 {\
  721. background: #8c735a;\
  722. background-image: linear-gradient(to bottom, #8c735a, #806650);\
  723. }\
  724. .sbcc15 {\
  725. background: #fff;\
  726. background-image: linear-gradient(to bottom, #fff, #e3e3e3);\
  727. }\
  728. </style>");
  729. $("#scroll-box-buttons").append('<div class="bsbi" style="width: 0px; height: 0px; position: absolute; z-index: 11">\
  730. <div class="bsbir' + ((SBRadicalsEnabled) ? ' on' : '') + '" style="position: absolute"><span lang="ja" style="font-size: inherit">部首</span></div>\
  731. <div class="bsbik' + ((SBKanjiEnabled) ? ' on' : '') + '" style="margin-left: 56px; position: absolute"><span lang="ja" style="font-size: inherit;">漢字</span></div>\
  732. <div class="bsbiv' + ((SBVocabularyEnabled) ? ' on' : '') + '" style="margin-left: 112px; position: absolute"><span lang="ja" style="font-size: inherit">単語</span></div>\
  733. </div>\
  734. <div class="bsbs" style="width: 0px; height: 0px; position: absolute; z-index: 11">\
  735. <div class="bsbsa' + ((SBApprenticeEnabled) ? ' on' : '') + '" style="margin-left: 168px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Appr" : "見習い") + '</span></div>\
  736. <div class="bsbsg' + ((SBGuruEnabled) ? ' on' : '') + '" style="margin-left: 248px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Guru" : "尊師") + '</span></div>\
  737. <div class="bsbsm' + ((SBMasterEnabled) ? ' on' : '') + '" style="margin-left: 328px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Master" : "達人") + '</span></div>\
  738. <div class="bsbse' + ((SBEnlightenEnabled) ? ' on' : '') + '" style="margin-left: 408px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Enlight" : "啓発") + '</span></div>\
  739. <div class="bsbsb' + ((SBBurnedEnabled) ? ' on' : '') + '" style="margin-left: 488px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Burned" : "焦げ") + '</span></div>\
  740. <div class="bsbsl' + ((SBLockedEnabled) ? ' on' : '') + '" style="margin-left: 568px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Locked" : "ロック") + '</span></div></div>\
  741. <div class="bsbt" style="width: 0px; position: absolute; z-index: 11; margin-left: 648px">\
  742. <div class="bsbtj' + ((SBLangJP) ? ' on' : '') + '" style="position: absolute"><span lang="ja" style="font-size: inherit">日本語</span></div>\
  743. <div class="bsbtc' + ((SBUseCache) ? ' on' : '') + '" style="margin-left: 80px; position: absolute"><span lang="ja" style="font-size: ' + ((!SBLangJP) ? "inherit" : "14px; padding-top: 3px") + '">' + ((!SBLangJP) ? "Cache" : "キャッシュ") + '</span></div>\
  744. <div class="bsbts' + ((SBStart) ? ' on' : '') + '" style="margin-left: 160px; position: absolute"><span lang="ja" style="font-size: ' + ((!SBLangJP) ? "12px" : "14px") + '; margin-top: -3px">' + ((!SBLangJP) ? "Start\nButton" : "スタート\nボタン") + '</span></div>\></div>\
  745. </div>\
  746. <div class="bsbm" style="width: 0px; margin-left: 888px; position: absolute; z-index: 11">\
  747. <span class="bsbmlh" style="font-size: ' + ((!SBLangJP) ? "9" : "14") + 'px; width: 80px; padding: 0px 5px 0px ' + ((!SBLangJP) ? "5" : "10") + 'px; margin-bottom: 1px" lang="jp">' + ((!SBLangJP) ? "Height Multiplier" : "高さの乗数") + '</span>\
  748. <div class="bsbmh" style="width: 0px; position: absolute' + ((!SBLangJP) ? "; margin-top: 5px" : "" ) + '">\
  749. <div class="bsbmh0' + ((SBHeight == 1) ? ' on' : '') + '" style="position: absolute; margin-top: -15px; margin-left: 85px; width: 20px"><span style="font-size: 14px; width: 20px; padding: 2px 8px 2px 2px; margin-bottom: 0px" lang="jp">1x</div>\
  750. <div class="bsbmh1' + ((SBHeight == 2) ? ' on' : '') + '" style="position: absolute; margin-top: -15px; margin-left: 113px; width: 20px"><span style="font-size: 14px; width: 20px; padding: 2px 8px 2px 2px; margin-bottom: 0px" lang="jp">2x</div>\
  751. <div class="bsbmh2' + ((SBHeight == 3) ? ' on' : '') + '" style="position: absolute; margin-top: -15px; margin-left: 141px; width: 20px"><span style="font-size: 14px; width: 20px; padding: 2px 8px 2px 2px; margin-bottom: 0px" lang="jp">3x</div>\
  752. <div class="bsbmh3' + ((SBHeight == 4) ? ' on' : '') + '" style="position: absolute; margin-top: -15px; margin-left: 169px; width: 20px"><span style="font-size: 14px; width: 20px; padding: 2px 8px 2px 2px; margin-bottom: 0px" lang="jp">4x</div>\
  753. <div class="bsbmh4' + ((SBHeight == 5) ? ' on' : '') + '" style="position: absolute; margin-top: -15px; margin-left: 197px; width: 20px"><span style="font-size: 14px; width: 20px; padding: 2px 8px 2px 2px; margin-bottom: 0px" lang="jp">5x</div>\
  754. </div><span class="bsbmls" style="font-size: ' + ((!SBLangJP) ? "9" : "14") + 'px; width: 80px; padding: ' + ((!SBLangJP) ? "8" : "0") + 'px 5px 0px 7px" lang="jp">' + ((!SBLangJP) ? "Speed Multiplier" : "速度の乗数") + '</span>\
  755. <div class="bsbms" style="width: 0px; margin-top: -' + ((!SBLangJP) ? "16" : "20") + 'px; position: absolute">\
  756. <div class="bsbms0' + ((SBSpeed == 0.5) ? ' on' : '') + '" style="position: absolute; margin-left: 85px; width: 20px"><span style="font-size: 14px; width: 20px; padding: 2px 8px 2px 2px; margin-bottom: 0px" lang="jp">0.5x</div>\
  757. <div class="bsbms1' + ((SBSpeed == 1) ? ' on' : '') + '" style="position: absolute; margin-left: 113px; width: 20px"><span style="font-size: 14px; width: 20px; padding: 2px 8px 2px 2px; margin-bottom: 0px" lang="jp">1x</div>\
  758. <div class="bsbms2' + ((SBSpeed == 1.5) ? ' on' : '') + '" style="position: absolute; margin-left: 141px; width: 20px"><span style="font-size: 14px; width: 20px; padding: 2px 8px 2px 2px; margin-bottom: 0px" lang="jp">1.5x</div>\
  759. <div class="bsbms3' + ((SBSpeed == 2) ? ' on' : '') + '" style="position: absolute; margin-left: 169px; width: 20px"><span style="font-size: 14px; width: 20px; padding: 2px 8px 2px 2px; margin-bottom: 0px" lang="jp">2x</div>\
  760. <div class="bsbms4' + ((SBSpeed == 2.5) ? ' on' : '') + '" style="position: absolute; margin-left: 197px; width: 20px"><span style="font-size: 14px; width: 20px; padding: 2px 8px 2px 2px; margin-bottom: 0px" lang="jp">2.5x</div>\
  761. </div>');
  762. $(".bsbi div, .bsbs div, .bsbt div, .bsbm div div span, .sb-col-sel-tgl span").css({"font-size": "20px", "text-shadow": "none", "-webkit-touch-callout": "none", "-webkit-user-select": "none", "-khtml-user-select": "none",
  763. "-moz-user-select": "none", "-ms-user-select": "none", "user-select": "none"});
  764. $(".bsbi div, .bsbs div, .bsbm div div, .bsbt div").css({"background-repeat": "repeat-x", "color": "#fff", "padding": "5px 4px 0px 4px", "text-align": "center", "vertical-align": "middle"});
  765. $(".bsbi div, .bsbs div, .bsbt div").css({"width": "72px"}).mouseover(function() {
  766. $(this).css("text-shadow", "0 0 0.2em #fff");
  767. }).mouseout(function() {
  768. $(this).css("text-shadow", "none");
  769. });
  770. $(".bsbi div, .bsbs div").css({"height": "24px"});
  771. $('.bsbi div').css({"width": "48px"}).click(function() {
  772. var cancel = false;
  773. if ($(this).hasClass("on")) {
  774. if ((SBRadicalsEnabled && SBKanjiEnabled) || (SBRadicalsEnabled && SBVocabularyEnabled) || (SBKanjiEnabled && SBVocabularyEnabled)) {
  775. if ($(this).attr("class") == "bsbir on") {
  776. localStorage.setItem("SBRadicalsEnabled", false);
  777. SBRadicalsEnabled = false;
  778. $('a[href*="/radicals/"]').css("visibility", "hidden");
  779. } else if ($(this).attr("class") == "bsbik on") {
  780. localStorage.setItem("SBKanjiEnabled", false);
  781. SBKanjiEnabled = false;
  782. $('a[href*="/kanji/"]').css("visibility", "hidden");
  783. } else if ($(this).attr("class") == "bsbiv on") {
  784. localStorage.setItem("SBVocabularyEnabled", false);
  785. SBVocabularyEnabled = false;
  786. $('a[href*="/vocabulary/"]').css("visibility", "hidden");
  787. }
  788. } else cancel = true;
  789. } else {
  790. if ($(this).attr("class") == "bsbir") {
  791. localStorage.removeItem("SBRadicalsEnabled");
  792. SBRadicalsEnabled = true;
  793. $('a[href*="/radicals/"]').css("visibility", "inherit");
  794. } else if ($(this).attr("class") == "bsbik") {
  795. localStorage.removeItem("SBKanjiEnabled");
  796. SBKanjiEnabled = true;
  797. $('a[href*="/kanji/"]').css("visibility", "inherit");
  798. } else if ($(this).attr("class") == "bsbiv") {
  799. localStorage.removeItem("SBVocabularyEnabled");
  800. SBVocabularyEnabled = true;
  801. $('a[href*="/vocabulary/"]').css("visibility", "inherit");
  802. }
  803. }
  804. if (!cancel) $(this).toggleClass("on");
  805. });
  806. $('.bsbs div').css({"font-size": "20px", "width": "72px"}).click(function() {
  807. var cancel = false;
  808. if ($(this).hasClass("on")) {
  809. if ((SBApprenticeEnabled && SBGuruEnabled) || (SBApprenticeEnabled && SBMasterEnabled) || (SBApprenticeEnabled && SBEnlightenEnabled) ||
  810. (SBApprenticeEnabled && SBBurnedEnabled) || (SBApprenticeEnabled && SBLockedEnabled) || (SBGuruEnabled && SBMasterEnabled) ||
  811. (SBGuruEnabled && SBEnlightenEnabled) || (SBGuruEnabled && SBBurnedEnabled) || (SBGuruEnabled && SBLockedEnabled) ||
  812. (SBMasterEnabled && SBEnlightenEnabled) || (SBMasterEnabled && SBBurnedEnabled) || (SBMasterEnabled && SBLockedEnabled) ||
  813. (SBEnlightenEnabled && SBBurnedEnabled) || (SBEnlightenEnabled && SBBurnedEnabled) || (SBBurnedEnabled && SBLockedEnabled)) {
  814. if ($(this).attr("class") == "bsbsa on") {
  815. localStorage.setItem("SBApprenticeEnabled", false);
  816. SBApprenticeEnabled = false;
  817. $("a.Apprentice").css("visibility", "hidden");
  818. } else if ($(this).attr("class") == "bsbsg on") {
  819. localStorage.setItem("SBGuruEnabled", false);
  820. SBGuruEnabled = false;
  821. $("a.Guru").css("visibility", "hidden");
  822. } else if ($(this).attr("class") == "bsbsm on") {
  823. localStorage.setItem("SBMasterEnabled", false);
  824. SBMasterEnabled = false;
  825. $("a.Master").css("visibility", "hidden");
  826. } else if ($(this).attr("class") == "bsbse on") {
  827. localStorage.setItem("SBEnlightenEnabled", false);
  828. SBEnlightenEnabled = false;
  829. $("a.Enlightened").css("visibility", "hidden");
  830. } else if ($(this).attr("class") == "bsbsb on") {
  831. localStorage.setItem("SBBurnedEnabled", false);
  832. SBBurnedEnabled = false;
  833. $("a.Burned").css("visibility", "hidden");
  834. } else if ($(this).attr("class") == "bsbsl on") {
  835. localStorage.setItem("SBLockedEnabled", false);
  836. SBLockedEnabled = false;
  837. $("a.Locked").css("visibility", "hidden");
  838. }
  839. } else cancel = true;
  840. } else {
  841. if ($(this).attr("class") == "bsbsa") {
  842. localStorage.removeItem("SBApprenticeEnabled");
  843. SBApprenticeEnabled = true;
  844. $("a.Apprentice").css("visibility", "inherit");
  845. } else if ($(this).attr("class") == "bsbsg") {
  846. localStorage.removeItem("SBGuruEnabled");
  847. SBGuruEnabled = true;
  848. $("a.Guru").css("visibility", "inherit");
  849. } else if ($(this).attr("class") == "bsbsm") {
  850. localStorage.removeItem("SBMasterEnabled");
  851. SBMasterEnabled = true;
  852. $("a.Master").css("visibility", "inherit");
  853. } else if ($(this).attr("class") == "bsbse") {
  854. localStorage.removeItem("SBEnlightenEnabled");
  855. SBEnlightenEnabled = true;
  856. $("a.Enlightened").css("visibility", "inherit");
  857. } else if ($(this).attr("class") == "bsbsb") {
  858. localStorage.removeItem("SBBurnedEnabled");
  859. SBBurnedEnabled = true;
  860. $("a.Burned").css("visibility", "inherit");
  861. } else if ($(this).attr("class") == "bsbsl") {
  862. localStorage.removeItem("SBLockedEnabled");
  863. SBLockedEnabled = true;
  864. $("a.Locked").css("visibility", "inherit");
  865. }
  866. }
  867. if (!cancel) $(this).toggleClass("on");
  868. });
  869. $('.bsbm div div').css({"padding": "1px 4px 1px 4px"});
  870. $('.bsbm div div span').css({"font-size": "12px", "padding": "0px 0px 0px 0px"});
  871. $('.bsbm .bsbmh div').click(function() {
  872. $(".bsbm .bsbmh div").removeClass("on");
  873. $(this).addClass("on");
  874. SBHeight = parseInt($(this).children(".bsbm .bsbmh div span").html(), 10);
  875. SBResize();
  876. localStorage.setItem("SBHeight", SBHeight);
  877. });
  878. $('.bsbm .bsbms div').click(function() {
  879. $(".bsbm .bsbms div").removeClass("on");
  880. $(this).addClass("on");
  881. SBSpeed = parseFloat($(this).children(".bsbm .bsbms div span").html(), 2);
  882. clearInterval(newSBItemTimer);
  883. newSBItem();
  884. newSBItemTimer = setInterval(newSBItem, 1500 / SBSpeed);
  885. $('a[id*="SBI"]').each(function() {
  886. $(this).stop().animate({ "left": -$(this).width()*1.5}, {"duration": ($(this).attr("speed") * Math.pow((parseInt($(this).css("font-size"), 10) / 17), -1.1)) * 49000 / SBSpeed, "queue": false, "complete": function() {
  887. $(this).remove();
  888. }
  889. }, "linear" );
  890. });
  891. localStorage.setItem("SBSpeed", SBSpeed);
  892. });
  893. $('.bsbt div').css({"height": "24px"}).click(function() {
  894. $(this).toggleClass("on");
  895. if ($(this).children(".bsbt div span").html() == "日本語") {
  896. if (!SBLangJP) localStorage.setItem("SBLangJP", true);
  897. else localStorage.removeItem("SBLangJP");
  898. switchSBLang();
  899. } else if ($(this).children(".bsbt div span").html() == "Cache" || $(this).children(".bsbt div span").html() == "キャッシュ") {
  900. if (!SBUseCache) localStorage.setItem("SBUseCache", true);
  901. else localStorage.removeItem("SBUseCache");
  902. SBUseCache = !SBUseCache;
  903. } else {
  904. if (SBStart) localStorage.setItem("SBStart", false);
  905. else localStorage.removeItem("SBStart");
  906. SBStart = !SBStart;
  907. }
  908. });
  909. $('#sb-col-sel-tgl').css("display", "initial").click(function() {
  910. if ($('#sb-col-sel-tgl').css("right") == "-10px") {
  911. SBColIndex = (SBColTemp > -1) ? SBColTemp : 0;
  912. $('#sb-col-sel-tgl').css({"-webkit-transition": "1s ease-in-out",
  913. "-moz-transition": "1s ease-in-out",
  914. "-o-transition": "1s ease-in-out",
  915. "transition": "1s ease-in-out"}
  916. ).css("right", "-95px");
  917. $('#sb-col-sel').css({"-webkit-transition": "1s ease-in-out",
  918. "-moz-transition": "1s ease-in-out",
  919. "-o-transition": "1s ease-in-out",
  920. "transition": "1s ease-in-out"}
  921. ).css("right", "-85px");
  922. } else {
  923. $('a[cctemp]').removeAttr("cctemp");
  924. SBColIndex = -1;
  925. $("#sb-col-sel-tgl").css("right", "-10px");
  926. $("#sb-col-sel").css("right", "0px");
  927. }
  928. });
  929. for (var c = 0; c < 16; c++) {
  930. $("#sb-col-sel").append('<div class="sbcc' + c + '" style="width: 16px; height: 16px; left: ' + (9 + (20 * (c % 4))) + 'px; margin-top: ' + (7 + (20 * Math.floor(c / 4))) +
  931. 'px; position: absolute">' + ((c < 15) ? "" : '<span style="font-size: 16px; margin-left: 5px" lang="jp">?</span>') + '</div>');
  932. $(".sbcc" + c).click(function() {
  933. var index = parseInt($(this).attr("class").replace(/\D/g, ''));
  934. if (index !== SBColIndex || index == 15) {
  935. $('a[cctemp]').removeAttr("cctemp");
  936. SBColSelect(index);
  937. }
  938. });
  939. }
  940. $(".sbcc1 span").css("pointer-events", "none");
  941. /*document.getElementById("scroll-box-bg").onmousedown = function(e) {
  942. var scrollBoxBg = document.getElementById("scroll-box-bg");
  943. scrollBoxBg.setAttribute("potX", e.pageX - $("#scroll-box-bg").offset().left);
  944. scrollBoxBg.onmousemove = function(e) {
  945. $("#scroll-box-bg").attr("potX", (e.pageX - $("#scroll-box-bg").offset().left));
  946. };
  947. scrollBoxBg.onmouseup = function() {
  948. $('a[id^="SB"]').each(function() {
  949. //$(this).css("left", ($(this).css("left") + $("#scroll-box-bg").attr("potX")) + "px");
  950. $(this).animate({"left": ($(this).left + $("#scroll-box-bg").attr("potX"))}, {"queue": false, "duration": 1667}, "linear");
  951. });
  952. document.getElementById("scroll-box-bg").setAttribute("potX", document.getElementById("scroll-box-bg").getAttribute("potX") - ((document.getElementById("scroll-box-bg").getAttribute("potX") > 0) ? 1 : -1));
  953. };
  954. //alert($("#scroll-box-bg").attr("potX"));
  955. //$("#scroll-box-bg").removeAttr("potX");
  956. scrollBoxBg.mousemove = null;
  957. scrollBoxBg.mouseup = null;
  958. };*/
  959. //for (var l = 0; l < Object.keys(SBIndex.vocabulary.locked).length; l++) alert(SBIndex.vocabulary.locked[l]);
  960. newSBItemTimer = setInterval(newSBItem, 1500);
  961. }
  962.  
  963. function SBSelect(target, type) {
  964. $(".SBSelect").remove();
  965. if (target !== null) {
  966. var index = parseInt(target.attr("class").replace(/\D/g, ''));
  967. $('<div class="SBSelect">' + ((SBColIndex < 15 || target.hasClass("Locked")) ? "" : '<span lang="jp" style="color: black; font-size: ' + target.css("font-size") + '">?</span>') + '</div>').insertBefore($(target));
  968. $(".SBSelect").attr("style", $(target).attr("style")).css({"z-index": 100, "min-width": ($(target).width() - 4), "height": ($(target).height() - 4), "background": ((type === 0) ? "#0af" : ((type == 1) ? "#f0a" : "#a0f")),
  969. "border": "2px inset " + ((type === 0) ? "#0093dd" : ((type == 1) ? "#dd0093" : "#9300dd"))});
  970. if (SBColIndex > -1) {
  971. if (SBColIndex === 0) $(".SBSelect").css({"background": $(".sbcc0").css("background"), "border": $(".sbcc0").css("background"), "background-image": $(".sbcc0").css("background")});
  972. else if (SBColIndex > 0) $(".SBSelect").css({"background": $(".sbcc" + SBColIndex).css("background"), "border": $(".sbcc" + SBColIndex).css("background"), "background-image": $(".sbcc" + SBColIndex).css("background-image")});
  973. }
  974. }
  975. }
  976.  
  977. function SBColSelect(index) {
  978. $('div[class^="sbcc"]').each(function() {
  979. if ($(this).css("border-width") == "2px") {
  980. $(this).css({"border-width": "0px", "margin-top": (parseInt($(this).css("margin-top"), 10) + 2) + "px", "margin-left": (parseInt($(this).css("margin-left"), 10) + 2) + "px"});
  981. }
  982. });
  983. if (index > -1) {
  984. $('.sbcc' + index + ':not(a)').css({"border": "2px ridge white", "margin-top": (parseInt($('.sbcc' + index).css("margin-top"), 10) - 2) + "px", "margin-left": (parseInt($('.sbcc' + index).css("margin-left"), 10) - 2) + "px"});
  985. SBColIndex = index;
  986. SBColTemp = SBColIndex;
  987. }
  988. }
  989.  
  990. function rand(low, high) {
  991. return Math.floor(Math.random()*(high+1)) + low;
  992. }
  993.  
  994. function filterSBRadicalData(data) {
  995. var dataArr = {};
  996. for (var d = 1; d < data.length; d++) {
  997. dataArr[Object.keys(dataArr).length] = {"character": data[d].substring(0, 1), "meaning": data[d].substring(data[d].indexOf('"meaning":"') + 11, data[d].indexOf('","image"')).split(", "),
  998. "image": data[d].substring(data[d].indexOf('"image":"') + 10, data[d].indexOf('","level"')).split(", "),
  999. "srs": ((data[d].indexOf('"srs":') > -1) ? data[d].substring(data[d].indexOf('"srs":"') + 7, data[d].indexOf('","unl')) : null)
  1000. };
  1001. if (dataArr[Object.keys(dataArr).length - 1].srs !== null) {
  1002. SBIndex.radicals[dataArr[Object.keys(dataArr).length - 1].srs][SBIndexCount.radicals[dataArr[Object.keys(dataArr).length - 1].srs]] = d - 1;
  1003. SBIndexCount.radicals[dataArr[Object.keys(dataArr).length - 1].srs]++;
  1004. } else {
  1005. SBIndex.radicals.locked[SBIndexCount.radicals.locked] = d - 1;
  1006. SBIndexCount.radicals.locked++;
  1007. }
  1008. }
  1009. //alert(SBIndexCount.radicals);
  1010. return dataArr;
  1011. }
  1012.  
  1013. function filterSBKanjiData(data) {
  1014. var dataArr = {};
  1015. for (var d = 1; d < data.length; d++) {
  1016. dataArr[Object.keys(dataArr).length] = {"character": data[d].substring(0, 1), "meaning": data[d].substring(data[d].indexOf('"meaning":"') + 11, data[d].indexOf('","onyomi"')).split(", "),
  1017. "onyomi": data[d].substring(data[d].indexOf('"onyomi":"') + 10, data[d].indexOf('","kunyomi"')).split(", "), "kunyomi": data[d].substring(data[d].indexOf('"kunyomi":"') + 11,
  1018. data[d].indexOf('","important')).split(", "), "important_reading": data[d].substring(data[d].indexOf('"important_reading":"') + 21, data[d].indexOf('","level"')),
  1019. "srs": ((data[d].indexOf('"srs":') > -1) ? data[d].substring(data[d].indexOf('"srs":"') + 7, data[d].indexOf('","unl')) : null)
  1020. };
  1021. if (dataArr[Object.keys(dataArr).length - 1].srs !== null) {
  1022. SBIndex.kanji[dataArr[Object.keys(dataArr).length - 1].srs][SBIndexCount.kanji[dataArr[Object.keys(dataArr).length - 1].srs]] = d - 1;
  1023. SBIndexCount.kanji[dataArr[Object.keys(dataArr).length - 1].srs]++;
  1024. } else {
  1025. SBIndex.kanji.locked[SBIndexCount.kanji.locked] = d - 1;
  1026. SBIndexCount.kanji.locked++;
  1027. }
  1028. }
  1029. return dataArr;
  1030. }
  1031.  
  1032. function filterSBVocabData(data) {
  1033. var dataArr = {};
  1034. for (var p = 0; p < Object.keys(data).length; p++) {
  1035. for (var d = 1; d < Object.keys(data[p]).length; d++) {
  1036. dataArr[Object.keys(dataArr).length] = {"character": data[p][d].substring(0, data[p][d].indexOf('"')), "kana": data[p][d].substring(data[p][d].indexOf('"kana":"') + 8, data[p][d].indexOf('","meaning"')).split(", "),
  1037. "meaning": (data[p][d].substring(data[p][d].indexOf('"meaning":"') + 11, data[p][d].indexOf('","level"'))).split(", "),
  1038. "srs": ((data[p][d].indexOf('"srs":') > -1) ? data[p][d].substring(data[p][d].indexOf('"srs":"') + 7, data[p][d].indexOf('","unl')) : null)
  1039. };
  1040. if (dataArr[Object.keys(dataArr).length - 1].srs !== null) {
  1041. SBIndex.vocabulary[dataArr[Object.keys(dataArr).length - 1].srs][SBIndexCount.vocabulary[dataArr[Object.keys(dataArr).length - 1].srs]] = Object.keys(dataArr).length - 1;
  1042. SBIndexCount.vocabulary[dataArr[Object.keys(dataArr).length - 1].srs]++;
  1043. } else {
  1044. SBIndex.vocabulary.locked[SBIndexCount.vocabulary.locked] = Object.keys(dataArr).length - 1;
  1045. SBIndexCount.vocabulary.locked++;
  1046. }
  1047. }
  1048. }
  1049. return dataArr;
  1050. }
  1051.  
  1052. cancelExecution = false;
  1053.  
  1054. if (localStorage.getItem("apiKey") !== null && localStorage.getItem("apiKey").length == 32) apiKey = localStorage.getItem("apiKey");
  1055. else if (apiKey.length == 32) localStorage.setItem("apiKey", apiKey);
  1056. else {
  1057. cancelExecution = true;
  1058. alert("Please enter your API key near the top of the WanaKani Scroll Box userscript.");
  1059. }
  1060.  
  1061. newSBItemTimer = 0;
  1062.  
  1063. if (!cancelExecution) {
  1064. SBLangJP = (localStorage.getItem("SBLangJP") == null) ? false : true;
  1065. SBUseCache = (localStorage.getItem("SBUseCache") == null) ? false : true;
  1066. SBStart = (localStorage.getItem("SBStart") == null) ? true : false;
  1067. if (localStorage.getItem("SBHeight") == null) localStorage.setItem("SBHeight", 2);
  1068. SBHeight = localStorage.getItem("SBHeight");
  1069. if (localStorage.getItem("SBSpeed") == null) localStorage.setItem("SBSpeed", 2);
  1070. SBSpeed = localStorage.getItem("SBSpeed");
  1071. SBICount = 0;
  1072. SBColIndex = -1;
  1073. SBColTemp = -1;
  1074. SBPause = false;
  1075. SBRadicalsEnabled = (localStorage.getItem("SBRadicalsEnabled") !== null) ? false : true;
  1076. SBKanjiEnabled = (localStorage.getItem("SBKanjiEnabled") !== null) ? false : true;
  1077. SBVocabularyEnabled = (localStorage.getItem("SBVocabularyEnabled") !== null) ? false : true;
  1078. SBApprenticeEnabled = (localStorage.getItem("SBApprenticeEnabled") !== null) ? false : true;
  1079. SBGuruEnabled = (localStorage.getItem("SBGuruEnabled") !== null) ? false : true;
  1080. SBMasterEnabled = (localStorage.getItem("SBMasterEnabled") !== null) ? false : true;
  1081. SBEnlightenEnabled = (localStorage.getItem("SBEnlightenEnabled") !== null) ? false : true;
  1082. SBBurnedEnabled = (localStorage.getItem("SBBurnedEnabled") !== null) ? false : true;
  1083. SBLockedEnabled = (localStorage.getItem("SBLockedEnabled") !== null) ? false : true;
  1084. SBRadicalData = {};
  1085. SBKanjiData = {};
  1086. SBVocabData = {};
  1087. SBLevels = "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";
  1088. SBIndex = (localStorage.getItem("SBIndex") !== null) ? JSON.parse(localStorage.getItem("SBIndex")) : {
  1089. "radicals": {
  1090. "apprentice": [], "guru": [], "master": [], "enlighten": [], "burned": [], "locked": []
  1091. }, "kanji": {
  1092. "apprentice": [], "guru": [], "master": [], "enlighten": [], "burned": [], "locked": []
  1093. }, "vocabulary": {
  1094. "apprentice": [], "guru": [], "master": [], "enlighten": [], "burned": [], "locked": []
  1095. }
  1096. };
  1097. SBIndexCount = (localStorage.getItem("SBIndexCount") !== null) ? JSON.parse(localStorage.getItem("SBIndexCount")) : {
  1098. "radicals": {
  1099. "apprentice": 0, "guru": 0, "master": 0, "enlighten": 0, "burned": 0, "locked": 0
  1100. }, "kanji": {
  1101. "apprentice": 0, "guru": 0, "master": 0, "enlighten": 0, "burned": 0, "locked": 0
  1102. }, "vocabulary": {
  1103. "apprentice": 0, "guru": 0, "master": 0, "enlighten": 0, "burned": 0, "locked": 0
  1104. }
  1105. };
  1106. SBIndexBG = (localStorage.getItem("SBIndexBG") !== null) ? JSON.parse(localStorage.getItem("SBIndexBG")) : { "radicals": [], "kanji": [], "vocabulary": [] };
  1107. if (SBPageTop) $(getSBSection()).insertBefore($(".review-status ul"));
  1108. else $(getSBSection()).insertAfter($(".span12 .row:first"));
  1109. if (!SBLangJP) $("#loadingSB").html('<a lang="ja" href="javascript:void(0)" style="font-size: 52px; color: #434343; text-decoration: none">Start</a>');
  1110. else $("#loadingSB").html('<a lang="ja" href="javascript:void(0)" style="font-size: 52px; color: #434343; text-decoration: none">開始</a>');
  1111. $("#loadingSB a").click( function() {
  1112. if (!SBUseCache) clearSBItemData();
  1113. getSBWKData();
  1114. });
  1115. if (!SBStart) $("#loadingSB a").click();
  1116. }
  1117. // ==/UserScript==