// ==UserScript== // @name Diep.io Auto Tank Builder/Upgrader - Enhance Your Diep.io Gameplay Experience! // @version 1.6 // @description Streamline your Diep.io gameplay with the ultimate auto tank builder and upgrader, empowering you with optimized builds for strategic dominance. // @author Its_Arslan // @match *://diep.io/* // @grant none // @namespace https://greasyfork.org/users/970291 // @license CC BY-NC-ND // @downloadURL https://update.greasyfork.icu/scripts/452994/Diepio%20Auto%20Tank%20BuilderUpgrader%20-%20Enhance%20Your%20Diepio%20Gameplay%20Experience%21.user.js // @updateURL https://update.greasyfork.icu/scripts/452994/Diepio%20Auto%20Tank%20BuilderUpgrader%20-%20Enhance%20Your%20Diepio%20Gameplay%20Experience%21.meta.js // ==/UserScript== (function () { "use strict"; var textG = document.createElement("div"); document.getElementsByTagName("body")[0].appendChild(textG); textG.innerHTML = ` `; var defaultJson = { builds: [{ id: "01", name: "Stable", code: "765421765421765421765421765421765" }, { id: "02", name: "Bullet Storm", code: "212127654765476547654765476547652" }, { id: "03", name: "Glass Cannon", code: "567567485675674856748567456744488" }, { id: "04", name: "Rammer", code: "111888232323232323231181188867676" }, { id: "05", name: "Null", code: "000000000000000000000000000000000" }, { id: "06", name: "Null", code: "000000000000000000000000000000000" }, { id: "07", name: "Null", code: "000000000000000000000000000000000" } ] }; var jsonData = loadJson(); function loadJson() { var jsonData = localStorage.getItem('builds'); if (!jsonData) { localStorage.setItem('builds', JSON.stringify(defaultJson)); jsonData = localStorage.getItem('builds'); } return JSON.parse(jsonData); } var notificationQueue = []; function notification(message, type) { var notificationDiv = document.getElementById("notificationDiv"); var notification = document.createElement('h3'); notification.textContent = message; notification.style.transform = "scale(0.8)"; notification.style.opacity = "0"; var oldNotification = document.querySelector(".notificationCurrent"); if (oldNotification) { oldNotification.classList.remove("notificationCurrent"); } switch (type) { case "print": notification.classList.add("notificationCurrent", "printNotification"); break; case "warn": notification.classList.add("notificationCurrent", "warnNotification"); break; case "error": notification.classList.add("notificationCurrent", "errorNotification"); break; } notificationDiv.appendChild(notification); setTimeout(function() { notification.style.transition = "transform 0.5s ease, opacity 0.5s ease"; notification.style.transform = "scale(1)"; notification.style.opacity = "1"; }, 0); setTimeout(function() { notification.style.transition = "transform 0.8s ease, opacity 0.8s ease"; notification.style.transform = "scale(0.0)"; notification.style.opacity = "0"; setTimeout(function() { notificationDiv.removeChild(notification); }, 500); }, 2500); } function buildsConfigDropdown(build, buildButtonsDiv, buildsConfigDiv, buildConfigButton) { document.querySelector('.addBuildInputDiv').style.display = "none"; document.querySelector('.addBuildActionDiv').style.display = "none"; document.querySelector('.addBuildBtn').style.display = "flex"; var existingDropdown = buildConfigButton.nextElementSibling; if (existingDropdown && existingDropdown.classList.contains('buildDropdownDiv')) { existingDropdown.remove(); return; } var buildInputs = document.getElementsByClassName('input'); buildInputs.value = ''; document.querySelectorAll('.buildDropdownDiv').forEach(function(element) { element.remove(); }); var buildDropdownDiv = document.createElement('div'); buildDropdownDiv.className = 'buildDropdownDiv'; var editBtn = document.createElement('button'); editBtn.className = 'editBtn'; editBtn.textContent = 'Edit'; var deleteBtn = document.createElement('button'); deleteBtn.className = 'deleteBtn'; deleteBtn.textContent = 'Delete'; buildDropdownDiv.appendChild(editBtn); buildDropdownDiv.appendChild(deleteBtn); buildConfigButton.parentNode.insertBefore(buildDropdownDiv, buildConfigButton.nextSibling); editBtn.addEventListener('click', function() { notification('Edit feature is coming soon.', 'print'); }); deleteBtn.addEventListener('click', function() { var nullBuild = { id: build.id, name: 'Null', code: '000000000000000000000000000000000' }; var buildIndex = jsonData.builds.findIndex(function(item) { return item.id === build.id; }); notification(build.name + ' has been deleted successfully.', 'print'); if (buildIndex !== -1) { jsonData.builds[buildIndex] = nullBuild; localStorage.setItem('builds', JSON.stringify(jsonData)); document.querySelectorAll('.buildDropdownDiv').forEach(function(element) { element.remove(); }); document.querySelector(".buildButtonsDiv [id='" + build.id + "']").remove(); buildConfigButton.remove(); } }); }; function addHtml() { var jsonData = loadJson(); if (!jsonData || !jsonData.builds) { jsonData = defaultJson; } var mainMenuDiv = document.createElement('div'); mainMenuDiv.className = 'mainMenuDiv'; mainMenuDiv.id = 'mainMenuDiv'; var settingMenuDiv = document.createElement('div'); settingMenuDiv.className = 'settingMenuDiv'; settingMenuDiv.id = 'settingMenuDiv'; var notificationDiv = document.createElement('div'); notificationDiv.className = 'notificationDiv'; notificationDiv.id = 'notificationDiv'; var infoDiv = document.createElement('div'); infoDiv.className = 'infoDiv'; mainMenuDiv.appendChild(infoDiv); var buildButtonsDiv = document.createElement('div'); buildButtonsDiv.className = 'buildButtonsDiv'; mainMenuDiv.appendChild(buildButtonsDiv); var controlButtonsDiv = document.createElement('div'); controlButtonsDiv.className = 'controlButtonsDiv'; mainMenuDiv.appendChild(controlButtonsDiv); var buildsConfigDiv = document.createElement('div'); buildsConfigDiv.className = 'buildsConfigDiv'; settingMenuDiv.appendChild(buildsConfigDiv); var addBuildDiv = document.createElement('div'); addBuildDiv.className = 'addBuildDiv'; settingMenuDiv.appendChild(addBuildDiv); var nameBtn = document.createElement('button'); nameBtn.className = 'nameBtn'; nameBtn.textContent = 'Its_Arslan'; infoDiv.appendChild(nameBtn); var hideBtn = document.createElement('button'); hideBtn.className = 'hideBtn'; hideBtn.textContent = 'Press T To Hide'; infoDiv.appendChild(hideBtn); var websiteBtn = document.createElement('button'); websiteBtn.className = 'websiteBtn'; websiteBtn.textContent = 'Website'; infoDiv.appendChild(websiteBtn); nameBtn.addEventListener("click", function() { var link = "https://greasyfork.org/en/users/970291"; window.open(link, "_blank"); }); hideBtn.addEventListener("click", function() { mainMenuDiv.style.display = "none"; settingMenuDiv.style.display = "none"; }); websiteBtn.addEventListener("click", function() { var link = "https://site--arslanbehleem.repl.co/"; window.open(link, "_blank"); }); jsonData.builds.forEach(function(build) { if (build.name !== 'Null') { var buildButton = document.createElement('button'); buildButton.id = build.id; buildButton.className = 'buildButton'; buildButton.textContent = build.name; buildButton.setAttribute('onclick', "input.execute('game_stats_build " + build.code + "')"); buildButtonsDiv.appendChild(buildButton); buildButton.addEventListener('click', function() { notification(build.name + ' has been activated.', "print"); }); var buildConfigButton = document.createElement('button'); buildConfigButton.id = build.id; buildConfigButton.className = 'buildConfigButton'; buildConfigButton.textContent = build.name; buildsConfigDiv.appendChild(buildConfigButton); buildConfigButton.addEventListener('click', function() { buildsConfigDropdown(build, buildButtonsDiv, buildsConfigDiv, buildConfigButton); }); } }); var addBuildBtn = document.createElement('button'); addBuildBtn.className = 'addBuildBtn'; addBuildBtn.textContent = 'Add Build'; addBuildDiv.appendChild(addBuildBtn); var addBuildInputDiv = document.createElement('div'); addBuildInputDiv.className = 'addBuildInputDiv'; addBuildDiv.appendChild(addBuildInputDiv); var addBuildActionDiv = document.createElement('div'); addBuildActionDiv.className = 'addBuildActionDiv'; addBuildDiv.appendChild(addBuildActionDiv); addBuildBtn.addEventListener('click', function() { if (buildsConfigDiv) { var existingDropdowns = buildsConfigDiv.querySelectorAll('.buildDropdownDiv'); for (var i = 0; i < existingDropdowns.length; i++) { existingDropdowns[i].remove(); } } addBuildBtn.style.display = "none"; addBuildInputDiv.style.display = "flex"; addBuildActionDiv.style.display = "flex"; }); var buildNameInput = document.createElement('input'); buildNameInput.type = 'text'; buildNameInput.className = 'input'; buildNameInput.placeholder = 'Enter Build Name'; addBuildInputDiv.appendChild(buildNameInput); buildNameInput.addEventListener('keydown', function(event) { event.stopPropagation(); if ( event.key === 'Backspace' || (event.ctrlKey && event.key === 'c') || (event.ctrlKey && event.key === 'a') || (event.ctrlKey && event.key === 'x') || (event.ctrlKey && event.key === 'v') || event.key.includes('Arrow') || (event.shiftKey && event.key.includes('Arrow')) ) { return; } if ( !(event.key.match(/^[a-zA-Z0-9_ -]$/)) || buildNameInput.value.length >= 16 ) { event.preventDefault(); } }); buildNameInput.addEventListener('input', function() { var sanitizedText = buildNameInput.value.replace(/[^a-zA-Z0-9_ -]/g, ''); var maxLength = 16; if (sanitizedText.length > maxLength) { sanitizedText = sanitizedText.substring(0, maxLength); } if (buildNameInput.value !== sanitizedText) { buildNameInput.value = sanitizedText; } }); var buildCodeInput = document.createElement('input'); buildCodeInput.type = 'text'; buildCodeInput.className = 'input'; buildCodeInput.placeholder = 'Enter Build Code'; addBuildInputDiv.appendChild(buildCodeInput); buildCodeInput.addEventListener('keydown', function(event) { event.stopPropagation(); if ( event.key === 'Backspace' || (event.ctrlKey && event.key === 'c') || (event.ctrlKey && event.key === 'a') || (event.ctrlKey && event.key === 'x') || (event.ctrlKey && event.key === 'v') || event.key.includes('Arrow') || (event.shiftKey && event.key.includes('Arrow')) ) { return; } if ( !(event.key.match(/^[1-8]$/)) || buildCodeInput.value.length >= 33 ) { event.preventDefault(); } }); buildCodeInput.addEventListener('input', function() { var sanitizedCode = buildCodeInput.value.replace(/[^1-8]/g, ''); var maxLength = 33; if (sanitizedCode.length > maxLength) { sanitizedCode = sanitizedCode.substring(0, maxLength); } if (buildCodeInput.value !== sanitizedCode) { buildCodeInput.value = sanitizedCode; } }); var saveBuildBtn = document.createElement('button'); saveBuildBtn.className = 'saveBuildBtn'; saveBuildBtn.textContent = 'Save'; addBuildActionDiv.appendChild(saveBuildBtn); saveBuildBtn.addEventListener('click', function() { var newName = buildNameInput.value; var newCode = buildCodeInput.value; if (buildCodeInput.value.length !== 33) { notification("BuildCode must be exactly 33 characters in length.", "error"); } else { if (newName && newCode) { var build = jsonData.builds.find(function(build) { return build.name === 'Null'; }); if (build) { build.name = newName; build.code = newCode; } else { return; } notification(build.name + " has been saved.", "print"); addBuildInputDiv.style.display = "none"; addBuildActionDiv.style.display = "none"; addBuildBtn.style.display = "flex"; buildNameInput.value = ''; buildCodeInput.value = ''; var buildButton = document.createElement('button'); buildButton.id = build.id; buildButton.className = 'buildButton'; buildButton.textContent = build.name; buildButton.setAttribute('onclick', "input.execute('game_stats_build " + build.code + "')"); buildButtonsDiv.appendChild(buildButton); buildButton.addEventListener('click', function() { notification(build.name + ' has been activated.', "print"); }); var buildConfigButton = document.createElement('button'); buildConfigButton.id = build.id; buildConfigButton.className = 'buildConfigButton'; buildConfigButton.textContent = build.name; buildsConfigDiv.appendChild(buildConfigButton); buildConfigButton.addEventListener('click', function() { buildsConfigDropdown(build, buildButtonsDiv, buildsConfigDiv, buildConfigButton); }); localStorage.setItem('builds', JSON.stringify(jsonData)); } } }); var discardBuildBtn = document.createElement('button'); discardBuildBtn.className = 'discardBuildBtn'; discardBuildBtn.textContent = 'Discard'; addBuildActionDiv.appendChild(discardBuildBtn); discardBuildBtn.addEventListener('click', function() { addBuildInputDiv.style.display = "none"; addBuildActionDiv.style.display = "none"; addBuildBtn.style.display = "flex"; buildNameInput.value = ''; buildCodeInput.value = ''; }); var musicBtn = document.createElement('button'); musicBtn.className = 'musicBtn'; controlButtonsDiv.appendChild(musicBtn); var settingBtn = document.createElement('button'); settingBtn.className = 'settingBtn'; controlButtonsDiv.appendChild(settingBtn) musicBtn.addEventListener('click', function() { notification('Music feature is coming soon.', 'print'); }); settingBtn.addEventListener('click', function() { document.querySelector('.addBuildInputDiv').style.display = "none"; document.querySelector('.addBuildActionDiv').style.display = "none"; document.querySelector('.addBuildBtn').style.display = "flex"; buildNameInput.value = ''; buildCodeInput.value = ''; document.querySelectorAll('.buildDropdownDiv').forEach(function(element) { element.remove(); }); var existingDropdowns = settingMenuDiv.querySelectorAll('.buildDropdownDiv'); for (var i = 0; i < existingDropdowns.length; i++) { existingDropdowns[i].remove(); } settingMenuDiv.style.display = (settingMenuDiv.style.display === 'flex') ? 'none' : 'flex'; }); document.addEventListener('keydown', function(event) { if (event.key === 't') { if (mainMenuDiv.style.display === 'flex' || mainMenuDiv.style.display === '') { mainMenuDiv.style.display = settingMenuDiv.style.display = 'none'; } else { mainMenuDiv.style.display = 'flex'; } } }); document.body.appendChild(mainMenuDiv); document.body.appendChild(settingMenuDiv); document.body.appendChild(notificationDiv); setTimeout(function() { notification("Auto Tank Builder/Upgrader has been loaded.", "print"); }, 500); } addHtml(); })();