From e2810dd215dabc490b6f6c3f254af86fca81a0f8 Mon Sep 17 00:00:00 2001 From: wmillers <31211860+wmillers@users.noreply.github.com> Date: Tue, 6 Jul 2021 22:33:04 +0800 Subject: [PATCH] improve detecting kindle platform --- README.md | 4 ++-- cw.htm | 56 ++++++++++++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 4831df4..e1283e6 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,6 @@ Install `python3` requirements by the command line I write in the comments befor ### 智能家居Hue(Home Smart for Philips-Hue) 适配飞利浦Hue智能家居的开关。Hue中继桥的api带CROS跨域操作头,可以不需要手动代理,但是为了稳定性,此处仍然提供手动代理的步骤:将该代码前注释中的`location /hue/ {..}`代码复制到Nginx配置文件中。如果不需要手动代理,则将网页代码中`hueBaseUrl`变量修改为`//philips-hue/api/`。 -为获取api授权操作码,按下Hue中继桥的配对按钮,在本页运行hReg(),记录返回的凭证,并手动修改页面文件1383行左右的变量`hueToken`为该值。 +为获取api授权操作码,按下Hue中继桥的配对按钮,在本页运行hReg(),记录返回的凭证,并手动修改页面文件`Basic Settings`中变量`hueToken`为该值。 Smart home switch for Philips-Hue products. Response Header returned from Hue bridge api contains allow CROS *, therefore it's optional to proxy the request. Here are the setups if you want it more reliable: copy the `location /hue/ {..}` code to your Nginx config. If you want to disable the proxy, edit the content of the `hueBaseUrl` variable in the page source code file to `//philips-hue/api/`. -To get Hue api token: 1.Press the Hue Link button 2. Run hReg() 3. Change the content of the `hueToken` variable in the page source code file's Line1383~. +To get Hue api token: 1.Press the Hue Link button 2. Run hReg() 3. Change the content of the `hueToken` variable in the page source code file's `Basic Settings`. diff --git a/cw.htm b/cw.htm index af50003..40cb314 100644 --- a/cw.htm +++ b/cw.htm @@ -27,15 +27,19 @@ ], license: 'LGPL2.1' } -var autostart=[//COMMENT unwanted auto-start modules +var isOnKindle=!/windows|chrome/i.test(navigator.userAgent);//most affect autostart +var autostart=isOnKindle?[//COMMENT unwanted auto-start modules 'ticklist', //'danmu', - 'home']; + 'home'] + :[]; var isDanmuFullWindow=true;//true if danmu start in fullwindow mode (fullscreen mode activated by danmuOnly()) var danmuFontSizeFullScreen="5.7vh";//only takes effect under fullscreen (not fullwindow) mode var hueBaseUrl = '/hue/';//'//philips-hue/api/' if no need CROS Access-Control-Allow-Origin * -var hueToken = "UDp1xs0RpZiOho4oX7PY-L7fpAOe8pYnOMTK1tfo";//replace with your own's token -//******************************************** +var hueToken = "UDp1xs0RpZiOho4oX7PY-L7fpAOe8pYnOMTK1tfo";//replace with your token, to get: push bridge button and run hReg() +//*******************END********************** + +if (!isOnKindle) console.log('Autostart only enabled on Kindle'); window.onerror=function handler(msg, source, line, col, e){comment((line?'['+line+']':'')+(e?e.stack:msg));}; setTimeout(function isLoaded(){ if (typeof loaded=="undefined"){ @@ -247,7 +251,6 @@ var initialTitle = document.title; var clearCommentTime = 0; var basket = document.getElementsByClassName('basket')[0]; -var isWindows=navigator.userAgent.indexOf('Windows') != -1; function comment(s, isJam) { var lag = 30 * 60 * 1000; s = s == undefined ? 'und' : String(s); @@ -303,11 +306,8 @@ } else { setTimeout(function autoStart(){ if (!forTestUse) - if (isWindows) - comment('Autostart disabled in Windows'); - else - for (var i = 0; i < autostart.length; i++) - [showIcs, danmuSwitch, hUpdate][['ticklist', 'danmu', 'home'].indexOf(autostart[i])](); + for (var i = 0; i < autostart.length; i++) + [showIcs, danmuSwitch, hUpdate][['ticklist', 'danmu', 'home'].indexOf(autostart[i])](); }); } setTimeout(function loadFromHash(){ @@ -792,7 +792,7 @@ document.getElementById('net').innerHTML = '无网络连接'; var date = getOffsetDate(); lastSyncTime = date.getTime(); - if (!forTestUse && !isWindows){ + if (!forTestUse && isOnKindle){ var ifrm = document.getElementsByClassName('weath')[0]; ifrm.src = "//i.tianqi.com/index.php?c=code&id=2&bdc=%23&icon=5&num=3&site=15";//change iframe document.getElementById('net').innerHTML = '完成上一次同步'; @@ -1427,8 +1427,8 @@ danmuStart = getOffsetTime(); danmuTryToken = 0; danmuPop = 0; - streamer[2] = []; - streamer[3] = []; + streamer[2] = space(streamer[0].length-1).split(' '); + streamer[3] = streamer[2].slice(); danmuTaskIndexs = [0, 0, 0]; danmuStyle.opacity = 1; roomId = String(roomId); @@ -1457,11 +1457,11 @@ clearTimeout(danmuTaskIndexs[1]); clearTimeout(danmuTaskIndexs[2]); clearTimeout(danmuTaskIndexs[3]); - setTimeout('if (danmuPop==1) danmuClear()', 10 * 60 * 1000); + setTimeout(danmuClear, 10 * 60 * 1000); danmuAlter(true); danmu.innerHTML = '[OFF@'+ dateString() +'] ' + (s != undefined ? s + ' ' : '') + 'run' + timeFormat(getOffsetTime() - danmuStart, 2, true) + '
' + (danmu.innerHTML).slice(0, danmuMax / 5) + '...'; - danmuInfo(); danmuPop = 0; + danmuInfo(); } function danmuTitle(s, end, i){//s == string (when end == undefined) OR start if (i==undefined) @@ -1504,7 +1504,7 @@ } } function setDanmuPop(p) { - if (p != danmuPop && !(danmuPop == 0 && p == 1 && getOffsetTime() - danmuStart < 2 * 60 * 1000) || (danmuPop == 9999 && p != 1)) { + if (isDanmuLive && p != danmuPop && !(danmuPop == 0 && p == 1 && getOffsetTime() - danmuStart < 2 * 60 * 1000) || (danmuPop == 9999 && p != 1)) { var old = danmuPop; danmuPopTrends = p < danmuPop ? -1 : (p == danmuPop ? 0 : 1); danmuPop = p; @@ -1641,11 +1641,12 @@ } } function danmuInfo() { - var status = ['OFF', streamer[2][streamer[1].indexOf(danmuRoomId)] ? streamer[2][streamer[1].indexOf(danmuRoomId)] : 'oи' + (danmuPop == 9999 ? '☕' : ''), 'ᗯατcᏥ'][isDanmuLive]; + var status = ['OFF', streamer[2][streamer[1].indexOf(danmuRoomId)] ? streamer[2][streamer[1].indexOf(danmuRoomId)] : 'oи' + (danmuPop == 9999 ? '☕' : ''), 'ᗯατcᏥ'][isDanmuLive];//watch is not used now var liveStatus=''; - for (var i=0;i 3) status = ' ⁉' + danmuTryToken; - document.getElementsByClassName('danmu_info')[0].innerHTML = atag((isDanmuLive == 2 || !streamer[2].join('') ? '人气' : '' + streamer[2].reduce(function a(s, n) {return s + (n ? '•' : '◦')}, '') + ' ') + dTrends, false, 'danmuFullScreen()', '全屏 FullScreen') + ''+atag(danmuTitle(), 'https://live.bilibili.com/blanc/'+danmuRoomId) + '' + atag(status, false, "f5('', '#danmuOnly()')", '刷新 Refresh') + '
' + danmuSuperChat + '' +liveStatus + ''; + document.getElementsByClassName('danmu_info')[0].innerHTML = atag((isDanmuLive == 2 || !streamer[2].join('') ? '人气' : '' + streamer[2].reduce(function a(s, n) {return s + (n ? '•' : '◦')}, '') + ' ') + dTrends, false, 'danmuFullScreen()', '全屏 FullScreen') + ''+atag(danmuTitle(), 'https://live.bilibili.com/blanc/'+danmuRoomId) + '' + atag(status, false, "f5('', '#danmuOnly()')", '刷新 Refresh') + '
' + danmuSuperChat + (liveStatus?'' +liveStatus + ''+ ' '+dateString():''); function atag(inner, href, onclick, title){ return '' + inner + ''; @@ -1682,7 +1683,7 @@ n=(n+1)%streamer[1].length; danmuTaskIndexs[3] = setTimeout(function getRealId(){ danmuRead("cros:https://api.live.bilibili.com/room/v1/Room/room_init?id=" + streamer[1][n], function count(s){danmuParseStreamer(s, n);}); - }, danmuTryToken >= 3 || danmuPop==1 ? 600e3 : (streamer[3][n]? 300e3 : 60e3)); + }, danmuTryToken >= 3 || danmuPop==1 ? 600e3 : (streamer[3].indexOf('')==-1? 300e3 : 60e3)); var stat = JSON.parse(s); danmuRead("cros:https://api.bilibili.com/x/space/acc/info?mid=" + stat.data.uid, function a(s) { var stat = JSON.parse(s); @@ -1723,9 +1724,10 @@ } } function danmuClear() { - if (isDanmuLive) return; - danmuStyle.opacity = 0; - document.getElementsByClassName('danmu_info')[0].innerHTML = ''; + if (!isDanmuLive){ + danmuStyle.opacity = 0; + document.getElementsByClassName('danmu_info')[0].innerHTML = ''; + } } @@ -1758,7 +1760,7 @@ var hPreventNetworkError=(hueBaseUrl=='/hue/')?false:true; function hHelp() { hFail('1. Press the Hue Link button 2. Run hReg() 3. Change the hueToken in this page file'); - alert('hueToken around line:1313 is empty'); + alert('hueToken in *Basic Settings* is invalid'); } function hCollect(f) { if (!hueToken) { @@ -1848,7 +1850,7 @@ + (switchs[i].on ? "" : "color: black;") + "text-shadow: 4px 4px 0 "+sdcolor+", -4px -4px 0 "+sdcolor+", -4px 4px 0 "+sdcolor+", 4px -4px 0 "+sdcolor; } - if (isWindows) + if (!isOnKindle) home.innerHTML += "
Star
"; } }