Greasy Fork

imageBaiduSlide

image Baidu Slide

目前为 2021-12-10 提交的版本。查看 最新版本

// ==UserScript==
// @name       imageBaiduSlide
// @namespace  https://blog.csdn.net/huang007guo
// @version    0.6
// @description  image Baidu Slide
// @match        https://image.baidu.com/search/detail?*
// @include        https://image.baidu.com/search/detail?*
// @copyright  20181129+, Hank
// @run-at document-end
// @require       https://code.jquery.com/jquery-3.3.1.min.js
// ==/UserScript==
(function (){
    var opacity = .4;
    var playInterval = getlocalKey("playInterval")?getlocalKey("playInterval"):10;
    var playInt = null;
    var openUrl = $("<div style='display:block;position:fixed;top:10px;left:10px;opacity:" + opacity +
                    ";z-index:999;' class='openUrl'><button style='width:40px;height:40px;font:20px bold;line-height:0px;border-radius:20px;' type='button'>&gt;</button>"+
                    "<button style='width:30px;height:30px;font:20px bold;line-height:0px;border-radius:30px' type='button'>O</button>"+
                    "<input type='number' style='width:35px' step='0.25' value="+ playInterval +"></div>");
    $("body").append(openUrl);
    //移入移出
    openUrl.mouseover(() => {
        openUrl.css("opacity", 0.9);
    }).mouseleave(() => {
        openUrl.css("opacity", opacity);
    });
    //play按钮
    openUrl.find("button:eq(0)").click(() => {
        if(playInt){
            openUrl.find("button:eq(1)").show();
            openUrl.find("input").show();
            window.clearInterval(playInt);
            playInt = null;
            openUrl.find("button:eq(0)").text(">");
            opacity = .4;
        }else{
            openUrl.find("button:eq(1)").hide();
            openUrl.find("input").hide();
            playInterval = openUrl.find("input").val();
            setlocalKey(playInterval, "playInterval");
            playInt = window.setInterval(()=>{
                //let newEl = $(".img-next:visible").length>0?$(".img-next:visible"):$(".right-arrow-wrap");
                $(".img-next").trigger("click");
                $(".right-arrow-wrap:visible").length>0 && $(".right-arrow-wrap:visible").trigger("click");
                setlocalKey(window.location.href);
            }, playInterval*1000);
            openUrl.find("button:eq(0)").text("||");
            opacity = .1;
        }
    })
    //O按钮
    openUrl.find("button:eq(1)").click(()=>{
        window.location.href = getlocalKey();
    });
    function getlocalKey(type='nowHref'){
        return window.localStorage["https://image.baidu.com/search/detail?word="+getWord()+type];
    }
    function setlocalKey(val, type='nowHref'){
        return window.localStorage["https://image.baidu.com/search/detail?word="+getWord()+type] = val;
    }
    function getWord(){
        return window.location.href.replace(/^http.*?(\&|\?)word=(.*?)\&.*$/, "$2");
    }
})();