JS判断浏览器是否缩放(参考斗鱼源码)

// 翻斗鱼的源码看到的

 define("douyu/com/zoom", ["jquery", "shark/observer", "shark/util/cookie/1.0", "shark/util/storage/1.0", "douyu/context", "douyu/com/zoom-dp"], function (e, i, t, n, o, a) {
        var s = {
                storageName: "zoomtip",
                storageVal: "1",
                storageTime: 604800,
                isPop: !1,
                init: function () {
                    this.handleCookie(), this.pop(), i.on("mod.layout.screen.change", function (e) {
                        s.detect() && s.pop()
                    })
                }, handleCookie: function () {
                    t.get(this.storageName) && (t.remove(this.storageName), n.set(this.storageName, this.storageVal, this.storageTime))
                }, detect: function () {
                    return this.ua = navigator.userAgent.toLowerCase(), -1 == this.ua.indexOf("windows") ? !1 : !n.get(this.storageName)
                }, cal: function () {
                // 最主要的应该就是这一段了 判断设备比 比例等
                // devicePixelRatio 我测试了下火狐和谷歌目前都支持了 100% 就是1 
                    var e = 0,
                        i = window.screen;
                    return void 0 !== window.devicePixelRatio ? e = window.devicePixelRatio : ~this.ua.indexOf("msie") ? i.deviceXDPI && i.logicalXDPI && (e = i.deviceXDPI / i.logicalXDPI) : void 0 !== window.outerWidth && void 0 !== window.innerWidth && (e = window.outerWidth / window.innerWidth), e && (e = Math.round(100 * e)), 99 !== e && 101 !== e || (e = 100), e
                }, resize: function () {
                    var i = this.cal();
                    if (this.isPop && i && 100 == i) return void this.close();
                    var t = 540,
                        n = 432,
                        o = 100 * t / i,
                        a = 100 * n / i;
                    e(".pop-zoom-container").css({
                        width: o + "px",
                        height: a + "px",
                        marginLeft: -o / 2 + "px",
                        marginTop: -a / 2 + "px"
                    })
                }, pop: function () {
                    var t = this.cal();
                    if (!n.get(this.storageName) && !this.isPop && 100 !== t) {
                        var a = o.get("sys.web_url") + "app/douyu/res/com/sg-zoom-error.png?20160823",
                            s = ['<div class="pop-zoom-container">', '<div class="pop-zoom">', '<img class="pop-zoom-bg" src="', a, '">', '<div class="pop-zoom-close">close</div>', '<div class="pop-zoom-hide"></div>', "</div>", "</div>"].join("");
                        e("body").append(s), this.bindEvt(), this.isPop = !this.isPop, i.trigger("dys.com.zoom.pop.show")
                    }
                    this.resize()
                }, close: function () {
                    e(".pop-zoom-container").remove(), this.isPop = !this.isPop, i.trigger("dys.com.zoom.pop.close")
                }, bindEvt: function () {
                    var t = this;
                    e(".pop-zoom-close").on("click", function () {
                        t.close()
                    }), e(".pop-zoom-hide").on("click", function () {
                        n.set(t.storageName, t.storageVal, t.storageTime), i.trigger("dys.com.zoom.pop.zoomtip"), t.close()
                    })
                }
            },
            r = function () {
                s.detect() && s.init()
            };
        e(r)
    })

最后提出来

var getScreenScaleNum = function () { 
	var e = 0, i = window.screen; 
	return void 0 !== window.devicePixelRatio ? e = window.devicePixelRatio : ~this.ua.indexOf("msie") ? i.deviceXDPI && i.logicalXDPI && (e = i.deviceXDPI / i.logicalXDPI) : void 0 !== window.outerWidth && void 0 !== window.innerWidth && (e = window.outerWidth / window.innerWidth), e && (e = Math.round(100 * e)), 99 !== e && 101 !== e || (e = 100), e 
}

// getScreenScaleNum() => 100 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用 Python 的 requests 库和斗鱼的 API 实现自动送礼物,无需打开浏览器。具体实现方法可以参考以下代码: ```python import requests # 设置请求头 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} # 登录斗鱼获取 cookie login_url = 'https://www.douyu.com/member/login' login_data = { 'username': 'your_username', 'password': 'your_password', 'client_id': '1', 'nonce': 'your_nonce', 'timestamp': 'your_timestamp', 'sign': 'your_sign' } session = requests.Session() session.post(login_url, headers=headers, data=login_data) # 获取房间信息 room_url = 'https://www.douyu.com/room/roomInfo/get' room_data = { 'roomId': 'your_room_id' } room_info = session.post(room_url, headers=headers, data=room_data).json() # 获取礼物列表 gift_url = 'https://www.douyu.com/gapi/rkc/directory/2_1/' gift_data = { 'rid': 'your_room_id' } gift_list = session.post(gift_url, headers=headers, data=gift_data).json()['data']['list'] # 选择礼物并送礼 gift_id = 'your_gift_id' gift_num = 'your_gift_num' gift_url = 'https://www.douyu.com/japi/roomuserlevel/sendProp' gift_data = { 'propId': gift_id, 'propCount': gift_num, 'roomId': 'your_room_id', 'bizExt': '{"yzxq":{}}' } session.post(gift_url, headers=headers, data=gift_data) ``` 其中,需要替换的参数有: - your_username:斗鱼账号的用户名 - your_password:斗鱼账号的密码 - your_nonce:登录时获取的随机字符串 - your_timestamp:登录时的时间戳 - your_sign:登录时的签名 - your_room_id:要送礼物的房间号 - your_gift_id:要送的礼物的 ID - your_gift_num:要送的礼物数量 另外,获取登录时的随机字符串、时间戳和签名可以使用斗鱼的开放 API,具体方法可以参考斗鱼开放平台的文档。 以上代码仅供参考,具体实现需要根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值