// ==UserScript== // @name MyShowBox // @version 2025.12.29.2 // @description Kquery+MyDownloaderBox+Downloader // @author You // @grant none // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_download // @require https://scriptcat.org/lib/3250/1.0.0/Kquery.js?sha384-ZncoRTUgKTzjYO2TOYZ/dyZbmdXbvRwRgZw0demGIW6d40YqqdPB3fXcy3AtXjR1 // @require https://scriptcat.org/lib/3859/1.0.1/MyDownloaderBox.js?sha384-2ailwX24CSjHB9pShHnrdPL3wceTdkPpXNIcI7BRBaXQbKuSj3BtKYC20BR105wR // ==/UserScript== /** * 把图片全部添加到一个Showbox里的类,只能new一次 * @class * @example const showBox = new ShowBox(); showBox.Add(imgs); @ps Add函数只能调用一次 */ function ShowBox(){ let imgs = null; let num = 10; let showNum = num; let nowIndex = 0; /** * @type {Downloader} */ let downloader = new DownloadBox(); let box = $('.clickShowBox').length > 0 ? $('.clickShowBox') : CreateShowBox() this.downloader = {get obj(){return downloader;}} /** * 把图片全部添加到一个Showbox里 * @example Add(imgs) * @param {JQuery} iimgs * @ps 只能调用一次,等图片获取完了再调用 */ this.Add = (iimgs)=>{ imgs = iimgs; AddImgs(); } /** * @example controlType = "mouse" */ this.controlType = "mouse"; /** * 设置一次预加载多少图片,默认是10 * @example SetShowNum = 20 * @param {number} n * @ps 未加载的图片src为空,只有small_src和big_src */ this.SetShowNum = (n) => {showNum = num = n;} /** * @param {string} type - {gm / iframe / blob} */ //this.Set_donwloadType = (type)=>{downloader = new DownloaderFactory(type);} /** * 重写下载图片的方法 * @example SetDonloadFunction((name,src)=>{...}) * @param {function({name:string},{src:string}):void} foo - (name,src)=>{} */ //this.SetDonloadFunction = (/**@type {function({name:string},{src:string}):void}*/foo)=>{downloader.download = foo;} function AddImgs(){ const i = 0; const time = new Date().getTime(); imgs.each(function(){ const n = document.title + time + i + (this.src?.match(/\.jpg|\.jpeg|\.webp|\.png/i)?.[0] || '.png'); const item = $('
') .append($('').attr({'small_src':this.src,src:"",'big_src':$(this).attr('big_src'),name:n})); $('.clickShowBox').append(item); i++; }) ClickShowNext({img:$('img'),onlyDown:false}); } function CreateShowBox(){ let box = `

1/10

` box = $(box); $('body').prepend(box); $('.clickShowBox .close').click(function(){ $('.clickShowBox').fadeOut(); $('.clickShowBox_ShowBu').show() }) $('.clickShowBox_ShowBu').click(function(){ $('.clickShowBox').fadeIn(); $(this).hide(); Show_imgs(num); }) $('.clickShowBox .download').click(function(){ BU_nomal($(this)) const img = $('.clickShowBox .item img').eq(nowIndex); let src = img[0].src; if(img.attr('big_src')){ src = img.attr('big_src'); img[0].src = src; } let name = document.title + new Date().getTime() + src.match(/\.jpg|\.jpeg|\.webp|\.png/g)[0]; if(img.attr('name')){ name = img.attr('name'); } BU_busy($(this)) try{ GM_download({ url:src, name:name, onload:function(){ BU_done($('.download')); }, error:function(){ BU_error($('.download')); } }) }catch(error){ console.log(error); BU_error($('.download')); } }) $('.clickShowBox .downloadall').click(function(){ BU_busy($(this)); try{ //console.log(downloader) downloader.AddImgs($('.clickShowBox .item img').clone()); }catch(error){ console.log(error); BU_error($(this)); } }) // downloader.AllComplete(()=>{ // BU_done($('.clickShowBox .downloadall')); // }); // downloader.OneSuccess((img)=>{ // $('.clickShowBox .item img').filter(function(){return $(this).attr('big_src')||$(this).attr('small_src') == img[0].src}) // .attr('src',img[0].src); // }); Add_ClickShowBox_css(); $('.clickShowBox').hide(); Add_keyControl() return box; } function Add_ClickShowBox_css(){ let css = ` .clickShowBox{ width: 100%; height: 100%; background-color: #2d2d2d; overflow: hidden; border-radius: 0vw; position: fixed; z-index: 9999; } .clickShowBox .item{ width: 100%; height: 100%; background-color: #2D2D2D; display: flex; align-items: center; justify-content: center; } .clickShowBox .item img{ max-width: 100%; height: auto; max-height: 100%; } .clickShowBox .pages{ font-size: 5vw; color: rgba(255,255,255,0.5); position: fixed; top: 1.5vw; margin: 2vw; right:12vw } .clickShowBox .close{ width: 10vw; height:10vw; font-size: 6vw; border-radius: 10vw; background-color: rgba(255,255,255,0.1); color: rgba(255,255,255,0.1); position: fixed; right: 0; top:0; margin: 2vw; font-weight: bold; border: none; } .clickShowBox .close:active{ filter:invert(100%); } .clickShowBox .downloadBU{ display: flex; flex-direction: row; position: fixed; bottom:0; } .clickShowBox .download ,.clickShowBox .downloadall{ width:100%; font-size: 5vmin; aspect-ratio: 1/1; border-radius: 2vmin; background-color: #ff8a17; color: white; margin: 0 0 2vw 2vw; border: none; opacity: .4; position: relative; } .clickShowBox .download:active ,.clickShowBox .downloadall:active{ opacity: .6; } .clickShowBox .busy{ animation: BU_busy infinite 1s linear; } @keyframes BU_busy{ 0%{top:0} 25%{top:2vw} 75%{top:-2vw} 100%{top:0} } .clickShowBox .error{ background-color: red; } .clickShowBox_ShowBu{ width: 10vw; height: 10vw; border-radius: 10vw; background-color: orange; position: fixed; bottom: 30%; right: -5vw; z-index: 999999; display: flex; align-items: center; justify-content: center; } .clickShowBox_ShowBu::after{ content: ""; width: 70%; height: 70%; background-image: url('data:image/svg+xml;utf8,'); background-size: cover; background-repeat: no-repeat; transform: scaleX(0.8); } ` Add_css(css) } function BU_busy(bu){ bu.addClass('busy'); } function BU_done(bu){ bu.removeClass('busy'); } function BU_error(bu){ bu.removeClass('busy'); bu.addClass('error'); } function BU_nomal(bu){ bu.removeClass('busy').removeClass('error'); } function Add_keyControl(){ let downItem = $('