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.2
  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("<style type=text/css>\
  599. .bsbi div, .bsbs div, .bsbt div, .bsbm div div {\
  600. background-color: rgb(49, 49, 49);\
  601. background-image: linear-gradient(to bottom, rgb(67, 67, 67), rgb(49, 49, 49));\
  602. color: #E3E3E3\
  603. -moz-box-shadow: inset 2px 2px 2px rgba(255, 255, 255, .2), inset -2px -2px 2px rgba(0, 0, 0, .2);\
  604. -webkit-box-shadow: inset 2px 2px 2px rgba(255, 255, 255, .2), inset -2px -2px 2px rgba(0, 0, 0, .2);\
  605. box-shadow: inset 2px 2px 2px rgba(255, 255, 255, .2), inset -2px -2px 2px rgba(0, 0, 0, .2);\
  606. }\
  607. .bsbir.on {\
  608. background-color: #00a0f1; background-image: linear-gradient(to bottom, #0af, #0093dd);\
  609. }\
  610. .bsbik.on {\
  611. background-color: #f100a0; background-image: linear-gradient(to bottom, #f0a, #dd0093);\
  612. }\
  613. .bsbiv.on {\
  614. background-color: #a000f1; background-image: linear-gradient(to bottom, #a0f, #9300dd);\
  615. }\
  616. .bsbt .on, .bsbm div .on {\
  617. background-color: #80c100; background-image: linear-gradient(to bottom, #8c0, #73ad00);\
  618. }\
  619. .Apprentice, .bsbsa.on {\
  620. background: #f100a0;\
  621. border-color: #f100a0;\
  622. background-image: linear-gradient(to bottom, #f0a, #dd0093);\
  623. }\
  624. .Guru, .bsbsg.on {\
  625. background: #882d9e;\
  626. border-color: #882d9e;\
  627. background-image: linear-gradient(to bottom, #aa38c6, #882d9e);\
  628. }\
  629. .Master, .bsbsm.on {\
  630. background: #294ddb;\
  631. border-color: #294ddb;\
  632. background-image: linear-gradient(to bottom, #5571e2, #294ddb);\
  633. }\
  634. .Enlightened, .bsbse.on {\
  635. background: #0093dd;\
  636. border-color: #0093dd;\
  637. background-image: linear-gradient(to bottom, #0af, #0093dd);\
  638. }\
  639. .Burned, .bsbsb.on {\
  640. background: #434343;\
  641. border-color: #434343;\
  642. background-image: linear-gradient(to bottom, #555, #434343);\
  643. }\
  644. .Locked, .bsbsl.on {\
  645. background: #868686;\
  646. border-color: #313131;\
  647. background-image: linear-gradient(to bottom, #bbb, #a3a3a3);\
  648. }\
  649. .on {\
  650. color: #FFF\
  651. }\
  652. .SBSelect {\
  653. opacity: 0.5;\
  654. pointer-events: none;\
  655. }\
  656. .sbcc0 {\
  657. background: #434343;\
  658. background-image: linear-gradient(90deg, #f100a0, #882d9e, #0093dd, #434343, #868686);\
  659. }\
  660. .sbcc1 {\
  661. background: #fff;\
  662. background-image: linear-gradient(to bottom, #fff, #e3e3e3);\
  663. }\
  664. .sbcc2 {\
  665. background: #131313;\
  666. background-image: linear-gradient(to bottom, #131313, #000);\
  667. }\
  668. .sbcc3 {\
  669. background: #ff1313;\
  670. background-image: linear-gradient(to bottom, #ff1313, #e30000);\
  671. }\
  672. .sbcc4 {\
  673. background: #f0a;\
  674. background-image: linear-gradient(to bottom, #fa0, #dd9300);\
  675. }\
  676. .sbcc5 {\
  677. background: #fe0;\
  678. background-image: linear-gradient(to bottom, #fe0, #e3d300);\
  679. }\
  680. .sbcc6 {\
  681. background: #28a0228;\
  682. background-image: linear-gradient(to bottom, #28a028, #1a931a);\
  683. }\
  684. .sbcc7 {\
  685. background: #58e058;\
  686. background-image: linear-gradient(to bottom, #58e058, #48d348);\
  687. }\
  688. .sbcc8 {\
  689. background: #00f0fa;\
  690. background-image: linear-gradient(to bottom, #00f0fa, #00e3f0);\
  691. }\
  692. .sbcc9 {\
  693. background: #1313a0;\
  694. background-image: linear-gradient(to bottom, #1378a0, #006093);\
  695. }\
  696. .sbcc10 {\
  697. background: #1313a0;\
  698. background-image: linear-gradient(to bottom, #1313a0, #000093);\
  699. }\
  700. .sbcc11 {\
  701. background: #a858e0;\
  702. background-image: linear-gradient(to bottom, #a858e0, #9a4ad3);\
  703. }\
  704. .sbcc12 {\
  705. background: #ecbcf3;\
  706. background-image: linear-gradient(to bottom, #ecbcf3, #e0b0d6);\
  707. }\
  708. .sbcc13 {\
  709. background: #ec13a3;\
  710. background-image: linear-gradient(to bottom, #ec13a3, ##e00a90);\
  711. }\
  712. .sbcc14 {\
  713. background: #8c735a;\
  714. background-image: linear-gradient(to bottom, #8c735a, #806650);\
  715. }\
  716. .sbcc15 {\
  717. background: #fff;\
  718. background-image: linear-gradient(to bottom, #fff, #e3e3e3);\
  719. }\
  720. </style>");
  721. $("#scroll-box-buttons").append('<div class="bsbi" style="width: 0px; height: 0px; position: absolute; z-index: 11">\
  722. <div class="bsbir' + ((SBRadicalsEnabled) ? ' on' : '') + '" style="position: absolute"><span lang="ja" style="font-size: inherit">部首</span></div>\
  723. <div class="bsbik' + ((SBKanjiEnabled) ? ' on' : '') + '" style="margin-left: 56px; position: absolute"><span lang="ja" style="font-size: inherit;">漢字</span></div>\
  724. <div class="bsbiv' + ((SBVocabularyEnabled) ? ' on' : '') + '" style="margin-left: 112px; position: absolute"><span lang="ja" style="font-size: inherit">単語</span></div>\
  725. </div>\
  726. <div class="bsbs" style="width: 0px; height: 0px; position: absolute; z-index: 11">\
  727. <div class="bsbsa' + ((SBApprenticeEnabled) ? ' on' : '') + '" style="margin-left: 168px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Appr" : "見習い") + '</span></div>\
  728. <div class="bsbsg' + ((SBGuruEnabled) ? ' on' : '') + '" style="margin-left: 248px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Guru" : "尊師") + '</span></div>\
  729. <div class="bsbsm' + ((SBMasterEnabled) ? ' on' : '') + '" style="margin-left: 328px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Master" : "達人") + '</span></div>\
  730. <div class="bsbse' + ((SBEnlightenEnabled) ? ' on' : '') + '" style="margin-left: 408px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Enlight" : "啓発") + '</span></div>\
  731. <div class="bsbsb' + ((SBBurnedEnabled) ? ' on' : '') + '" style="margin-left: 488px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Burned" : "焦げ") + '</span></div>\
  732. <div class="bsbsl' + ((SBLockedEnabled) ? ' on' : '') + '" style="margin-left: 568px; position: absolute"><span lang="ja" style="font-size: inherit">' + ((!SBLangJP) ? "Locked" : "ロック") + '</span></div></div>\
  733. <div class="bsbt" style="width: 0px; position: absolute; z-index: 11; margin-left: 648px">\
  734. <div class="bsbtj' + ((SBLangJP) ? ' on' : '') + '" style="position: absolute"><span lang="ja" style="font-size: inherit">日本語</span></div>\
  735. <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>\
  736. <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>\
  737. </div>\
  738. <div class="bsbm" style="width: 0px; margin-left: 888px; position: absolute; z-index: 11">\
  739. <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>\
  740. <div class="bsbmh" style="width: 0px; position: absolute' + ((!SBLangJP) ? "; margin-top: 5px" : "" ) + '">\
  741. <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>\
  742. <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>\
  743. <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>\
  744. <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>\
  745. <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>\
  746. </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>\
  747. <div class="bsbms" style="width: 0px; margin-top: -' + ((!SBLangJP) ? "16" : "20") + 'px; position: absolute">\
  748. <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>\
  749. <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>\
  750. <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>\
  751. <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>\
  752. <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>\
  753. </div>');
  754. $(".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",
  755. "-moz-user-select": "none", "-ms-user-select": "none", "user-select": "none"});
  756. $(".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"});
  757. $(".bsbi div, .bsbs div, .bsbt div").css({"width": "72px"}).mouseover(function() {
  758. $(this).css("text-shadow", "0 0 0.2em #fff");
  759. }).mouseout(function() {
  760. $(this).css("text-shadow", "none");
  761. });
  762. $(".bsbi div, .bsbs div").css({"height": "24px"});
  763. $('.bsbi div').css({"width": "48px"}).click(function() {
  764. var cancel = false;
  765. if ($(this).hasClass("on")) {
  766. if ((SBRadicalsEnabled && SBKanjiEnabled) || (SBRadicalsEnabled && SBVocabularyEnabled) || (SBKanjiEnabled && SBVocabularyEnabled)) {
  767. if ($(this).attr("class") == "bsbir on") {
  768. localStorage.setItem("SBRadicalsEnabled", false);
  769. SBRadicalsEnabled = false;
  770. $('a[href*="/radicals/"]').css("visibility", "hidden");
  771. } else if ($(this).attr("class") == "bsbik on") {
  772. localStorage.setItem("SBKanjiEnabled", false);
  773. SBKanjiEnabled = false;
  774. $('a[href*="/kanji/"]').css("visibility", "hidden");
  775. } else if ($(this).attr("class") == "bsbiv on") {
  776. localStorage.setItem("SBVocabularyEnabled", false);
  777. SBVocabularyEnabled = false;
  778. $('a[href*="/vocabulary/"]').css("visibility", "hidden");
  779. }
  780. } else cancel = true;
  781. } else {
  782. if ($(this).attr("class") == "bsbir") {
  783. localStorage.removeItem("SBRadicalsEnabled");
  784. SBRadicalsEnabled = true;
  785. $('a[href*="/radicals/"]').css("visibility", "inherit");
  786. } else if ($(this).attr("class") == "bsbik") {
  787. localStorage.removeItem("SBKanjiEnabled");
  788. SBKanjiEnabled = true;
  789. $('a[href*="/kanji/"]').css("visibility", "inherit");
  790. } else if ($(this).attr("class") == "bsbiv") {
  791. localStorage.removeItem("SBVocabularyEnabled");
  792. SBVocabularyEnabled = true;
  793. $('a[href*="/vocabulary/"]').css("visibility", "inherit");
  794. }
  795. }
  796. if (!cancel) $(this).toggleClass("on");
  797. });
  798. $('.bsbs div').css({"font-size": "20px", "width": "72px"}).click(function() {
  799. var cancel = false;
  800. if ($(this).hasClass("on")) {
  801. if ((SBApprenticeEnabled && SBGuruEnabled) || (SBApprenticeEnabled && SBMasterEnabled) || (SBApprenticeEnabled && SBEnlightenEnabled) ||
  802. (SBApprenticeEnabled && SBBurnedEnabled) || (SBApprenticeEnabled && SBLockedEnabled) || (SBGuruEnabled && SBMasterEnabled) ||
  803. (SBGuruEnabled && SBEnlightenEnabled) || (SBGuruEnabled && SBBurnedEnabled) || (SBGuruEnabled && SBLockedEnabled) ||
  804. (SBMasterEnabled && SBEnlightenEnabled) || (SBMasterEnabled && SBBurnedEnabled) || (SBMasterEnabled && SBLockedEnabled) ||
  805. (SBEnlightenEnabled && SBBurnedEnabled) || (SBEnlightenEnabled && SBBurnedEnabled) || (SBBurnedEnabled && SBLockedEnabled)) {
  806. if ($(this).attr("class") == "bsbsa on") {
  807. localStorage.setItem("SBApprenticeEnabled", false);
  808. SBApprenticeEnabled = false;
  809. $("a.Apprentice").css("visibility", "hidden");
  810. } else if ($(this).attr("class") == "bsbsg on") {
  811. localStorage.setItem("SBGuruEnabled", false);
  812. SBGuruEnabled = false;
  813. $("a.Guru").css("visibility", "hidden");
  814. } else if ($(this).attr("class") == "bsbsm on") {
  815. localStorage.setItem("SBMasterEnabled", false);
  816. SBMasterEnabled = false;
  817. $("a.Master").css("visibility", "hidden");
  818. } else if ($(this).attr("class") == "bsbse on") {
  819. localStorage.setItem("SBEnlightenEnabled", false);
  820. SBEnlightenEnabled = false;
  821. $("a.Enlightened").css("visibility", "hidden");
  822. } else if ($(this).attr("class") == "bsbsb on") {
  823. localStorage.setItem("SBBurnedEnabled", false);
  824. SBBurnedEnabled = false;
  825. $("a.Burned").css("visibility", "hidden");
  826. } else if ($(this).attr("class") == "bsbsl on") {
  827. localStorage.setItem("SBLockedEnabled", false);
  828. SBLockedEnabled = false;
  829. $("a.Locked").css("visibility", "hidden");
  830. }
  831. } else cancel = true;
  832. } else {
  833. if ($(this).attr("class") == "bsbsa") {
  834. localStorage.removeItem("SBApprenticeEnabled");
  835. SBApprenticeEnabled = true;
  836. $("a.Apprentice").css("visibility", "inherit");
  837. } else if ($(this).attr("class") == "bsbsg") {
  838. localStorage.removeItem("SBGuruEnabled");
  839. SBGuruEnabled = true;
  840. $("a.Guru").css("visibility", "inherit");
  841. } else if ($(this).attr("class") == "bsbsm") {
  842. localStorage.removeItem("SBMasterEnabled");
  843. SBMasterEnabled = true;
  844. $("a.Master").css("visibility", "inherit");
  845. } else if ($(this).attr("class") == "bsbse") {
  846. localStorage.removeItem("SBEnlightenEnabled");
  847. SBEnlightenEnabled = true;
  848. $("a.Enlightened").css("visibility", "inherit");
  849. } else if ($(this).attr("class") == "bsbsb") {
  850. localStorage.removeItem("SBBurnedEnabled");
  851. SBBurnedEnabled = true;
  852. $("a.Burned").css("visibility", "inherit");
  853. } else if ($(this).attr("class") == "bsbsl") {
  854. localStorage.removeItem("SBLockedEnabled");
  855. SBLockedEnabled = true;
  856. $("a.Locked").css("visibility", "inherit");
  857. }
  858. }
  859. if (!cancel) $(this).toggleClass("on");
  860. });
  861. $('.bsbm div div').css({"padding": "1px 4px 1px 4px"});
  862. $('.bsbm div div span').css({"font-size": "12px", "padding": "0px 0px 0px 0px"});
  863. $('.bsbm .bsbmh div').click(function() {
  864. $(".bsbm .bsbmh div").removeClass("on");
  865. $(this).addClass("on");
  866. SBHeight = parseInt($(this).children(".bsbm .bsbmh div span").html(), 10);
  867. SBResize();
  868. localStorage.setItem("SBHeight", SBHeight);
  869. });
  870. $('.bsbm .bsbms div').click(function() {
  871. $(".bsbm .bsbms div").removeClass("on");
  872. $(this).addClass("on");
  873. SBSpeed = parseFloat($(this).children(".bsbm .bsbms div span").html(), 2);
  874. clearInterval(newSBItemTimer);
  875. newSBItem();
  876. newSBItemTimer = setInterval(newSBItem, 1500 / SBSpeed);
  877. $('a[id*="SBI"]').each(function() {
  878. $(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() {
  879. $(this).remove();
  880. }
  881. }, "linear" );
  882. });
  883. localStorage.setItem("SBSpeed", SBSpeed);
  884. });
  885. $('.bsbt div').css({"height": "24px"}).click(function() {
  886. $(this).toggleClass("on");
  887. if ($(this).children(".bsbt div span").html() == "日本語") {
  888. if (!SBLangJP) localStorage.setItem("SBLangJP", true);
  889. else localStorage.removeItem("SBLangJP");
  890. switchSBLang();
  891. } else if ($(this).children(".bsbt div span").html() == "Cache" || $(this).children(".bsbt div span").html() == "キャッシュ") {
  892. if (!SBUseCache) localStorage.setItem("SBUseCache", true);
  893. else localStorage.removeItem("SBUseCache");
  894. SBUseCache = !SBUseCache;
  895. } else {
  896. if (SBStart) localStorage.setItem("SBStart", false);
  897. else localStorage.removeItem("SBStart");
  898. SBStart = !SBStart;
  899. }
  900. });
  901. $('#sb-col-sel-tgl').css("display", "initial").click(function() {
  902. if ($('#sb-col-sel-tgl').css("right") == "-10px") {
  903. SBColIndex = (SBColTemp > -1) ? SBColTemp : 0;
  904. $('#sb-col-sel-tgl').css({"-webkit-transition": "1s ease-in-out",
  905. "-moz-transition": "1s ease-in-out",
  906. "-o-transition": "1s ease-in-out",
  907. "transition": "1s ease-in-out"}
  908. ).css("right", "-95px");
  909. $('#sb-col-sel').css({"-webkit-transition": "1s ease-in-out",
  910. "-moz-transition": "1s ease-in-out",
  911. "-o-transition": "1s ease-in-out",
  912. "transition": "1s ease-in-out"}
  913. ).css("right", "-85px");
  914. } else {
  915. $('a[cctemp]').removeAttr("cctemp");
  916. SBColIndex = -1;
  917. $("#sb-col-sel-tgl").css("right", "-10px");
  918. $("#sb-col-sel").css("right", "0px");
  919. }
  920. });
  921. for (var c = 0; c < 16; c++) {
  922. $("#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))) +
  923. 'px; position: absolute">' + ((c < 15) ? "" : '<span style="font-size: 16px; margin-left: 5px" lang="jp">?</span>') + '</div>');
  924. $(".sbcc" + c).click(function() {
  925. var index = parseInt($(this).attr("class").replace(/\D/g, ''));
  926. if (index !== SBColIndex || index == 15) {
  927. $('a[cctemp]').removeAttr("cctemp");
  928. SBColSelect(index);
  929. }
  930. });
  931. }
  932. $(".sbcc1 span").css("pointer-events", "none");
  933. /*document.getElementById("scroll-box-bg").onmousedown = function(e) {
  934. var scrollBoxBg = document.getElementById("scroll-box-bg");
  935. scrollBoxBg.setAttribute("potX", e.pageX - $("#scroll-box-bg").offset().left);
  936. scrollBoxBg.onmousemove = function(e) {
  937. $("#scroll-box-bg").attr("potX", (e.pageX - $("#scroll-box-bg").offset().left));
  938. };
  939. scrollBoxBg.onmouseup = function() {
  940. $('a[id^="SB"]').each(function() {
  941. //$(this).css("left", ($(this).css("left") + $("#scroll-box-bg").attr("potX")) + "px");
  942. $(this).animate({"left": ($(this).left + $("#scroll-box-bg").attr("potX"))}, {"queue": false, "duration": 1667}, "linear");
  943. });
  944. document.getElementById("scroll-box-bg").setAttribute("potX", document.getElementById("scroll-box-bg").getAttribute("potX") - ((document.getElementById("scroll-box-bg").getAttribute("potX") > 0) ? 1 : -1));
  945. };
  946. //alert($("#scroll-box-bg").attr("potX"));
  947. //$("#scroll-box-bg").removeAttr("potX");
  948. scrollBoxBg.mousemove = null;
  949. scrollBoxBg.mouseup = null;
  950. };*/
  951. //for (var l = 0; l < Object.keys(SBIndex.vocabulary.locked).length; l++) alert(SBIndex.vocabulary.locked[l]);
  952. newSBItemTimer = setInterval(newSBItem, 1500);
  953. }
  954.  
  955. function SBSelect(target, type) {
  956. $(".SBSelect").remove();
  957. if (target !== null) {
  958. var index = parseInt(target.attr("class").replace(/\D/g, ''));
  959. $('<div class="SBSelect">' + ((SBColIndex < 15 || target.hasClass("Locked")) ? "" : '<span lang="jp" style="color: black; font-size: ' + target.css("font-size") + '">?</span>') + '</div>').insertBefore($(target));
  960. $(".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")),
  961. "border": "2px inset " + ((type === 0) ? "#0093dd" : ((type == 1) ? "#dd0093" : "#9300dd"))});
  962. if (SBColIndex > -1) {
  963. if (SBColIndex === 0) $(".SBSelect").css({"background": $(".sbcc0").css("background"), "border": $(".sbcc0").css("background"), "background-image": $(".sbcc0").css("background")});
  964. else if (SBColIndex > 0) $(".SBSelect").css({"background": $(".sbcc" + SBColIndex).css("background"), "border": $(".sbcc" + SBColIndex).css("background"), "background-image": $(".sbcc" + SBColIndex).css("background-image")});
  965. }
  966. }
  967. }
  968.  
  969. function SBColSelect(index) {
  970. $('div[class^="sbcc"]').each(function() {
  971. if ($(this).css("border-width") == "2px") {
  972. $(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"});
  973. }
  974. });
  975. if (index > -1) {
  976. $('.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"});
  977. SBColIndex = index;
  978. SBColTemp = SBColIndex;
  979. }
  980. }
  981.  
  982. function rand(low, high) {
  983. return Math.floor(Math.random()*(high+1)) + low;
  984. }
  985.  
  986. function filterSBRadicalData(data) {
  987. var dataArr = {};
  988. for (var d = 1; d < data.length; d++) {
  989. 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(", "),
  990. "image": data[d].substring(data[d].indexOf('"image":"') + 10, data[d].indexOf('","level"')).split(", "),
  991. "srs": ((data[d].indexOf('"srs":') > -1) ? data[d].substring(data[d].indexOf('"srs":"') + 7, data[d].indexOf('","unl')) : null)
  992. };
  993. if (dataArr[Object.keys(dataArr).length - 1].srs !== null) {
  994. SBIndex.radicals[dataArr[Object.keys(dataArr).length - 1].srs][SBIndexCount.radicals[dataArr[Object.keys(dataArr).length - 1].srs]] = d - 1;
  995. SBIndexCount.radicals[dataArr[Object.keys(dataArr).length - 1].srs]++;
  996. } else {
  997. SBIndex.radicals.locked[SBIndexCount.radicals.locked] = d - 1;
  998. SBIndexCount.radicals.locked++;
  999. }
  1000. }
  1001. //alert(SBIndexCount.radicals);
  1002. return dataArr;
  1003. }
  1004.  
  1005. function filterSBKanjiData(data) {
  1006. var dataArr = {};
  1007. for (var d = 1; d < data.length; d++) {
  1008. 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(", "),
  1009. "onyomi": data[d].substring(data[d].indexOf('"onyomi":"') + 10, data[d].indexOf('","kunyomi"')).split(", "), "kunyomi": data[d].substring(data[d].indexOf('"kunyomi":"') + 11,
  1010. data[d].indexOf('","important')).split(", "), "important_reading": data[d].substring(data[d].indexOf('"important_reading":"') + 21, data[d].indexOf('","level"')),
  1011. "srs": ((data[d].indexOf('"srs":') > -1) ? data[d].substring(data[d].indexOf('"srs":"') + 7, data[d].indexOf('","unl')) : null)
  1012. };
  1013. if (dataArr[Object.keys(dataArr).length - 1].srs !== null) {
  1014. SBIndex.kanji[dataArr[Object.keys(dataArr).length - 1].srs][SBIndexCount.kanji[dataArr[Object.keys(dataArr).length - 1].srs]] = d - 1;
  1015. SBIndexCount.kanji[dataArr[Object.keys(dataArr).length - 1].srs]++;
  1016. } else {
  1017. SBIndex.kanji.locked[SBIndexCount.kanji.locked] = d - 1;
  1018. SBIndexCount.kanji.locked++;
  1019. }
  1020. }
  1021. return dataArr;
  1022. }
  1023.  
  1024. function filterSBVocabData(data) {
  1025. var dataArr = {};
  1026. for (var p = 0; p < Object.keys(data).length; p++) {
  1027. for (var d = 1; d < Object.keys(data[p]).length; d++) {
  1028. 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(", "),
  1029. "meaning": (data[p][d].substring(data[p][d].indexOf('"meaning":"') + 11, data[p][d].indexOf('","level"'))).split(", "),
  1030. "srs": ((data[p][d].indexOf('"srs":') > -1) ? data[p][d].substring(data[p][d].indexOf('"srs":"') + 7, data[p][d].indexOf('","unl')) : null)
  1031. };
  1032. if (dataArr[Object.keys(dataArr).length - 1].srs !== null) {
  1033. SBIndex.vocabulary[dataArr[Object.keys(dataArr).length - 1].srs][SBIndexCount.vocabulary[dataArr[Object.keys(dataArr).length - 1].srs]] = Object.keys(dataArr).length - 1;
  1034. SBIndexCount.vocabulary[dataArr[Object.keys(dataArr).length - 1].srs]++;
  1035. } else {
  1036. SBIndex.vocabulary.locked[SBIndexCount.vocabulary.locked] = Object.keys(dataArr).length - 1;
  1037. SBIndexCount.vocabulary.locked++;
  1038. }
  1039. }
  1040. }
  1041. return dataArr;
  1042. }
  1043.  
  1044. cancelExecution = false;
  1045.  
  1046. if (localStorage.getItem("apiKey") !== null && localStorage.getItem("apiKey").length == 32) apiKey = localStorage.getItem("apiKey");
  1047. else if (apiKey.length == 32) localStorage.setItem("apiKey", apiKey);
  1048. else {
  1049. cancelExecution = true;
  1050. alert("Please enter your API key near the top of the WanaKani Scroll Box userscript.");
  1051. }
  1052.  
  1053. newSBItemTimer = 0;
  1054.  
  1055. if (!cancelExecution) {
  1056. SBLangJP = (localStorage.getItem("SBLangJP") == null) ? false : true;
  1057. SBUseCache = (localStorage.getItem("SBUseCache") == null) ? false : true;
  1058. SBStart = (localStorage.getItem("SBStart") == null) ? true : false;
  1059. if (localStorage.getItem("SBHeight") == null) localStorage.setItem("SBHeight", 2);
  1060. SBHeight = localStorage.getItem("SBHeight");
  1061. if (localStorage.getItem("SBSpeed") == null) localStorage.setItem("SBSpeed", 2);
  1062. SBSpeed = localStorage.getItem("SBSpeed");
  1063. SBICount = 0;
  1064. SBColIndex = -1;
  1065. SBColTemp = -1;
  1066. SBPause = false;
  1067. SBRadicalsEnabled = (localStorage.getItem("SBRadicalsEnabled") !== null) ? false : true;
  1068. SBKanjiEnabled = (localStorage.getItem("SBKanjiEnabled") !== null) ? false : true;
  1069. SBVocabularyEnabled = (localStorage.getItem("SBVocabularyEnabled") !== null) ? false : true;
  1070. SBApprenticeEnabled = (localStorage.getItem("SBApprenticeEnabled") !== null) ? false : true;
  1071. SBGuruEnabled = (localStorage.getItem("SBGuruEnabled") !== null) ? false : true;
  1072. SBMasterEnabled = (localStorage.getItem("SBMasterEnabled") !== null) ? false : true;
  1073. SBEnlightenEnabled = (localStorage.getItem("SBEnlightenEnabled") !== null) ? false : true;
  1074. SBBurnedEnabled = (localStorage.getItem("SBBurnedEnabled") !== null) ? false : true;
  1075. SBLockedEnabled = (localStorage.getItem("SBLockedEnabled") !== null) ? false : true;
  1076. SBRadicalData = {};
  1077. SBKanjiData = {};
  1078. SBVocabData = {};
  1079. 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";
  1080. SBIndex = (localStorage.getItem("SBIndex") !== null) ? JSON.parse(localStorage.getItem("SBIndex")) : {
  1081. "radicals": {
  1082. "apprentice": [], "guru": [], "master": [], "enlighten": [], "burned": [], "locked": []
  1083. }, "kanji": {
  1084. "apprentice": [], "guru": [], "master": [], "enlighten": [], "burned": [], "locked": []
  1085. }, "vocabulary": {
  1086. "apprentice": [], "guru": [], "master": [], "enlighten": [], "burned": [], "locked": []
  1087. }
  1088. };
  1089. SBIndexCount = (localStorage.getItem("SBIndexCount") !== null) ? JSON.parse(localStorage.getItem("SBIndexCount")) : {
  1090. "radicals": {
  1091. "apprentice": 0, "guru": 0, "master": 0, "enlighten": 0, "burned": 0, "locked": 0
  1092. }, "kanji": {
  1093. "apprentice": 0, "guru": 0, "master": 0, "enlighten": 0, "burned": 0, "locked": 0
  1094. }, "vocabulary": {
  1095. "apprentice": 0, "guru": 0, "master": 0, "enlighten": 0, "burned": 0, "locked": 0
  1096. }
  1097. };
  1098. SBIndexBG = (localStorage.getItem("SBIndexBG") !== null) ? JSON.parse(localStorage.getItem("SBIndexBG")) : { "radicals": [], "kanji": [], "vocabulary": [] };
  1099. $(getSBSection()).insertBefore($(".review-status ul"));
  1100. if (!SBLangJP) $("#loadingSB").html('<a lang="ja" href="javascript:void(0)" style="font-size: 52px; color: #434343; text-decoration: none">Start</a>');
  1101. else $("#loadingSB").html('<a lang="ja" href="javascript:void(0)" style="font-size: 52px; color: #434343; text-decoration: none">開始</a>');
  1102. $("#loadingSB a").click( function() {
  1103. if (!SBUseCache) clearSBItemData();
  1104. getSBWKData();
  1105. });
  1106. if (!SBStart) $("#loadingSB a").click();
  1107. }
  1108. // ==/UserScript==