YYPOST群发软件 发表于 2025-1-21 08:46:09

自动化屏幕监控:首次截图与5秒后对比

<div align="left"><font style="color: rgb(51, 51, 51);">判断页面有没有变化的两种方法:</font></div><div align="left"><ignore_js_op></ignore_js_op><font style="color: rgb(51, 51, 51);"><font face="&amp;quot;"><br></font></font></div><div align="left"><ignore_js_op></ignore_js_op><br></div><div class="blockcode" style="overflow: hidden; padding-right: 0px; padding-bottom: 5px; padding-left: 10px; background-image: linear-gradient(90deg, rgb(237, 237, 237), rgb(237, 237, 237)); background-size: 43px; color: rgb(102, 102, 102); zoom: 1;"><div id="code_XAN"><ol style="margin-left: 10px !important;"><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 方法1:这里是多个截图点进行检验<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 方法1:这里是多个截图点进行检验<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img = screen.screenShotFull();&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">img.save('/sdcard/1.jpg');&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 只输出一次RGB值<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var rgb = img.getPointRGB(0.822, 0.6427);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 可选:注释掉不必要的输出<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// console.log(rgb);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// console.log(rgb);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// console.log(rgb);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// console.log(rgb);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 减少等待的时间,比如改为5秒<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">sleep.millisecond(5000);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var imgNext = screen.screenShotFull();&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var rgbb = imgNext.getPointRGB(0.822, 0.6427);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 可选:注释掉不必要的输出<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// console.log(rgbb);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// console.log(rgbb);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// console.log(rgbb);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// console.log(rgbb);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 比较RGB值<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">if (rgb === rgbb &amp;&amp; rgb === rgbb &amp;&amp; rgb === rgbb) {&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; console.log('画面无变化');&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">} else {&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; console.log('画面有变化');&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"></li></ol></div><span style="color: rgb(255, 255, 255); margin-left: 43px; font-size: 12px; cursor: pointer; user-select: none; display: inline-block; margin-top: 8px; padding: 2px 8px; background: rgb(153, 153, 169); border-radius: 4px;">复制代码</span></div><div align="left"><font style="color: rgb(51, 51, 51);">根据比较结果输出信息:</font></div><div align="left"><font style="color: rgb(51, 51, 51);">如果RGB值相同,输出’画面无变化’,表示在这5秒内,该位置的颜色没有发生变化。<br>如果RGB值不同,输出’画面有变化’,表示在这5秒内,该位置的颜色发生了变化。</font></div><div align="left"><font style="color: rgb(51, 51, 51);">这段代码常用于自动化测试、监控屏幕内容变化或者实现某些特定的自动化操作,比如在等待某个界面加载完成时,通过检测特定区域的颜色变化来判断页面是否已经加载完毕。</font></div><br><div class="blockcode" style="overflow: hidden; padding-right: 0px; padding-bottom: 5px; padding-left: 10px; background-image: linear-gradient(90deg, rgb(237, 237, 237), rgb(237, 237, 237)); background-size: 43px; color: rgb(102, 102, 102); zoom: 1;"><div id="code_FeE"><ol style="margin-left: 10px !important;"><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 方法2:这里是多个截图点进行检验&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 定义要检查的坐标列表,,&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var checkPoints = \[&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; {x: 0.8194, y: 0.5254},&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; {x: 0.2847, y: 0.8047}, // 添加更多坐标点&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; // ... 其他坐标&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">\];&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 首次截图并获取各点RGB值&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 定义要检查的坐标列表&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var checkPoints = [&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; {x: 0.8194, y: 0.5254},&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; {x: 0.2847, y: 0.8047} // 添加更多坐标点&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; // ... 其他坐标&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">];&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 首次截图并获取各点RGB值&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var img = screen.screenShotFull();&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var rgbValues = [];&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">for (var point of checkPoints) {&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; var rgb = img.getPointRGB(point.x, point.y);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; rgbValues.push(rgb);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">console.log("首次截图RGB值:", rgbValues);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 等待一段时间后再次截图&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">sleep.millisecond(10000);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var imgNext = screen.screenShotFull();&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">// 比较两次截图的RGB值&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">var isSceneChanged = false;&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">for (var i = 0; i &lt; checkPoints.length; i++) {&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; var newRgb = imgNext.getPointRGB(checkPoints.x, checkPoints.y);&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; if (rgbValues !== newRgb ||&nbsp; &nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;rgbValues !== newRgb ||&nbsp; &nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;rgbValues !== newRgb) {&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;isSceneChanged = true;&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;break; // 发现变化就跳出循环&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; }&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">if (isSceneChanged) {&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; console.log('画面有变化');&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">} else {&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">&nbsp; &nbsp; console.log('画面无变化');&nbsp;&nbsp;<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">}<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"><br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;">//这是另一种方法<br></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; font-family: Monaco, Consolas, &quot;Lucida Console&quot;, &quot;Courier New&quot;, serif; font-size: 12px; line-height: 1.8em;"></li></ol></div><span style="color: rgb(255, 255, 255); margin-left: 43px; font-size: 12px; cursor: pointer; user-select: none; display: inline-block; margin-top: 8px; padding: 2px 8px; background: rgb(153, 153, 169); border-radius: 4px;">复制代码</span></div><div align="left"><font style="color: rgb(51, 51, 51);">主要作用:<br>定义检查点:定义一个包含多个坐标点的数组checkPoints,每个坐标点表示屏幕上的一个相对位置。<br>拍摄首次截图:拍摄屏幕的全屏截图。<br>获取RGB值:遍历checkPoints数组,获取每个检查点的RGB颜色值,并将这些值存储在rgbValues数组中。<br>等待10秒:让脚本暂停10秒,等待屏幕内容可能发生变化。<br>拍摄第二次截图:再次拍摄屏幕的全屏截图。<br>获取新RGB值:遍历checkPoints数组,获取第二次截图中每个检查点的RGB颜色值。<br>比较RGB值:比较两次截图中每个检查点的RGB值是否相同。<br>输出结果:根据比较结果输出’画面有变化’或’画面无变化’。<br>主要特点:<br>多点检测:检查多个特定位置的颜色变化。<br>等待时间较长:等待时间为10秒。<br>更全面的检测:通过多个检查点可以更全面地监控屏幕内容的变化。<br>总结<br>第一段代码:单点检测,等待时间为5秒。<br>第二段代码:多点检测,等待时间为10秒。</font></div><div align="left"><font style="color: rgb(51, 51, 51);">第二段代码由于检查了多个位置,因此能够更全面地检测屏幕内容的变化,而第一段代码则只关注一个特定位置。</font></div><p></p>
页: [1]
查看完整版本: 自动化屏幕监控:首次截图与5秒后对比