蜜柑动画快速过滤器

try to take over the world!

目前為 2017-11-03 提交的版本,檢視 最新版本

// ==UserScript==
// @name         蜜柑动画快速过滤器
// @namespace    pks
// @version      0.16
// @description  try to take over the world!
// @author       You
// @include        /^https?://mikanani\.me/?$/
// @grant        none
// ==/UserScript==
$(function () {
    (function(){
        var css = '.highlight::after {content:" ";height: 56px;}',
            head = document.head || document.getElementsByTagName('head')[0],
            style = document.createElement('style');

        style.type = 'text/css';
        if (style.styleSheet){
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }

        head.appendChild(style);
    })();



    function scrollToElement(ele) {
        var eleTop = $(ele).offset().top;
        $(window).animate({scrollTop: !!document.querySelector('#sk-data-nav.stick')?eleTop - 80:eleTop - 141});
    }

    function submitFilter() {
        var dropDownList = [];
        bangumis.forEach(function(item,index,arr){
            if (item.name.toLowerCase().indexOf($('#filter').val().toLowerCase()) !== -1 && dropDownList.length <= 5) {
                dropDownList.push(index);
            }
        });
        if (dropDownList.length > 0) {
            scrollToElement(bangumis[dropDownList[0]].element);
        }
        $('#filter').val('');
        $('#filter').css('display', 'none').blur();
    }

    $('.main-content').on('click','span.js-expand_bangumi',function(e){
        setTimeout(function(){
            scrollToElement(e.target);
        },1500);
    });

    var bangumis = [];

    $('.an-info a').each(function(index,element){
        var obj = {};
        obj.name = element.title;
        obj.element = $(element).closest('li')[0];
        bangumis.push(obj);
    });

    $('<input id="filter" placeholder="新番快速查找 ( Enter键提交 )">')
        .css({
        'width': '350px',
        'height': '64px',
        'position': 'fixed',
        'top': 0,
        'right': 0,
        'bottom': 0,
        'left': 0,
        'margin': 'auto',
        'fontSize': '24px',
        'opacity': '0.7',
        'textAlign': 'center',
        'display':'none'
    }).appendTo('body');

    $('#filter').on('keydown', function (e) {
        if (e.keyCode === 27 && !!$(this).val()) {
            $(this).wrap('<form></form>');
            $(this).parent()[0].reset();
            $(this).unwrap();
            $(this).focus();
        } else if (/^(13|8|27)$/.test(e.keyCode) && $(this).val()==='') {
            $(this).css('display', 'none').blur();
        } else if (e.keyCode === 13 && !!$(this).val() ) {
            submitFilter();
        }
    });
    var callFilter = function (e) {
        if (e.target.nodeName !== 'INPUT' && e.target.nodeName !== 'TEXTAREA' && /^(70|83)$/.test(e.keyCode) && $(window).width() >=992) {
            $('#filter').css('display', 'block').focus();
        }
    };
    $(document).on('keyup.wideScreenOnly', callFilter);
    $(window).on('resize', function (e) {
        if ($(window).width() <= 991) {
            $('#filter').css('display', 'none').blur();
            $(document).off('.wideScreenOnly');
        } else {
            $(document).on('keyup.wideScreenOnly', callFilter);
        }
    });
    $(document).on('click', function (e) {
        if (e.target.id !== 'filter' && $('#filter').css('display') === 'block') {
            $('#filter').css('display', 'none').blur();
        }
    });
});

QingJ © 2025

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