Wanikani Scrollbox

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

当前为 2014-12-27 提交的版本,查看 最新版本

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