蜜柑动画新番快速定位

使用快捷键 F 或 S 打开快速定位搜索框,ESC关闭。

  1. // ==UserScript==
  2. // @name 蜜柑动画新番快速定位
  3. // @namespace pks
  4. // @version 0.121
  5. // @icon https://mikanani.me/favicon.ico
  6. // @description 使用快捷键 F 或 S 打开快速定位搜索框,ESC关闭。
  7. // @author pks
  8. // @include /^https?://mikanani\.me/?$/
  9. // @include /^https?://mikanani\.me/Home/MyBangumi/?$/
  10. // @grant none
  11. // ==/UserScript==
  12. $(function () {
  13. (function(){
  14. var css = '.highlight{animation:bg 3s infinite} .highlight .an-text{color: red !important}@keyframes bg{0%{background-color:rgba(255,255,0,0.18);} 25%{background-color:rgba(255,255,0,0.5);} 50%{background-color:rgba(255,255,0,0.1);} 75%{background-color:rgba(255,255,0,0.3);} 100%{background-color:rgba(255,255,0,0.18);}} ',
  15. head = document.head || document.getElementsByTagName('head')[0],
  16. style = document.createElement('style');
  17.  
  18. style.type = 'text/css';
  19. if (style.styleSheet){
  20. style.styleSheet.cssText = css;
  21. } else {
  22. style.appendChild(document.createTextNode(css));
  23. }
  24.  
  25. head.appendChild(style);
  26. })();
  27.  
  28.  
  29.  
  30. function scrollToElement(ele) {
  31. var eleTop = $(ele).offset().top;
  32. if (!!document.querySelector('#sk-data-nav')) {
  33. $(window).animate({scrollTop: !!document.querySelector('#sk-data-nav.stick')?eleTop - 80:eleTop - 141});
  34. } else {
  35. $(window).animate({scrollTop: eleTop - 10});
  36. }
  37. $('.highlight').removeClass('highlight');
  38. $(ele).addClass('highlight');
  39. setTimeout(function(){
  40. $(ele).removeClass('highlight');
  41. }, 6000);
  42. }
  43.  
  44. function submitFilter() {
  45. var dropDownList = [];
  46. bangumis.forEach(function(item,index,arr){
  47. if (item.name.toLowerCase().trim().indexOf($('#filter').val().toLowerCase().trim()) !== -1 && dropDownList.length <= 5) {
  48. dropDownList.push(index);
  49. }
  50. });
  51. if (dropDownList.length > 0) {
  52. scrollToElement(bangumis[dropDownList[0]].element);
  53. }
  54. $('#filter').val('');
  55. $('#filter').css('display', 'none').blur();
  56. }
  57.  
  58. $('.main-content').on('click','span.js-expand_bangumi',function(e){
  59. console.log(e.target, this);
  60. if ($(this).parent().is('.active')) {
  61. setTimeout(function(){
  62. scrollToElement(e.target);
  63. },1500);
  64. }
  65. });
  66.  
  67. var bangumis = [];
  68.  
  69. function getBangumis() {
  70. bangumis = [];
  71. $('.an-info').each(function(index,element){
  72. var obj = {};
  73. obj.name = $(element).find('a.an-text').attr('title') || $(element).find('.date-text').eq(1).text();
  74. obj.element = $(element).closest('li')[0];
  75. bangumis.push(obj);
  76. });
  77. console.log(bangumis);
  78. }
  79. getBangumis();
  80.  
  81. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  82. var target = document.querySelector('#sk-body');
  83. var observer = new MutationObserver(getBangumis);
  84. var config = {childList: true};
  85. observer.observe(target, config);
  86.  
  87. $('<input id="filter" placeholder="新番快速查找 ( Enter键提交 )">')
  88. .css({
  89. 'width': '350px',
  90. 'height': '64px',
  91. 'position': 'fixed',
  92. 'top': 0,
  93. 'right': 0,
  94. 'bottom': 0,
  95. 'left': 0,
  96. 'margin': 'auto',
  97. 'fontSize': '24px',
  98. 'opacity': '0.9',
  99. 'textAlign': 'center',
  100. 'display':'none'
  101. }).appendTo('body');
  102.  
  103. $('#filter').on('keydown', function (e) {
  104. if (e.keyCode === 27 && !!$(this).val()) {
  105. $(this).wrap('<form></form>');
  106. $(this).parent()[0].reset();
  107. $(this).unwrap();
  108. $(this).focus();
  109. } else if (/^(13|8|27)$/.test(e.keyCode) && $(this).val()==='') {
  110. $(this).css('display', 'none').blur();
  111. } else if (e.keyCode === 13 && !!$(this).val() ) {
  112. submitFilter();
  113. }
  114. });
  115. var callFilter = function (e) {
  116. if (e.target.nodeName !== 'INPUT' && e.target.nodeName !== 'TEXTAREA' && /^(70|83)$/.test(e.keyCode) && $(window).width() >=992) {
  117. $('#filter').css('display', 'block').focus();
  118. }
  119. };
  120. $(document).on('keyup.wideScreenOnly', callFilter);
  121. $(window).on('resize', function (e) {
  122. if ($(window).width() <= 991) {
  123. $('#filter').css('display', 'none').blur();
  124. $(document).off('.wideScreenOnly');
  125. } else {
  126. $(document).on('keyup.wideScreenOnly', callFilter);
  127. }
  128. });
  129. $(document).on('click', function (e) {
  130. if (e.target.id !== 'filter' && $('#filter').css('display') === 'block') {
  131. $('#filter').css('display', 'none').blur();
  132. }
  133. });
  134. });
  135.  

QingJ © 2025

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