| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  | class WindowsJs { | 
					
						
							|  |  |  |   /// 点击监听
 | 
					
						
							|  |  |  |   static String clickEventJs = '''
 | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  | document.addEventListener("click", function (event) { | 
					
						
							|  |  |  |   var x = event.clientX; | 
					
						
							|  |  |  |   var y = event.clientY; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |   var click = { "x": x, "y": y }; | 
					
						
							|  |  |  |   var value = { click: click }; | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // 发送消息
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |   window.chrome.webview.postMessage(value); | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |   // window.chrome.webview.postMessage({"text":event.target.textContent,"end":event.target.textContent === "进入游戏"});
 | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // 检查点击的元素是否有类名为 'btn'
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |   if (event.target.textContent === "进入游戏") { | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  |     // 获取按钮上显示的文本内容
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |     window.chrome.webview.postMessage({ "成功获取到btn": 1 }); | 
					
						
							|  |  |  |     // window.chrome.webview.postMessage({ "btn": event.target.textContent });
 | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |     // 阻止默认的链接跳转行为
 | 
					
						
							|  |  |  |     event.preventDefault(); | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |     var oldUrl = window.location.href; | 
					
						
							|  |  |  |     var classUrl = event.target.href; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     var str = oldUrl; | 
					
						
							|  |  |  |     var startIndex = str.indexOf('www.'); | 
					
						
							|  |  |  |     var endIndex = str.indexOf('/', startIndex); | 
					
						
							|  |  |  |     var url = str.substring(startIndex, endIndex); | 
					
						
							|  |  |  |     var newUrl = "https://" + url + "/game/"; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |     // window.chrome.webview.postMessage({"元素地址": classUrl ,"旧地址":window.location.href ,"截取":url,"新地址": newUrl});
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |     window.location.href = newUrl; | 
					
						
							|  |  |  |        | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  | }); | 
					
						
							|  |  |  |   ''';
 | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 10:37:41 +08:00
										 |  |  |   /// 滚动监听
 | 
					
						
							|  |  |  |   static String scrollEventJs = '''
 | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |   // window.onscroll = function() {
 | 
					
						
							|  |  |  |   //    // 获取垂直滚动位置
 | 
					
						
							|  |  |  |   //    var scrollTop = window.scrollY;
 | 
					
						
							|  |  |  |   //    window.chrome.webview.postMessage({"scroll": 1 ,"y": scrollTop });
 | 
					
						
							|  |  |  |   // };
 | 
					
						
							|  |  |  |   // 轮询检查元素是否存在
 | 
					
						
							|  |  |  |   // const checkExist = setInterval(function() {
 | 
					
						
							|  |  |  |   //   const contentWrap = document.querySelector('content');
 | 
					
						
							|  |  |  |   //   const clList = document.querySelector('cl-list');
 | 
					
						
							|  |  |  |   //   console.log('轮询');
 | 
					
						
							|  |  |  |   //   if (contentWrap && clList) {
 | 
					
						
							|  |  |  |   //     clearInterval(checkExist); // 停止轮询
 | 
					
						
							|  |  |  |   //     console.log('停止轮询');
 | 
					
						
							|  |  |  |   //     contentWrap.addEventListener('scroll', function() {
 | 
					
						
							|  |  |  |   //       console.log('contentWrap position:', element.scrollTop);
 | 
					
						
							|  |  |  |   //     });
 | 
					
						
							|  |  |  |   //     clList.addEventListener('scroll', function() {
 | 
					
						
							|  |  |  |   //       console.log('clList position:', element.scrollTop);
 | 
					
						
							|  |  |  |   //     });
 | 
					
						
							|  |  |  |   //   }
 | 
					
						
							|  |  |  |   // }, 500); // 每500毫秒检查一次
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 10:37:41 +08:00
										 |  |  |   ''';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// 滚动到
 | 
					
						
							|  |  |  |   static String scrollTo(int value){ | 
					
						
							|  |  |  |     return '''
 | 
					
						
							|  |  |  |     window.scrollTo({ | 
					
						
							|  |  |  |     top: $value, | 
					
						
							|  |  |  |     behavior: 'smooth'  // 可选,设置滚动行为为平滑滚动
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     ''';
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  |   /// 模拟点击
 | 
					
						
							| 
									
										
										
										
											2024-04-03 18:27:31 +08:00
										 |  |  |   static String clickJs(int x, int y) { | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  |     return 'document.elementFromPoint($x, $y).click();'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// 输入
 | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  |   static String inputJs(int value) { | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  |     return '''
 | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |       console.log('输入赋值'); | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  |       var inputEvent = new Event('input', { | 
					
						
							|  |  |  |         bubbles: true, | 
					
						
							|  |  |  |         cancelable: true, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  |       var inputElement = document.querySelector(".bet-money"); | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  |       inputElement.value = "$value"; | 
					
						
							|  |  |  |       inputElement.dispatchEvent(inputEvent); | 
					
						
							| 
									
										
										
										
											2024-04-03 12:54:07 +08:00
										 |  |  |        | 
					
						
							|  |  |  |       // var inputElements = document.querySelectorAll(".bet-money");
 | 
					
						
							|  |  |  |       // inputElements.forEach(function(element) {
 | 
					
						
							|  |  |  |       //   var inputEvent = new Event('input', {
 | 
					
						
							|  |  |  |       //     bubbles: true,
 | 
					
						
							|  |  |  |       //     cancelable: true,
 | 
					
						
							|  |  |  |       //   });
 | 
					
						
							|  |  |  |       //   element.value = "$value";
 | 
					
						
							|  |  |  |       //   element.dispatchEvent(inputEvent);
 | 
					
						
							|  |  |  |       // });
 | 
					
						
							|  |  |  |       // const contentWrap = document.querySelector('content');
 | 
					
						
							|  |  |  |       // const clList = document.querySelector('cl-list');
 | 
					
						
							|  |  |  |       // console.log(contentWrap, clList);
 | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  |     ''';
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// 监听加载,在加载完成后缩放
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |   static String onloadZoom(int zoom){ | 
					
						
							|  |  |  |     assert(zoom >= 1 && zoom <= 100, 'zoom 1 到 100'); | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  |     return '''
 | 
					
						
							|  |  |  | window.onload = function () { | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |   var currentUrl = window.location.href; | 
					
						
							|  |  |  |   if (currentUrl.endsWith('game/')) { | 
					
						
							|  |  |  |      ${WindowsJs.zoom(zoom)} | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | ''';
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// 修改缩放
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |   static String zoom(int zoom){ | 
					
						
							|  |  |  |     assert(zoom >= 1 && zoom <= 100, 'zoom 1 到 100'); | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  |     return '''
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |       document.body.style.zoom = "$zoom%"; | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  |     ''';
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-02 20:29:52 +08:00
										 |  |  |   static String message = 'window.chrome.webview.postMessage({x:3333});'; | 
					
						
							| 
									
										
										
										
											2024-04-02 11:02:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 21:41:42 +08:00
										 |  |  | } |