// ==UserScript== // @name 图片采集下载工具 // @namespace http://tampermonkey.net/ // @version 1.1 // @description 测试一下 // @grant GM_setValue // @grant GM_getValue // @grant GM_listValues // @grant GM_deleteValue // @grant GM_download // @author yinyi // @include * // @downloadURL https://update.greasyfork.icu/scripts/374077/%E5%9B%BE%E7%89%87%E9%87%87%E9%9B%86%E4%B8%8B%E8%BD%BD%E5%B7%A5%E5%85%B7.user.js // @updateURL https://update.greasyfork.icu/scripts/374077/%E5%9B%BE%E7%89%87%E9%87%87%E9%9B%86%E4%B8%8B%E8%BD%BD%E5%B7%A5%E5%85%B7.meta.js // ==/UserScript== (function() { //全局变量 var ci = 0 var time = 0 var huan = 0 var time1 = 0 var dian = 0 var myVar; var zifuchangdu; var img_src = new Array(); var img_name = new Array(); //检测为分页采集模式跳转 if(GM_getValue("moshi") == 2 && GM_getValue("caijixia") !== undefined && GM_getValue("caijitu") !== undefined && GM_getValue("zhuti") !== undefined){ img_src=GM_getValue("imgurl"); img_name=GM_getValue("imgname"); zifuchangdu=GM_getValue("zifucd"); console.log(GM_getValue("imgurl")); console.log(GM_getValue("imgname")); console.log(GM_getValue("caijixia")); jiansuo(); var tiaozhuan = document.evaluate(GM_getValue("caijixia"), document).iterateNext(); if(tiaozhuan){ console.log(tiaozhuan) if(tiaozhuan.href.substring(tiaozhuan.href.length-1) == "#"){ tiaozhuan.href = tiaozhuan.href.substring(0,tiaozhuan.href.length-1) } if(tiaozhuan.href && tiaozhuan.href !== window.location.href){ console.log("有href"+tiaozhuan.href +"||"+ window.location.href) setTimeout(function(){ GM_setValue("winurl",window.location.href);tiaozhuan.click(); }, 300); }else{ console.log("无href") if(tiaozhuan.parentNode.href){ console.log("上层有"+tiaozhuan.parentNode) setTimeout(function(){ GM_setValue("winurl",window.location.href);tiaozhuan.parentNode.click(); }, 300); }else{ console.log("结束") xiazai(); qingchu(); } } }else{ console.log("Xpath 的规则无法定位,尝试测算url 进行下一页跳转") var qwin = GM_getValue("winurl") console.log(qwin) console.log(qwin[0]+"||"+window.location.host) console.log(qwin[1]+"||"+window.location.pathname) if(qwin !== window.location.href){ var zurl = ""; zurl = zifu(qwin,window.location.href) console.log(zurl) $.ajax({ url: zurl, type: 'GET', complete: function(response) { if(response.status == 200) { setTimeout(function(){ GM_setValue("winurl",window.location.href);window.open(zurl,"_self"); }, 300); } else { console.log("测算uel无效,终止") xiazai() qingchu(); } } }); } } } function qingchu(){ GM_deleteValue("moshi") GM_deleteValue("caijixia") GM_deleteValue("caijitu") GM_deleteValue("winurl") GM_deleteValue("zhuti") GM_deleteValue("imgurl") GM_deleteValue("imgname") } //测算url 的字符处理模块 function zifu(q,d){ var qi = ""; var hi = ""; var qn = 0; for(var i = 0;i 1200){ huan = 1; alert("在关闭本提示之后,单击需要设定为快捷键的按键,请注意避免与其他软件或脚本快捷键冲突,不支持组合键") return; }else{ GM_setValue("moshi",1) time1 = new Date().getTime()-time1 if (time1 < 450){ myStopFunction() GM_setValue("moshi",2) }else{ GM_setValue("moshi",1) time1 = new Date().getTime() } myFunction() } } } function myFunction(){myVar=setTimeout(function(){zhixing()},500);} function myStopFunction(){clearTimeout(myVar);} //绑定鼠标点击执行模块 function zhixing(){ document.addEventListener('click', link, true); console.log(GM_getValue("moshi")) GM_deleteValue("caijixia") GM_deleteValue("caijitu") GM_deleteValue("zhuti") GM_deleteValue("imgurl") GM_deleteValue("imgname") } //点击触发功能 function link(event) { event.preventDefault(); event.stopPropagation(); //moshi2触发Xpath 定位规则采集 if(event.target.tagName !== "IMG" && GM_getValue("moshi") == 2){ var inpt = prompt(" 请输入【下一页】按钮的Xpath定位",readXPath(event.target)); if(inpt){ //var data = document.evaluate(inpt, document).iterateNext(); //console.log(data) GM_setValue("caijixia",inpt) console.log(GM_getValue("caijixia")); } } //对图片特征规则采集 if(event.target.tagName == "IMG"){ var inus = event.target.src.substring(event.target.src.indexOf("\."), event.target.src.lastIndexOf("\/")+1); zifuchangdu = event.target.src.substring(event.target.src.lastIndexOf("\/")+1,event.target.src.length).length; console.log(zifuchangdu) GM_setValue("zifucd",zifuchangdu) //分割URL 获取最后 / 符号之前部分作为预设特征码,获取格式 var inpusers = prompt("请输入特征码",inus); // 弹出用户输入input框 if(inpusers){ GM_setValue("caijitu",inpusers) console.log(GM_getValue("caijitu")) //主题名称采集 var text = event.target.alt.replace(/[^\u4e00-\u9fa5]/g, '') if(text == "" && document.evaluate('//h1', document).iterateNext() !== null){ text = document.evaluate('//h1', document).iterateNext().innerHTML.replace(/[^\u4e00-\u9fa5]/g, '') } if(text == ""){text = "如需自定图片名称可以在此输入,否则请直接点击确定"} //预测匹配图片数量 var img = document.getElementsByTagName("img") var yuce = new Array(); for(var i = 0;i'+GM_getValue("imgname")[i]+'' i++ }); var xuanqu = "function opcheckboxed(objName,type){var objNameList=document.getElementsByName(objName);if(null!=objNameList){for(var i=0;i

'+GM_getValue("zhuti")+'

'+str+'
' var newwindow = window.open('','_blank','width=600,height=900'); newwindow.document.write(html); } })();