Wanikani Scrollbox

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

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

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