Size
14.6 KB
Version
1.1.1
Created
Oct 23, 2025
Updated
about 14 hours ago
1// ==UserScript==
2// @name MineFun.io Game Enhancer
3// @description Enhances MineFun.io gameplay with useful features and tools
4// @version 1.1.1
5// @match https://*.minefun.io/*
6// @icon https://minefun.io/Logo32x32.png
7// ==/UserScript==
8(function() {
9 'use strict';
10
11 console.log('MineFun.io Auto Block Placer loaded');
12
13 // Block types available in MineFun.io
14 const blockTypes = [
15 { name: 'Stone', key: '1', color: '#808080' },
16 { name: 'Dirt', key: '2', color: '#8B4513' },
17 { name: 'Wood', key: '3', color: '#DEB887' },
18 { name: 'Grass', key: '4', color: '#228B22' },
19 { name: 'Sand', key: '5', color: '#F4A460' },
20 { name: 'Glass', key: '6', color: '#87CEEB' },
21 { name: 'Brick', key: '7', color: '#B22222' },
22 { name: 'Gold', key: '8', color: '#FFD700' },
23 { name: 'Diamond', key: '9', color: '#00CED1' }
24 ];
25
26 let selectedBlock = blockTypes[0];
27 let autoPlaceEnabled = false;
28 let placeInterval = null;
29
30 // Create UI Panel
31 function createBlockPlacerPanel() {
32 const panel = document.createElement('div');
33 panel.id = 'block-placer-panel';
34 panel.style.cssText = `
35 position: fixed;
36 top: 10px;
37 right: 10px;
38 background: rgba(20, 20, 20, 0.95);
39 color: #ffffff;
40 padding: 20px;
41 border-radius: 12px;
42 font-family: 'Arial', sans-serif;
43 font-size: 14px;
44 z-index: 10000;
45 min-width: 280px;
46 box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
47 border: 3px solid #4CAF50;
48 `;
49
50 // Title
51 const title = document.createElement('div');
52 title.textContent = '🧱 Block Placer';
53 title.style.cssText = `
54 font-weight: bold;
55 font-size: 18px;
56 margin-bottom: 15px;
57 text-align: center;
58 color: #4CAF50;
59 text-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
60 `;
61 panel.appendChild(title);
62
63 // Block selector
64 const selectorLabel = document.createElement('div');
65 selectorLabel.textContent = 'Select Block Type:';
66 selectorLabel.style.cssText = `
67 margin-bottom: 10px;
68 font-weight: bold;
69 color: #aaa;
70 `;
71 panel.appendChild(selectorLabel);
72
73 const blockGrid = document.createElement('div');
74 blockGrid.style.cssText = `
75 display: grid;
76 grid-template-columns: repeat(3, 1fr);
77 gap: 8px;
78 margin-bottom: 15px;
79 `;
80
81 blockTypes.forEach(block => {
82 const blockBtn = document.createElement('button');
83 blockBtn.textContent = block.name;
84 blockBtn.style.cssText = `
85 padding: 10px;
86 background: ${block.color};
87 color: ${block.name === 'Glass' ? '#000' : '#fff'};
88 border: 2px solid #333;
89 border-radius: 6px;
90 cursor: pointer;
91 font-weight: bold;
92 font-size: 11px;
93 transition: all 0.2s;
94 text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
95 `;
96 blockBtn.onmouseover = () => {
97 blockBtn.style.transform = 'scale(1.05)';
98 blockBtn.style.boxShadow = '0 4px 8px rgba(0,0,0,0.3)';
99 };
100 blockBtn.onmouseout = () => {
101 blockBtn.style.transform = 'scale(1)';
102 blockBtn.style.boxShadow = 'none';
103 };
104 blockBtn.onclick = () => selectBlock(block, blockGrid);
105 blockGrid.appendChild(blockBtn);
106 });
107
108 panel.appendChild(blockGrid);
109
110 // Selected block display
111 const selectedDisplay = document.createElement('div');
112 selectedDisplay.id = 'selected-block-display';
113 selectedDisplay.style.cssText = `
114 padding: 12px;
115 background: rgba(76, 175, 80, 0.2);
116 border: 2px solid #4CAF50;
117 border-radius: 8px;
118 margin-bottom: 15px;
119 text-align: center;
120 font-weight: bold;
121 `;
122 selectedDisplay.innerHTML = `Selected: <span style="color: ${selectedBlock.color}">${selectedBlock.name}</span>`;
123 panel.appendChild(selectedDisplay);
124
125 // Control buttons
126 const controlsDiv = document.createElement('div');
127 controlsDiv.style.cssText = `
128 display: flex;
129 flex-direction: column;
130 gap: 10px;
131 `;
132
133 // Place once button
134 const placeOnceBtn = document.createElement('button');
135 placeOnceBtn.textContent = '🎯 Place Block (P)';
136 placeOnceBtn.style.cssText = `
137 padding: 12px;
138 background: #2196F3;
139 color: white;
140 border: none;
141 border-radius: 8px;
142 cursor: pointer;
143 font-weight: bold;
144 font-size: 14px;
145 transition: all 0.3s;
146 `;
147 placeOnceBtn.onmouseover = () => placeOnceBtn.style.background = '#1976D2';
148 placeOnceBtn.onmouseout = () => placeOnceBtn.style.background = '#2196F3';
149 placeOnceBtn.onclick = () => placeBlockInFront();
150 controlsDiv.appendChild(placeOnceBtn);
151
152 // Auto place toggle
153 const autoPlaceBtn = document.createElement('button');
154 autoPlaceBtn.id = 'auto-place-btn';
155 autoPlaceBtn.textContent = 'âš¡ Auto Place: OFF';
156 autoPlaceBtn.style.cssText = `
157 padding: 12px;
158 background: #666;
159 color: white;
160 border: none;
161 border-radius: 8px;
162 cursor: pointer;
163 font-weight: bold;
164 font-size: 14px;
165 transition: all 0.3s;
166 `;
167 autoPlaceBtn.onclick = () => toggleAutoPlace();
168 controlsDiv.appendChild(autoPlaceBtn);
169
170 // Speed control
171 const speedLabel = document.createElement('div');
172 speedLabel.textContent = 'Placement Speed:';
173 speedLabel.style.cssText = `
174 margin-top: 5px;
175 font-size: 12px;
176 color: #aaa;
177 `;
178 controlsDiv.appendChild(speedLabel);
179
180 const speedSlider = document.createElement('input');
181 speedSlider.type = 'range';
182 speedSlider.id = 'speed-slider';
183 speedSlider.min = '100';
184 speedSlider.max = '2000';
185 speedSlider.value = '500';
186 speedSlider.style.cssText = `
187 width: 100%;
188 cursor: pointer;
189 `;
190 controlsDiv.appendChild(speedSlider);
191
192 const speedValue = document.createElement('div');
193 speedValue.id = 'speed-value';
194 speedValue.textContent = '500ms';
195 speedValue.style.cssText = `
196 text-align: center;
197 font-size: 12px;
198 color: #4CAF50;
199 `;
200 controlsDiv.appendChild(speedValue);
201
202 speedSlider.oninput = () => {
203 speedValue.textContent = speedSlider.value + 'ms';
204 if (autoPlaceEnabled) {
205 toggleAutoPlace();
206 toggleAutoPlace();
207 }
208 };
209
210 panel.appendChild(controlsDiv);
211
212 // Instructions
213 const instructions = document.createElement('div');
214 instructions.style.cssText = `
215 margin-top: 15px;
216 padding: 10px;
217 background: rgba(255, 255, 255, 0.05);
218 border-radius: 6px;
219 font-size: 11px;
220 color: #888;
221 line-height: 1.5;
222 `;
223 instructions.innerHTML = `
224 <strong>Controls:</strong><br>
225 • Press <strong>P</strong> to place block<br>
226 • Press <strong>H</strong> to hide/show panel<br>
227 • Use number keys (1-9) to select blocks<br>
228 • Auto Place for continuous placement
229 `;
230 panel.appendChild(instructions);
231
232 return panel;
233 }
234
235 function selectBlock(block, gridContainer) {
236 selectedBlock = block;
237 const display = document.getElementById('selected-block-display');
238 if (display) {
239 display.innerHTML = `Selected: <span style="color: ${block.color}">${block.name}</span>`;
240 }
241
242 // Update button borders
243 const buttons = gridContainer.querySelectorAll('button');
244 buttons.forEach(btn => {
245 if (btn.textContent === block.name) {
246 btn.style.border = '3px solid #4CAF50';
247 btn.style.boxShadow = '0 0 10px rgba(76, 175, 80, 0.5)';
248 } else {
249 btn.style.border = '2px solid #333';
250 btn.style.boxShadow = 'none';
251 }
252 });
253
254 console.log(`Selected block: ${block.name}`);
255 }
256
257 function placeBlockInFront() {
258 // Simulate right-click to place block
259 const canvas = document.querySelector('canvas');
260 if (!canvas) {
261 console.error('Canvas not found');
262 return;
263 }
264
265 // Get canvas center (where player is looking)
266 const rect = canvas.getBoundingClientRect();
267 const centerX = rect.left + rect.width / 2;
268 const centerY = rect.top + rect.height / 2;
269
270 // Simulate mouse click at center
271 const mouseDownEvent = new MouseEvent('mousedown', {
272 bubbles: true,
273 cancelable: true,
274 view: window,
275 button: 2, // Right click
276 clientX: centerX,
277 clientY: centerY
278 });
279
280 const mouseUpEvent = new MouseEvent('mouseup', {
281 bubbles: true,
282 cancelable: true,
283 view: window,
284 button: 2,
285 clientX: centerX,
286 clientY: centerY
287 });
288
289 const contextMenuEvent = new MouseEvent('contextmenu', {
290 bubbles: true,
291 cancelable: true,
292 view: window,
293 clientX: centerX,
294 clientY: centerY
295 });
296
297 // First select the block type by pressing number key
298 const keyEvent = new KeyboardEvent('keydown', {
299 bubbles: true,
300 cancelable: true,
301 key: selectedBlock.key,
302 code: 'Digit' + selectedBlock.key,
303 keyCode: 48 + parseInt(selectedBlock.key)
304 });
305 document.dispatchEvent(keyEvent);
306
307 // Then place the block
308 setTimeout(() => {
309 canvas.dispatchEvent(mouseDownEvent);
310 setTimeout(() => {
311 canvas.dispatchEvent(mouseUpEvent);
312 canvas.dispatchEvent(contextMenuEvent);
313 }, 50);
314 }, 50);
315
316 console.log(`Placing ${selectedBlock.name} block in front`);
317
318 // Visual feedback
319 showPlacementFeedback();
320 }
321
322 function showPlacementFeedback() {
323 const feedback = document.createElement('div');
324 feedback.textContent = `Placed ${selectedBlock.name}!`;
325 feedback.style.cssText = `
326 position: fixed;
327 top: 50%;
328 left: 50%;
329 transform: translate(-50%, -50%);
330 background: rgba(76, 175, 80, 0.9);
331 color: white;
332 padding: 15px 30px;
333 border-radius: 8px;
334 font-weight: bold;
335 font-size: 16px;
336 z-index: 10001;
337 pointer-events: none;
338 animation: fadeOut 1s forwards;
339 `;
340
341 const style = document.createElement('style');
342 style.textContent = `
343 @keyframes fadeOut {
344 0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
345 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.2); }
346 }
347 `;
348 document.head.appendChild(style);
349
350 document.body.appendChild(feedback);
351 setTimeout(() => feedback.remove(), 1000);
352 }
353
354 function toggleAutoPlace() {
355 autoPlaceEnabled = !autoPlaceEnabled;
356 const btn = document.getElementById('auto-place-btn');
357 const slider = document.getElementById('speed-slider');
358
359 if (autoPlaceEnabled) {
360 btn.textContent = 'âš¡ Auto Place: ON';
361 btn.style.background = '#4CAF50';
362 const speed = parseInt(slider.value);
363 placeInterval = setInterval(() => placeBlockInFront(), speed);
364 console.log('Auto place enabled');
365 } else {
366 btn.textContent = 'âš¡ Auto Place: OFF';
367 btn.style.background = '#666';
368 if (placeInterval) {
369 clearInterval(placeInterval);
370 placeInterval = null;
371 }
372 console.log('Auto place disabled');
373 }
374 }
375
376 // Keyboard shortcuts
377 document.addEventListener('keydown', (e) => {
378 // Toggle panel with 'H' key
379 if (e.key === 'h' || e.key === 'H') {
380 const panel = document.getElementById('block-placer-panel');
381 if (panel) {
382 panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
383 }
384 }
385
386 // Place block with 'P' key
387 if (e.key === 'p' || e.key === 'P') {
388 placeBlockInFront();
389 }
390
391 // Quick select blocks with number keys (when not typing)
392 if (e.key >= '1' && e.key <= '9' && e.target.tagName !== 'INPUT') {
393 const blockIndex = parseInt(e.key) - 1;
394 if (blockIndex < blockTypes.length) {
395 const block = blockTypes[blockIndex];
396 selectBlock(block, document.querySelector('#block-placer-panel > div:nth-child(3)'));
397 }
398 }
399 });
400
401 // Initialize
402 async function init() {
403 console.log('Initializing Block Placer...');
404
405 // Wait for page to be ready
406 if (document.readyState === 'loading') {
407 document.addEventListener('DOMContentLoaded', init);
408 return;
409 }
410
411 // Wait for canvas to be available
412 let attempts = 0;
413 const waitForCanvas = setInterval(() => {
414 const canvas = document.querySelector('canvas');
415 if (canvas || attempts > 20) {
416 clearInterval(waitForCanvas);
417 if (canvas) {
418 // Create and add panel
419 const panel = createBlockPlacerPanel();
420 document.body.appendChild(panel);
421
422 // Select first block by default
423 const gridContainer = panel.querySelector('div:nth-child(3)');
424 selectBlock(blockTypes[0], gridContainer);
425
426 console.log('Block Placer ready! Press P to place blocks, H to toggle panel.');
427 } else {
428 console.error('Canvas not found after waiting');
429 }
430 }
431 attempts++;
432 }, 500);
433 }
434
435 // Start the extension
436 init();
437
438})();