UNPKG

dashen-tool

Version:

无法超越的大神代码

113 lines (112 loc) 4.35 kB
const DS_tool ={ parseUA : function() { var c = navigator.userAgent; var d = navigator.userAgent.toLowerCase(); var e = d.match(/MicroMessenger/i) == "micromessenger"; var b = e || (!!c.match(/(iPhone|iPod|Android|ios|Mobile)/i)); return { mobile: b, pc: !b, ios: !!c.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), android: c.indexOf("Android") > -1, weixin: e, newsapp: c.indexOf("NewsApp") > -1, yixin: c.indexOf("YiXin") > -1, weibo: c.indexOf("weibo") > -1, yunyuedu: c.indexOf("PRIS") > -1, cloudmusic: d.indexOf("neteasemusic") > -1 } }, pc_code:function() { var isPC = DS_tool.parseUA().pc; if (isPC) { if (document.body.getAttribute("code") == "no") { return } var d = document.createElement("div"); d.style.cssText = "width:100%;height:100%;position:fixed;left:0px;top:0px;z-index:9999999;background:#fff;"; var e = document.createElement("img"); e.style.cssText = "width:300px;height:300px;position:fixed;top:50%;left:50%;margin-left:-150px;margin-top:-220px;"; e.setAttribute("src", "http://tool.oschina.net/action/qrcode/generate?data=" + encodeURIComponent(location.href) + "&output=image%2Fgif&error=L&type=0&margin=4&size=4"); d.appendChild(e); var b = document.createElement("p"); b.style.cssText = "width:300px;height:300px;position:fixed;top:50%;left:50%;margin-left:-150px;margin-top:80px;text-align:center;font-size:19px;font-weight:bold;"; d.appendChild(b); document.body.appendChild(d) } if (console.group) { console.group(location.href) } console.log("%c ", "opacity:.6;display:block;padding:50px;background:url('http://tool.oschina.net/action/qrcode/generate?data=" + encodeURIComponent(location.href) + "&output=image%2Fgif&error=L&type=0&margin=4&size=4') no-repeat;background-size:contain;"); if (console.group) { console.groupEnd() } }, landscape:function() { var landscapeDiv = document.createElement("div"); landscapeDiv.className = "landscape"; // landscapeDiv.innerHTML = "<img src='//art.163.com/ping/news/exihibition4/src/assets/notice.png'>"; landscapeDiv.style.cssText = "width:100%;height:100%;position:fixed;left:0px;top:0px;z-index:999999999;background:#000 url(//go.163.com/2015/public/common/image/tip2.png) no-repeat center center;display:none;"; setTimeout(function() { document.body.appendChild(landscapeDiv) }, 200); function orientationIs() { if (document.body.getAttribute("landscape") == "no") { return } if (window.orientation === 180 || window.orientation === 0) { setTimeout(function() { landscapeDiv.style.display = "none" }, 250) } if (window.orientation === 90 || window.orientation === -90) { setTimeout(function() { landscapeDiv.style.display = "block" }, 250) } } orientationIs(); window.addEventListener("onorientationchange"in window ? "orientationchange" : "resize", orientationIs, false) }, autoPlay:function(c) { function b(d) { document.removeEventListener("WeixinJSBridgeReady", b, false); document.removeEventListener("YixinJSBridgeReady", b, false); document.removeEventListener("touchstart", b, false); switch (typeof (c)) { case "string": console.log('string') document.getElementById(c).play(); break; case "object": console.log('object') c.play(); break; case "function": c(d); break } } document.addEventListener("WeixinJSBridgeReady", b, false); document.addEventListener("YixinJSBridgeReady", b, false); document.addEventListener("touchstart", b, false); if (window.netease_ds.ua.ios && window.netease_ds.ua.newsapp) { b() } }, init: function() { window.netease_ds = DS_tool; window.netease_ds.ua = DS_tool.parseUA(); console.log(window.netease_ds.ua) console.log(DS_tool.parseUA()) DS_tool.landscape(); // a.survey(); // a.ant(); // window.share_survey = a.share_survey; // share_survey(); DS_tool.pc_code(); // a.share(); // a.addVConsole() } } export default DS_tool