WaniKani Profile Beautifier

Show numerical details instead of percentage on profile page

目前为 2017-12-03 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name WaniKani Profile Beautifier
  3. // @namespace https://www.wanikani.com
  4. // @version 0.2
  5. // @description Show numerical details instead of percentage on profile page
  6. // @author polv
  7. // @match https://www.wanikani.com/users/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. var color = {
  12. apprentice : '#E64CA3',
  13. guru : '#933BAB',
  14. master : '#4764DD',
  15. enlighten : '#3E9AE5',
  16. burned : '#000000'
  17. };
  18.  
  19. (function() {
  20. 'use strict';
  21.  
  22. $.ajax({ // ajax call starts
  23. url: 'https://www.wanikani.com/api/user/' + localStorage.apiKey + '/srs-distribution',
  24. dataType: 'json', // Choosing a JSON datatype
  25. })
  26. .done(function(data) {
  27. var total_count = 0;
  28. $.each(data.requested_information, function(key, value){
  29. total_count += value.kanji;
  30. });
  31.  
  32. var html_array = [];
  33. $.each(data.requested_information, function(key, value){
  34. html_array.push('<div class="bar-supplemental" style="text-align: right; float:left; width: ' + value.kanji/total_count*100 + '%; background-color:' + color[key] + '"><span class="beautifier_box">'+ value.kanji + '</span></div>');
  35. });
  36. $('.kanji-progress .progress').html(html_array.reverse().join(''));
  37.  
  38. total_count = 0;
  39. $.each(data.requested_information, function(key, value){
  40. total_count += value.vocabulary;
  41. });
  42. html_array = [];
  43. $.each(data.requested_information, function(key, value){
  44. html_array.push('<div class="bar-supplemental" style="text-align: right; float:left; width: ' + value.vocabulary/total_count*100 + '%; background-color:' + color[key] + '"><span class="beautifier_box">'+ value.vocabulary + '</span></div>');
  45. });
  46. $('.vocabulary-progress .progress').html(html_array.reverse().join(''));
  47. var style = css($(".bar span"));
  48. console.log(style);
  49. $('.beautifier_box').css({
  50. position: 'relative',
  51. top: '-20px',
  52. margin: '0.5em'
  53. });
  54.  
  55. }).fail(function(err) {
  56. alert(err.code);
  57. });
  58. })();
  59.  
  60. function css(a) {
  61. var sheets = document.styleSheets, o = {};
  62. for (var i in sheets) {
  63. var rules = sheets[i].rules || sheets[i].cssRules;
  64. for (var r in rules) {
  65. if (a.is(rules[r].selectorText)) {
  66. o = $.extend(o, css2json(rules[r].style), css2json(a.attr('style')));
  67. }
  68. }
  69. }
  70. return o;
  71. }
  72.  
  73. function css2json(css) {
  74. var s = {};
  75. if (!css) return s;
  76. if (css instanceof CSSStyleDeclaration) {
  77. for (var i in css) {
  78. if ((css[i]).toLowerCase) {
  79. s[(css[i]).toLowerCase()] = (css[css[i]]);
  80. }
  81. }
  82. } else if (typeof css == "string") {
  83. css = css.split("; ");
  84. for (var i in css) {
  85. var l = css[i].split(": ");
  86. s[l[0].toLowerCase()] = (l[1]);
  87. }
  88. }
  89. return s;
  90. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址