Clicks tree every 30 minutes, reloads every 10 minutes, and returns to home automatically after click.
当前为
// ==UserScript==
// @name Knolix Auto Tree Clicker (fixed)
// @namespace http://tampermonkey.net/
// @version 1.6
// @description Clicks tree every 30 minutes, reloads every 10 minutes, and returns to home automatically after click.
// @author Rubystance
// @license MIT
// @match https://knolix.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
const CLICK_INTERVAL_MINUTES = 30;
const RELOAD_INTERVAL_MINUTES = 10;
const CLICK_DELAY_MS = 5000;
const HOME_DELAY_MS = 2000;
const STORAGE_KEY = 'knolix_last_click';
function getLastClickTime() {
return parseInt(localStorage.getItem(STORAGE_KEY) || '0', 10);
}
function updateLastClickTime() {
localStorage.setItem(STORAGE_KEY, Date.now().toString());
}
function isTreeFull() {
for (let i = 0; i < 60; i++) {
const el = document.getElementById('bitcoin' + i);
if (!el || el.offsetWidth === 0 || el.offsetHeight === 0) {
return false;
}
}
return true;
}
function tryClickTreeIfTime() {
const now = Date.now();
const lastClick = getLastClickTime();
const minutesSinceLastClick = (now - lastClick) / 60000;
if (minutesSinceLastClick < CLICK_INTERVAL_MINUTES) {
console.log(`[Knolix Auto] Only ${minutesSinceLastClick.toFixed(1)}min since last click. Waiting...`);
return;
}
const tree = document.getElementById('btctree');
if (!tree) {
console.log('[Knolix Auto] Tree element not found.');
return;
}
const style = window.getComputedStyle(tree);
const isVisible = style.display !== 'none' && style.visibility !== 'hidden' && tree.offsetParent !== null;
if (!isVisible || !isTreeFull()) {
console.log('[Knolix Auto] Tree not visible or not full.');
return;
}
console.log('[Knolix Auto] Tree is ready! Waiting 5s before clicking...');
setTimeout(() => {
try {
tree.click();
updateLastClickTime();
console.log('[Knolix Auto] Tree clicked successfully!');
setTimeout(tryClickHome, HOME_DELAY_MS);
} catch (e) {
console.error('[Knolix Auto] Failed to click tree:', e);
}
}, CLICK_DELAY_MS);
}
function tryClickHome() {
const homeBtn = document.querySelector('a.navlink.w-nav-link[href="/"]');
if (homeBtn) {
try {
homeBtn.click();
console.log('[Knolix Auto] Home button clicked!');
} catch (e) {
console.error('[Knolix Auto] Failed to click Home:', e);
}
} else {
console.log('[Knolix Auto] Home button not found.');
}
}
setTimeout(() => {
console.log('[Knolix Auto] Reloading page after 10 minutes...');
location.reload();
}, RELOAD_INTERVAL_MINUTES * 60 * 1000);
window.addEventListener('load', () => {
tryClickTreeIfTime();
});
})();