Automatically votes for bots on top.gg by handling ad timers and clicking vote buttons
Size
6.3 KB
Version
1.0.1
Created
Nov 21, 2025
Updated
22 days ago
1// ==UserScript==
2// @name Top.gg Auto Voter
3// @description Automatically votes for bots on top.gg by handling ad timers and clicking vote buttons
4// @version 1.0.1
5// @match https://*.top.gg/*
6// @icon https://top.gg/favicon.png
7// @grant GM.getValue
8// @grant GM.setValue
9// @grant GM.notification
10// ==/UserScript==
11(function() {
12 'use strict';
13
14 console.log('Top.gg Auto Voter initialized');
15
16 // Debounce function to prevent excessive calls
17 function debounce(func, wait) {
18 let timeout;
19 return function executedFunction(...args) {
20 const later = () => {
21 clearTimeout(timeout);
22 func(...args);
23 };
24 clearTimeout(timeout);
25 timeout = setTimeout(later, wait);
26 };
27 }
28
29 // Check if we're on a voting page
30 function isVotingPage() {
31 return window.location.pathname.includes('/vote');
32 }
33
34 // Wait for ad timer and handle countdown
35 async function handleAdTimer() {
36 console.log('Checking for ad timer...');
37
38 // Look for the countdown button
39 const timerButton = document.querySelector('button.chakra-button.css-7rul47');
40
41 if (timerButton) {
42 const timeLeft = parseInt(timerButton.textContent);
43 console.log(`Ad timer found: ${timeLeft} seconds remaining`);
44
45 if (timeLeft > 0) {
46 console.log(`Waiting ${timeLeft} seconds for ad timer to complete...`);
47 // Wait for the timer to complete plus a small buffer
48 await new Promise(resolve => setTimeout(resolve, (timeLeft + 2) * 1000));
49 console.log('Ad timer should be complete, checking for vote button...');
50 return true;
51 }
52 }
53
54 return false;
55 }
56
57 // Find and click the vote button
58 async function clickVoteButton() {
59 console.log('Looking for vote button...');
60
61 // Wait a bit for the page to update after timer
62 await new Promise(resolve => setTimeout(resolve, 1000));
63
64 // Common selectors for vote buttons on top.gg
65 const voteButtonSelectors = [
66 'button[type="button"]:not(.chakra-button)',
67 'button:has-text("Vote")',
68 'button[class*="vote"]',
69 'a[href*="vote"]',
70 'button.css-7rul47:not(:has-text("10"))',
71 'div[class*="vote"] button'
72 ];
73
74 for (const selector of voteButtonSelectors) {
75 try {
76 const buttons = document.querySelectorAll('button[type="button"]');
77 for (const button of buttons) {
78 const buttonText = button.textContent.toLowerCase();
79 if (buttonText.includes('vote') && !buttonText.match(/\d+/)) {
80 console.log('Found vote button:', button);
81 button.click();
82 console.log('Vote button clicked!');
83
84 // Save vote timestamp
85 const botId = window.location.pathname.split('/')[2];
86 await GM.setValue(`lastVote_${botId}`, Date.now());
87
88 // Show notification
89 GM.notification({
90 text: 'Successfully voted for this bot!',
91 title: 'Top.gg Auto Voter',
92 timeout: 3000
93 });
94
95 return true;
96 }
97 }
98 } catch (e) {
99 console.log('Error checking selector:', e);
100 }
101 }
102
103 console.log('Vote button not found yet');
104 return false;
105 }
106
107 // Main automation function
108 async function automateVoting() {
109 if (!isVotingPage()) {
110 console.log('Not on a voting page, skipping automation');
111 return;
112 }
113
114 console.log('Starting voting automation...');
115
116 // Check if we already voted recently
117 const botId = window.location.pathname.split('/')[2];
118 const lastVoteTime = await GM.getValue(`lastVote_${botId}`, 0);
119 const timeSinceLastVote = Date.now() - lastVoteTime;
120 const twelveHours = 12 * 60 * 60 * 1000;
121
122 if (timeSinceLastVote < twelveHours) {
123 const hoursLeft = Math.ceil((twelveHours - timeSinceLastVote) / (60 * 60 * 1000));
124 console.log(`Already voted recently. Can vote again in ${hoursLeft} hours`);
125
126 GM.notification({
127 text: `You can vote again in ${hoursLeft} hours`,
128 title: 'Top.gg Auto Voter',
129 timeout: 5000
130 });
131 return;
132 }
133
134 // Handle ad timer if present
135 const hadTimer = await handleAdTimer();
136
137 // Try to click vote button
138 const voted = await clickVoteButton();
139
140 if (!voted) {
141 console.log('Could not complete voting automatically. Retrying in 3 seconds...');
142 setTimeout(automateVoting, 3000);
143 }
144 }
145
146 // Observer to watch for page changes
147 function setupObserver() {
148 const observer = new MutationObserver(debounce(() => {
149 if (isVotingPage()) {
150 automateVoting();
151 }
152 }, 1000));
153
154 observer.observe(document.body, {
155 childList: true,
156 subtree: true
157 });
158
159 console.log('DOM observer set up');
160 }
161
162 // Initialize the extension
163 async function init() {
164 console.log('Initializing Top.gg Auto Voter...');
165
166 // Wait for page to be fully loaded
167 if (document.readyState === 'loading') {
168 document.addEventListener('DOMContentLoaded', init);
169 return;
170 }
171
172 // Wait a bit for dynamic content to load
173 await new Promise(resolve => setTimeout(resolve, 2000));
174
175 // Set up observer for dynamic changes
176 setupObserver();
177
178 // Start automation if on voting page
179 if (isVotingPage()) {
180 automateVoting();
181 }
182
183 console.log('Top.gg Auto Voter ready!');
184 }
185
186 // Start the extension
187 init();
188})();