// ==UserScript== // @name MutliQRCode // @namespace https://greasyfork.org/zh-CN/users/1073349 // @version 0.5.3 // @description PC端和移动端都可用的二维码识别 // @author 4ehex // @grant GM_setValue // @grant GM_getValue // @grant GM_xmlhttpRequest // @match *://*/* // @icon data:image/svg+xml;base64,PHN2ZyBjbGFzcz0iaWNvbiIgc3R5bGU9IndpZHRoOiAxZW07aGVpZ2h0OiAxZW07dmVydGljYWwtYWxpZ246IG1pZGRsZTtmaWxsOiBjdXJyZW50Q29sb3I7b3ZlcmZsb3c6IGhpZGRlbjsiIHZpZXdCb3g9IjAgMCAxMDI0IDEwMjQiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBwLWlkPSI3NjA1Ij48cGF0aCBkPSJNMTg2LjAyNjY2NyAwaDY1MS45NDY2NjZRMTAyNCAwIDEwMjQgMTg2LjAyNjY2N3Y2NTEuOTQ2NjY2UTEwMjQgMTAyNCA4MzcuOTczMzMzIDEwMjRIMTg2LjAyNjY2N1EwIDEwMjQgMCA4MzcuOTczMzMzVjE4Ni4wMjY2NjdRMCAwIDE4Ni4wMjY2NjcgMHoiIGZpbGw9IiMzNjg5RjUiIHAtaWQ9Ijc2MDYiPjwvcGF0aD48cGF0aCBkPSJNMjEzLjMzMzMzMyAzMDQuNjRBOTAuODggOTAuODggMCAwIDEgMzA0LjIxMzMzMyAyMTMuMzMzMzMzaDkwLjg4djQyLjY2NjY2N0gzMDYuMzQ2NjY3YTQ1LjY1MzMzMyA0NS42NTMzMzMgMCAwIDAtNDYuNTA2NjY3IDQ4LjY0djkxLjczMzMzM0gyMTMuMzMzMzMzek0zOTYuOCA4MTAuNjY2NjY3SDMwNi4zNDY2NjdhOTAuNDUzMzMzIDkwLjQ1MzMzMyAwIDAgMS05MC44OC05MS4zMDY2Njd2LTkxLjczMzMzM2g0Ni41MDY2NjZ2OTEuNzMzMzMzQTQ1LjY1MzMzMyA0NS42NTMzMzMgMCAwIDAgMzA4LjA1MzMzMyA3NjhoOTAuODhhMjk4LjY2NjY2NyAyOTguNjY2NjY3IDAgMCAwLTIuMTMzMzMzIDQyLjY2NjY2N3pNODEwLjY2NjY2NyA3MTkuMzZBOTAuNDUzMzMzIDkwLjQ1MzMzMyAwIDAgMSA3MTcuNjUzMzMzIDgxMC42NjY2NjdINjI3LjJ2LTQ2LjkzMzMzNGg5MC40NTMzMzNhNDUuNjUzMzMzIDQ1LjY1MzMzMyAwIDAgMCA0Ni41MDY2NjctNDYuNTA2NjY2di05MS4zMDY2NjdIODEwLjY2NjY2N3pNMjEzLjMzMzMzMyA0ODcuNjhoNTk1LjJ2NDYuOTMzMzMzSDIxMy4zMzMzMzN6TTgxMC42NjY2NjcgMzk2LjM3MzMzM2gtNDguNjRWMzA0LjY0YTQ1LjY1MzMzMyA0NS42NTMzMzMgMCAwIDAtNDYuMDgtNDYuNTA2NjY3aC05MC44OFYyMTMuMzMzMzMzaDkwLjg4YTkwLjg4IDkwLjg4IDAgMCAxIDkwLjg4IDkxLjMwNjY2N3oiIGZpbGw9IiNGRkZGRkYiIHAtaWQ9Ijc2MDciPjwvcGF0aD48L3N2Zz4= // @require https://update.greasyfork.icu/scripts/469053/1207999/jsQR.js // @grant unsafeWindow // @license GPL // @downloadURL none // ==/UserScript== (function() { 'use strict'; //全局变量 被选中的图片src var g_img_src = null; var g_is_moblie_env = isPhone(); var g_cors_proxy = ['GM_xmlhttpRequest', 'https://api.allorigins.win/get?url=', 'https://corsproxy.io/?']; var g_usr_diy_cors = GM_getValue('usr_diy_cors', ''); var g_cur_use_cors = GM_getValue('cur_use_cors', g_cors_proxy[0]); //适配移动端 很多移动端浏览器并没有实现油猴接口 //添加'识别二维码'按钮样式 let btn_style = document.createElement('style'); btn_style.type = 'text/css'; if (!g_is_moblie_env){ btn_style.innerText = `.idtfy_div{width:5.5vw;height:2.1vh;font-size:1vh;color:#000000;background:#F8F8FF;border-radius:1.5vh;border:0.12vh solid #f2cac9;line-height:2vh;text-align:center;vertical-align:middle;z-index:99999999;display:none;position:absolute;top:20;left:20;cursor:pointer;box-shadow:0.13vh 0.13vh 0.1vh #888888;}`; //GM_addStyle(`.idtfy_div{width:5.5vw;height:2.1vh;font-size:1vh;color:#000000;background:#F8F8FF;border-radius:1.5vh;border:0.12vh solid #f2cac9;line-height:2vh;text-align:center;vertical-align:middle;z-index:99999999;display:none;position:absolute;top:20;left:20;cursor:pointer;box-shadow:0.13vh 0.13vh 0.1vh #888888;}`); } else{ btn_style.innerText = `.idtfy_div{width:25vw;height:3vh;font-size:1.6vh;color:#000000;background:#F8F8FF;border-radius:1.5vh;border:0.14vw solid #f2cac9;line-height:3vh;text-align:center;vertical-align:middle;z-index:99999999;display:none;position:absolute;top:20;left:20;cursor:pointer;box-shadow:0.15vw 0.15vw 0.13vw #888888;}`; } document.head.appendChild(btn_style); //添加'识别二维码'按钮 var identify_div = document.createElement('div'); identify_div.id = 'identify_div'; identify_div.className = 'idtfy_div';//👇添加一个图标 identify_div.innerHTML = ` 识别二维码`; identify_div.onclick = OnClickedIdentifyBtn; document.body.appendChild(identify_div); //添加精简后的'notie.js' 一款纯js实现的消息弹窗 var notie=function(){function E(a,b,c){document.activeElement.blur(),D++,setTimeout(function(){D--},1e3*e+10),1==D&&(A?(clearTimeout(B),clearTimeout(C),G(function(){F(a,b,c)})):F(a,b,c))}function F(b,c,d){A=!0;var f=0;switch(f="undefined"==typeof d?3e3:1>d?1e3:1e3*d,b){case 1:v.style.backgroundColor=g,v.onclick=function(){};break;case 2:v.style.backgroundColor=h,v.onclick=w;break;case 3:v.style.backgroundColor=i,v.onclick=w;break;case 4:v.style.backgroundColor=j,v.onclick=w}y.innerHTML=c,v.style.top="-10000px",v.style.display="table",v.style.top="-"+v.offsetHeight-5+"px",B=setTimeout(function(){a&&(v.style.boxShadow="0px 0px 10px 0px rgba(0,0,0,0.5)"),v.style.MozTransition="all "+e+"s ease",v.style.WebkitTransition="all "+e+"s ease",v.style.transition="all "+e+"s ease",v.style.top=0,C=setTimeout(function(){G(function(){})},f)},20)}function G(b){v.style.top="-"+v.offsetHeight-5+"px",setTimeout(function(){a&&(v.style.boxShadow=""),v.style.MozTransition="",v.style.WebkitTransition="",v.style.transition="",v.style.top="-10000px",A=!1,b&&b()},1e3*e+10)}var v,w,x,y,A,B,C,D,a=!0,b="18px",c="24px",d=600,e=.3,g="#57BF57",h="#E3B771",i="#E1715B",j="#4D82D6",k="#FFF",l="notie-alert-outer",m="notie-alert-inner",n="notie-alert-text",o=function(a){a.style.fontSize=window.innerWidth<=d?b:c},p=500,q=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}};return window.addEventListener("keydown",function(a){var b=13==a.which||13==a.keyCode,c=27==a.which||27==a.keyCode;A&&(b||c)&&(clearTimeout(B),clearTimeout(C),G())}),"undefined"==typeof Element.prototype.addEventListener&&(Element.prototype.addEventListener=Window.prototype.addEventListener=function(a,b){return a="on"+a,this.attachEvent(a,b)}),v=document.createElement("div"),v.id=l,v.style.position="fixed",v.style.top="0",v.style.left="0",v.style.zIndex="999999999",v.style.height="auto",v.style.width="100%",v.style.display="none",v.style.textAlign="center",v.style.cursor="default",v.style.MozTransition="",v.style.WebkitTransition="",v.style.transition="",v.style.cursor="pointer",w=function(){clearTimeout(B),clearTimeout(C),G()},x=document.createElement("div"),x.id=m,x.style.padding="20px",x.style.display="table-cell",x.style.verticalAlign="middle",v.appendChild(x),y=document.createElement("span"),y.id=n,y.style.color=k,y.style.fontSize=window.innerWidth<=d?b:c,window.addEventListener("resize",q(o.bind(null,y),p),!0),x.appendChild(y),document.body.appendChild(v),A=!1,D=0,{alert:E,alert_hide:G}}(); //👆以上混淆纯粹为了压缩体积 原作者代码: https://github.com/jaredreich/notie if (!g_is_moblie_env){ //电脑端 右键弹出 双击隐藏 window.onmousedown = function(e) { if (e.button == 2) {//右键 var clickedElement = e.target; if (clickedElement.id == 'identify_div'){ SelectCorsProxy(); document.getElementById("identify_div").style.display = 'none'; } else if ((g_img_src = GetQRSrc(clickedElement)) != null){ document.getElementById("identify_div").style.top = (e.pageY + 10) + "px"; document.getElementById("identify_div").style.left = (e.pageX) + "px"; document.getElementById("identify_div").style.display = 'block'; } else{ document.getElementById("identify_div").style.display = 'none'; } } }; window.ondblclick = function(e) {//双击隐藏按钮 document.getElementById("identify_div").style.display = 'none'; }; } else{ //移动端 监听长按事件 let time_out = 0, touch_time = 800; window.addEventListener("touchstart", function(e){ time_out = setTimeout(function(){ var touchedElement = e.target; if (touchedElement.id == 'identify_div'){ //长按识别按钮 弹出设置跨域代理服务器的设置窗口 SelectCorsProxy(); document.getElementById("identify_div").style.display = 'none'; } else if ((g_img_src = GetQRSrc(touchedElement)) != null) { document.getElementById("identify_div").style.top = (e.touches[0].pageY - 50) + "px"; document.getElementById("identify_div").style.left = (e.touches[0].pageX + 20) + "px"; document.getElementById("identify_div").style.display = 'block'; } }, touch_time);//touch_time毫秒后弹出识别按钮 //触碰其他地方则隐藏按钮 if (e.target.id != 'identify_div'){ g_img_src = null; document.getElementById("identify_div").style.display = 'none'; } }); window.addEventListener("touchmove", function(e){ // 如果触摸未达到 touch_time ms且开始移动,则清除计时器 clearTimeout(time_out); time_out = 0; }); window.addEventListener("touchend", function(e){ // 如果触摸未达到 touch_time ms且离开屏幕,则清除计时器 clearTimeout(time_out); time_out = 0; }); } //设置/选择跨域代理服务器 function SelectCorsProxy(){ let select_html = ``, options_html, usr_input_html = ``; for (let i = 0, len = g_cors_proxy.length; i < len; i++){ options_html += ``; } select_html = select_html.replace('[options_]', options_html); let setting_html = `
`; notie.alert(1, '选择一个跨域代理服务器