IdleonEfficiency Produce Check

Check and notify on https://www.idleonefficiency.com/ with Telegram support

目前为 2024-04-14 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name IdleonEfficiency Produce Check
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Check and notify on https://www.idleonefficiency.com/ with Telegram support
  6. // @author Tiande
  7. // @match https://www.idleonefficiency.com/*
  8. // @grant GM_notification
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @license MIT
  12. // ==/UserScript==
  13. (function() {
  14. 'use strict';
  15.  
  16. var interval = 10 * 60 * 1000; // check status every 5m
  17. //var interval = 5000 // USE FOR TEST
  18. var refreshInterval = 1.01 * 60 * 60 * 1000; // auto refresh to Dashboard every 10m
  19.  
  20. // Telegram Bot API Token
  21. var tgbotToken = 'YOUR BOT TOKEN';
  22. // Telegram user ID to send the message to
  23. var tguserId = 'YOUR USER ID';
  24.  
  25. // CHECK 1: lable text under player's name
  26. //var whichFull = /(worship is full|production is full|\s[1-5]\sminute)/i; // (is full|being full|can equip sth|missing a trap|maxed) etc.
  27. // CHECK 2: skill to notify
  28. //var skill = /(Refinery|Birthday|taste|printer|cranium cooking)/i; // (Refinery|Arena|Printer Go Brr) etc.
  29. // CHECK 3: bookcount to check
  30. //var bookcount = 20;
  31. // CHECK 4: AFKTime Check
  32. //var AFKHour = 9;
  33. //var AFKMin = 30;
  34. // CHECK 5: banner notify. Must use img src
  35. var bannerRegex = /(ClassIcons57)/i; //img-src
  36. var bannerLabelRegex = /(ready to rank up|plots are fully grown|maximum capacity of chests|Max sprouts capacity|Sprinkler drops has reached it's capacity|Equinox bar is full)/i; //aria-label |squirrel|shovel
  37. // exclude 3d printer circle check
  38. //var excludeKeyword = /(printer|happy)/i;
  39.  
  40. var notificationPermission = GM_getValue('notificationPermission');
  41. var isFunctionEnabled = true;
  42. var intervalId; // Store interval ID for pausing and resuming
  43.  
  44. // tg send
  45. function tgsendMessage(message) {
  46. var tgurl = 'https://api.telegram.org/bot' + tgbotToken + '/sendMessage';
  47. var tgparams = 'chat_id=' + tguserId + '&text=' + encodeURIComponent(message);
  48.  
  49. var tgxhr = new XMLHttpRequest();
  50. tgxhr.open('POST', tgurl, true);
  51. tgxhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  52. tgxhr.onreadystatechange = function() {
  53. if (tgxhr.readyState == 4 && tgxhr.status == 200) {
  54. console.log('Message sent successfully!');
  55. }
  56. };
  57. tgxhr.onerror = function(error) {
  58. console.error('Error sending message:', error);
  59. };
  60. tgxhr.send(tgparams);
  61. }
  62.  
  63. // autorefresh time
  64. var refreshId;
  65. // refreshPage
  66. function refreshPage() {
  67. if (isFunctionEnabled) {
  68. location.href = 'https://www.idleonefficiency.com/'; // 刷新页面到 dashboard
  69. } else {
  70. // 如果不是,则等待下一个刷新时间间隔
  71. refreshId = setInterval(refreshPage, refreshInterval);
  72. }
  73. }
  74.  
  75. function toggleRefresh() {
  76. if (isFunctionEnabled) {
  77. intervalId = setInterval(startInterval, interval); // 启动定时器
  78. refreshId = setInterval(refreshPage, refreshInterval);
  79. } else {
  80. clearInterval(intervalId); // 清除定时器
  81. clearInterval(refreshId);
  82. }
  83. }
  84. toggleRefresh(); // 在脚本启动时调用一次,以确保定时器已启动
  85. // Preload audio
  86. var audio = new Audio();
  87. audio.src = 'https://github.com/Tiande/IdelonCheck/raw/main/iphonewake.wav';
  88.  
  89. // Add CSS styles
  90. var style = document.createElement('style');
  91. style.innerHTML = `
  92. #toggleButtonContainer {
  93. position: fixed;
  94. top: 50%;
  95. left: calc(50% + 100px);
  96. transform: translate(-50%, -50%);
  97. display: flex;
  98. align-items: center;
  99. padding: 5px;
  100. background: green; /* Green color for default enabled state */
  101. color: white;
  102. border-radius: 5px;
  103. font-family: Arial, sans-serif;
  104. font-size: 14px;
  105. box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
  106. z-index: 99999;
  107. user-select: none;
  108. cursor: move;
  109. }
  110. #toggleButtonContainer.off {
  111. background: red; /* Red color for disabled state */
  112. }
  113. #toggleButton {
  114. padding: 5px 10px;
  115. border: none;
  116. border-radius: 5px;
  117. background: transparent;
  118. cursor: pointer;
  119. outline: none;
  120. }
  121. .drag-handle {
  122. cursor: move;
  123. }
  124. #produceCheck {
  125. background-color: black;
  126. color: white;
  127. padding: 5px;
  128. border-radius: 5px;
  129. margin-right: 5px;
  130. }
  131. `;
  132. document.head.appendChild(style);
  133.  
  134. createToggleButton(); // Create toggle button on script execution
  135. startInterval(); // Start interval on script execution
  136. function createToggleButton() {
  137. var toggleButtonContainer = document.createElement('div');
  138. toggleButtonContainer.id = 'toggleButtonContainer';
  139. toggleButtonContainer.classList.add('drag-handle');
  140. var produceCheck = document.createElement('span');
  141. produceCheck.id = 'produceCheck';
  142. produceCheck.textContent = 'Produce Check: ';
  143. toggleButtonContainer.appendChild(produceCheck);
  144. var toggleButton = document.createElement('button');
  145. toggleButton.id = 'toggleButton';
  146. toggleButton.addEventListener('click', toggleFunction);
  147. toggleButtonContainer.appendChild(toggleButton);
  148. document.body.appendChild(toggleButtonContainer);
  149. updateButtonStyle();
  150. makeDraggable(toggleButtonContainer);
  151. }
  152.  
  153. function updateButtonStyle() {
  154. var toggleButtonContainer = document.getElementById('toggleButtonContainer');
  155. toggleButtonContainer.classList.toggle('off', !isFunctionEnabled);
  156. var toggleButton = document.getElementById('toggleButton');
  157. toggleButton.innerHTML = isFunctionEnabled ? 'ON': 'OFF';
  158. }
  159.  
  160. function toggleFunction() {
  161. isFunctionEnabled = !isFunctionEnabled;
  162. updateButtonStyle();
  163. toggleRefresh(); // 根据isFunctionEnabled的值启用或暂停定时器
  164. }
  165.  
  166. function startInterval() {
  167.  
  168. //fully
  169. var images = document.querySelectorAll('div.StyledBox-sc-13pk1d4-0.fHlfiB > img'); // 获取页面上所有的img元素
  170. var matchedImages = Array.from(images).filter(function(image) {
  171. return bannerRegex.test(image.src); // 测试每个图片的src属性是否匹配正则表达式
  172. });
  173.  
  174. // 遍历匹配到正则的img元素并执行相应的操作
  175. if (matchedImages.length > 0) {
  176. var messages = [];
  177. matchedImages.forEach(function(image) {
  178. var src = image.src;
  179. var matchedText = src.match(bannerRegex)[0]; // 获取匹配文本
  180. if (matchedText == 'ClassIcons57'){
  181. matchedText = 'Farming plots is full!'
  182. }
  183. messages.push(matchedText); // 将匹配的文本收集起来
  184. });
  185.  
  186. // 将所有匹配的结果合并成一条消息并显示出来
  187. var message = messages.join(' ');
  188. showNotification(message);
  189. audio.play();
  190. if (tguserId !== 'your user ID') {
  191. tgsendMessage(message);
  192. }
  193. }
  194.  
  195. // 追踪另一组元素 banner salt garden (aria-label)
  196. var timeElements = document.querySelectorAll('.MuiBox-root.css-79elbk');
  197. var trackedContents = [];
  198.  
  199. timeElements.forEach(function(timeElement) {
  200. var ariaLabel = timeElement.getAttribute('aria-label');
  201. var matchResult = bannerLabelRegex.exec(ariaLabel);
  202. if (ariaLabel && matchResult) {
  203. var matchedText = matchResult[0]; // 获取匹配到的具体内容
  204. trackedContents.push(matchedText);
  205. }
  206. });
  207.  
  208. if (trackedContents.length > 0) {
  209. var message = trackedContents.join(', '); // 将数组内容连接成字符串,以逗号分隔
  210. showNotification(message);
  211. audio.play();
  212. if (tguserId !== 'your user ID') {
  213. tgsendMessage(message);
  214. }
  215. }
  216.  
  217. }//All func end
  218.  
  219. function showNotification(message) {
  220. if (notificationPermission === 'granted') {
  221. GM_notification({
  222. text: message,
  223. title: 'Idleonefficiency Notification',
  224. timeout: 5000,
  225. onclick: function() {
  226. window.focus();
  227. }
  228. });
  229. } else {
  230. window.Notification.requestPermission().then(function(permission) {
  231. if (permission === 'granted') {
  232. GM_notification({
  233. text: message,
  234. title: 'Idleonefficiency Notification',
  235. timeout: 5000,
  236. onclick: function() {
  237. window.focus();
  238. }
  239. });
  240. }
  241. });
  242. }
  243. }
  244.  
  245. function makeDraggable(element) {
  246. let pos1 = 0,
  247. pos2 = 0,
  248. pos3 = 0,
  249. pos4 = 0;
  250.  
  251. element.onmousedown = dragMouseDown;
  252.  
  253. function dragMouseDown(e) {
  254. e = e || window.event;
  255. e.preventDefault();
  256. // get the mouse cursor position at startup:
  257. pos3 = e.clientX;
  258. pos4 = e.clientY;
  259. document.onmouseup = closeDragElement;
  260. // call a function whenever the cursor moves:
  261. document.onmousemove = elementDrag;
  262. }
  263.  
  264. function elementDrag(e) {
  265. e = e || window.event;
  266. e.preventDefault();
  267. // calculate the new cursor position:
  268. pos1 = pos3 - e.clientX;
  269. pos2 = pos4 - e.clientY;
  270. pos3 = e.clientX;
  271. pos4 = e.clientY;
  272. // set the element's new position:
  273. element.style.top = (element.offsetTop - pos2) + "px";
  274. element.style.left = (element.offsetLeft - pos1) + "px";
  275. }
  276.  
  277. function closeDragElement() {
  278. /* stop moving when mouse button is released:*/
  279. document.onmouseup = null;
  280. document.onmousemove = null;
  281. }
  282. }
  283.  
  284. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址