-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathContent.js
1 lines (1 loc) · 17.8 KB
/
Content.js
1
var authInterval,username,voxels_location="",finalFetchComplete=!1;window.contentScriptReady=!0;const apiURL="https://pixels-api.xyz/API/load_data.php",toolsURL="https://tools.pixels-api.xyz/API/load_tools.php";var startButton,pageContentElement,notifications,taskboardTiles,nodeNames=[],premium=!1,loadTasksF=!1,onPlayPixels=!0;let timersArray=[],displayNamesJSONArray,craftingRecipesJSONArray=[],xpArray=[],autoUpdateLocations=[],landData=[],inventoryValue,petInventoryValue,guildRunes=0;var currentActiveTab="timers";let voxelsDisplayed=!0,fullPageActive=!1,activeFullPage="settings",weeklySessions=[{day:"Tuesday",startTimesUTC:[3,13,20],durationMinutes:45},{day:"Saturday",startTimesUTC:[14],durationMinutes:105}],taskTimerSec=120;const version="498",body=document.body;function startLoad(){let e=window.location.hostname;"play.pixels.xyz"===e?initiateLoad():"dashboard.pixels.xyz"===e&&(onPlayPixels=!1,lbReceiver(),loadDashboard())}function checkForHUD(){let e=document.querySelector(nodeNames.hudTopLeft);e?authUser():setTimeout(checkForHUD,100)}function initiate(){function e(){try{chrome.storage.local.get(["userStatus","auth","premium"],function(e){if(chrome.runtime.lastError){displayInfo({title:"Update!",rows:[{text:"Voxels has received an updated. Please reload this page."}]});return}e.userStatus?(clearInterval(authInterval),getNodeNames(),e.auth?(loadTitleSection("timers"),loadTimers(1),setTimeout(()=>{window.postMessage({type:"VOXELS_SET_INSTANCE_ACTIVE",value:!1})},100)):startAuthProcess()):displayInfo({title:"How to login:",rows:[{image:"login.png",text:"Click on the extension in the top right corner to sign in."}]})})}catch(e){extensionUpdated()}}authInterval=setInterval(e,1e3),e()}function initiateLoad(){let e=document.createElement("script");function t(e){e.source===window&&e.data.type&&"VOXELS_INITIATED"===e.data.type&&(e.data.label,loadBasicOverlay(),initiate(),setupDraggable(),window.removeEventListener("message",t))}e.src=chrome.runtime.getURL("images/Setup/login_page.js"),document.head.appendChild(e),initializeCanvas(),window.addEventListener("message",t)}function loadDashboard(){let e=document.createElement("script");e.src=chrome.runtime.getURL("images/Setup/dashboard.js"),document.head.appendChild(e)}function extensionUpdated(){displayInfo({title:"Update!",rows:[{text:"Voxels has received an updated. Please reload this page."}]})}function startAuthProcess(){displayInfo({title:"Next step:",rows:[{text:"Start Pixels to authenticate."}]}),checkForHUD()}function getNodeNames(){chrome.storage.local.get("node_info",function(e){void 0!==e.node_info&&(nodeNames=chrome.runtime.lastError?["error"]:e.node_info)})}function displayInfo(e){reloadOverlay();let t=document.querySelector(".voxels-main");var a=document.createElement("div");a.classList.add("voxels-main-top-section"),t.appendChild(a);var i=document.createElement("a");i.classList.add("voxels-main-title"),i.href="https://voxels-extension.com",i.target="_blank",i.textContent="Voxels-Extension.com",a.appendChild(i);var s=document.createElement("div");if(s.classList.add("voxels-main-setup","pixel-border"),s.style.display="block",t.appendChild(s),e.rows[0].image){var n=document.createElement("img");n.src=chrome.runtime.getURL("images")+"/Setup/"+e.rows[0].image,n.classList.add("voxels-setup-image"),s.appendChild(n)}var l=document.createElement("p");l.textContent=e.rows[0].text,l.classList.add("voxels-setup-text"),s.appendChild(l)}function authUser(){window.postMessage({type:"VOXELS_INITIATE_SETUP"}),chrome.storage.local.get(["user_info"],function(e){var t=e.user_info;function a(e){if(e.source===window&&e.data.type&&"VOXELS_PLAYER_LABEL"===e.data.type){let i=e.data.label;i==t&&(chrome.storage.local.set({auth:!0}),reloadOverlay(),loadTitleSection("timers"),loadTimers(1),window.removeEventListener("message",a),window.postMessage({type:"VOXELS_SET_INSTANCE_ACTIVE",value:!1}))}}window.addEventListener("message",a)})}function getUserData(){return new Promise((e,t)=>{chrome.storage.local.get(["user_info","user_acde","notifications","voxelsDisplayed","displayInventoryPrice","storageHover","taskboardTiles"],function(a){let i=a.user_info,s=a.user_acde;i?(loadingScreen(1),(function e(t,s,n=3,l=5e3){return new Promise((e,o)=>{let r=()=>{fetch(t,{method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify(s)}).then(e=>{if(200!==e.status)throw Error("fail");return e.json()}).then(t=>{let s=t.status;if("ok"===s){username=i,chrome.storage.local.set({pid:t.data.premium.pid,timer_data:t.data.timer,storage_data:t.data.storage,task_data:t.data.tasks,node_info:t.data.nodeData,user_acde:t.data.acde});let n=t.data.nodeData_inpage;n&&window.postMessage({type:"VOXELS_NODE_INPAGE",value:n},"*"),fetchDisplayNamesJSON().then(()=>{for(let e in t.data.items)if(t.data.items.hasOwnProperty(e)){let a=e,i=t.data.items[e],s=i.name,n=i.image,l=displayNamesJSONArray.find(e=>e.item===a);l||displayNamesJSONArray.push({item:a,display_name:s,image:n})}}),fetchCraftingRecipesJSON(),weeklySessions=t.data.weeklySessions,guildRunes=t.data.guild_runes,timersArray=t.data.timer,taskTimerSec=t.data.taskTime;var l=t.data.xpArray;xpArray=l.map((e,t)=>l.slice(0,t+1).reduce((e,t)=>e+t,0)),notifications=a.notifications,displayInventoryPrice=a.displayInventoryPrice,(voxelsDisplayed=a.voxelsDisplayed)||setTimeout(function(){let e=document.body,t=document.querySelector("#voxels-main-nav"),a=document.querySelector("#voxels-toggle-voxels-button");t.style.display="none",a.style.display="flex",e.classList.remove("js-voxels-main-modal-active")},200),displayStorageHover=a.storageHover,taskboardTiles=a.taskboardTiles,getNodeNames(),loadTasksF=t.data.loadTasksF,finalFetchComplete=!0,getToolsLands(),initialStorageFetch(),loadingScreen(0),t.data.news&&quickMessage(t.data.news,"news");let r=t.data.premium.premium,d=t.data.iData;if(r){let c=t.data.premium.premium_end,p=Math.floor(Date.now()/1e3);if(c>p){c-p<172800&&showAlert("Your premium runs out within the next 2 days! Renew now!","info"),premium=r,setTimeout(setupReceiver,1e3);let m=document.createElement("div");m.className="voxels-extra-nodes",document.body.appendChild(m)}}var u=document.createElement("div");u.setAttribute("id","voxels-main-nav"),document.body.appendChild(u);var v=document.createElement("div");v.setAttribute("id","voxels-toggle-voxels-button"),v.classList.add("clickable"),document.body.appendChild(v);var g=document.createElement("div");g.classList.add("voxels-toggle-voxels-button-icon"),v.appendChild(g);var h=document.createElement("img");g.appendChild(h),h.src=chrome.runtime.getURL("images/icons/icon__show.svg");var y=document.createElement("div");y.setAttribute("id","voxels-main-nav-inner"),y.classList.add("clickable"),u.appendChild(y),document.getElementById("voxels-main-nav-inner").onclick=function(){document.body.classList.toggle("js-voxels-active")},u.appendChild(createSubNavButtons());let f=limiter(toggleInventoryStack,1e4),x=limiter(toggleTaskboardDisplay,1e4);document.addEventListener("keydown",function(e){if(null===document.querySelector(".voxels-popup-info")){if(Date.now(),e.metaKey||e.ctrlKey||e.altKey||e.shiftKey){if(e.shiftKey&&e.code.startsWith("Digit")){let t=e.code.replace("Digit","");switch(t){case"1":changeTab("timers");break;case"2":changeTabWithLimit(changeTab,"networth",5e3);break;case"3":changeTabWithLimit(changeTab,"tasks",5e3);break;case"4":changeTabWithLimit(changeTab,"stats",1e4);break;case"5":changeTabWithLimit(changeTab,"premium",1e4);break;case"6":changeTabWithLimit(changeTab,"gw",5e3);break;case"7":changeTabWithLimit(changeTab,"land",2e3)}}else e.shiftKey&&"KeyG"===e.code?(e.stopPropagation(),changeTabWithLimit(switchFullPage,"guilds",5e3)):e.shiftKey&&"KeyD"===e.code?(e.stopPropagation(),x()):e.shiftKey&&"KeyA"===e.code?(e.stopPropagation(),changeTabWithLimit(switchFullPage,"player",5e3)):e.shiftKey&&"KeyP"===e.code?(e.stopPropagation(),changeTabWithLimit(switchFullPage,"pass",5e3)):e.shiftKey&&"KeyS"===e.code?(e.stopPropagation(),switchFullPage("settings")):e.shiftKey&&"KeyF"===e.code&&(e.stopPropagation(),fullPageActive?closeFullpage():openFullpage())}else"v"===e.key||"V"===e.key?toggleVoxels():e.key===nodeNames.presst||e.key===nodeNames.pressT?f():"r"===e.key||"R"===e.key?togglePrices():("n"===e.key||"N"===e.key)&&toggleNotifications()}}),v.addEventListener("click",function(){toggleVoxels()}),mainInterval(r,d),e(t.data.timer)}else console.log("Error in fetching user data:",t.error),o(Error(t.error))}).catch(e=>{console.log(e),n>0?(console.log(`Retrying in ${l/1e3} seconds. Remaining retries: ${n}`),setTimeout(r,l)):o(Error("Failed to fetch user data after retries"))})};r()})})("https://pixels-api.xyz/API/load_data.php",{name:i,user_acde:s,operation:"requestWithPremium",version:"498"}).then(e).catch(t)):quickMessage("Please logout and login to Voxels.","error")})})}async function fetchDisplayNamesJSON(){try{let e=await fetch(chrome.runtime.getURL("assets/display_names.json")),t=await e.json();displayNamesJSONArray=t}catch(a){console.error("Failed to fetch display names:",a)}}async function fetchCraftingRecipesJSON(){try{let e=await fetch(chrome.runtime.getURL("assets/crafting_recipes.json")),t=await e.json();craftingRecipesJSONArray=t}catch(a){console.error("Failed to fetch display names:",a)}}function setupReceiver(){let e=document.getElementById("voxels-main-nav-inner"),t=Date.now();function a(){let a=Date.now();a-t>500?(e.classList.remove("voxels-status-green"),e.classList.add("voxels-status-red")):(e.classList.remove("voxels-status-red"),e.classList.add("voxels-status-green"))}setInterval(a,100),window.addEventListener("message",e=>{if("VOXELS_GAME_DATA"===e.data.type)t=Date.now(),a(),handleEntityData(e.data.data);else if("VOXELS_OPEN_STORAGE"===e.data.type);else if("CAMERA_CHANGE"===e.data.type)cameraData=e.data.data;else if("LAND_CHANGE"===e.data.type)landData=e.data.data,"land"==currentActiveTab&&loadLandPage(e.data.data);else if("BALANCE_CHANGE"===e.data.type){let i=e.data.data;i.forEach(e=>{if("cur_guildtoken"===e.currencyId){guildRunes=e.balance;let t=document.querySelector(".voxels-gw-nav-item.voxels-gw-active");t&&loadGWPage(t.textContent.toLowerCase())}})}})}startLoad();const lastTabChangeTimes={};function changeTabWithLimit(e,t,a){let i=Date.now(),s=lastTabChangeTimes[t];s&&i-s<a?quickMessage("Please wait "+Math.round((a-(i-s))/1e3)+"s...","error"):(e(t),lastTabChangeTimes[t]=i)}function loadBasicOverlay(){document.body.classList.toggle("js-voxels-main-modal-active");var e=document.createElement("div");e.setAttribute("id","voxels-main-modal"),e.setAttribute("data-draggable","true"),e.classList.add("pixel-border"),document.body.appendChild(e),window.innerWidth>540&&chrome.storage.local.get("modalPosition",function(t){if(t.modalPosition){e.style.top=t.modalPosition.top,e.style.left=t.modalPosition.left;let a=e.getBoundingClientRect();(a.top+a.height>window.innerHeight||a.left+a.width>window.innerWidth)&&(e.style.top="70px",e.style.left="20px")}});var t=document.createElement("div");t.setAttribute("id","voxels-main-modal-header"),t.setAttribute("data-drag-handle","true"),e.appendChild(t);var a=document.createElement("div");a.classList.add("voxels-exit-icon","clickable"),a.textContent="X",e.appendChild(a),a.addEventListener("click",function(){document.body.classList.toggle("js-voxels-main-modal-active")});var i=document.createElement("div");i.classList.add("voxels-main"),e.appendChild(i),loadFullPage()}function loadFullPage(){var e=document.createElement("div");e.setAttribute("id","voxels-full-page"),e.style.display="none";var t=document.createElement("div");t.className="voxels-full-nav",["guilds","pass","player","settings"].forEach(function(e){var a=document.createElement("div");a.className="voxels-full-nav-item clickable";var i=document.createElement("img");i.src=chrome.runtime.getURL(`images/icons/icon__${e}.svg`),i.className="voxels-nav-icon",a.appendChild(i);var s=document.createElement("span");s.textContent=e.charAt(0).toUpperCase()+e.slice(1),s.className="voxels-nav-text",a.appendChild(s),"settings"==e&&a.classList.add("active"),t.appendChild(a),a.addEventListener("click",function(){changeTabWithLimit(switchFullPage,e,2e3)})});var a=document.createElement("div");a.classList.add("voxels-exit-icon","clickable"),a.textContent="X",e.appendChild(t),e.appendChild(a),a.addEventListener("click",function(){closeFullpage()}),document.body.appendChild(e);var i=document.createElement("div");i.setAttribute("id","voxels-full-page-main"),e.appendChild(i),loadFullOverlaypage(e),setTimeout(function(){loadSettings()},1e3)}function loadFullOverlaypage(e){var t=document.createElement("div");t.setAttribute("id","voxels-full-page-overlay"),e.appendChild(t);var a=document.createElement("div");a.setAttribute("id","voxels-full-overlay-top");var i=document.createElement("button");i.textContent="Back",i.onclick=function(){hideFullOverlay()},a.appendChild(i),t.appendChild(a);var s=document.createElement("div");s.setAttribute("id","voxels-full-overlay-main"),t.appendChild(s)}function switchFullPage(e){fullPageActive||openFullpage(),reloadFullPage();let t=document.querySelectorAll(".voxels-full-nav-item");t.forEach(e=>{e.classList.remove("active")});let a=Array.from(t).find(t=>t.textContent.toLowerCase()===e);a&&a.classList.add("active"),activeFullPage=e,"guilds"===e?(document.getElementById("voxels-full-page-main").classList.add("voxels-full-guilds"),loadGuildsPage()):"pass"===e?(document.getElementById("voxels-full-page-main").classList.remove("voxels-full-guilds"),loadPassPage()):"player"===e?(document.getElementById("voxels-full-page-main").classList.remove("voxels-full-guilds"),loadLeaderboardPage("overall")):"settings"===e&&(document.getElementById("voxels-full-page-main").classList.remove("voxels-full-guilds"),loadSettings())}function reloadFullPage(){let e=document.querySelector("#voxels-full-page-main");e.innerHTML=""}function createSubNavButtons(){var e=document.createElement("div");e.id="voxels-sub-nav";var t=createSubNavButton("timers","images/icons/icon__timer.svg"),a=createSubNavButton("networth","images/icons/icon__storage.svg"),i=createSubNavButton("tasks","images/icons/icon__task.svg"),s=createSubNavButton("stats","images/icons/icon__stats.svg"),n=createSubNavButton("premium","images/icons/icon__premium.svg"),l=createSubNavButton("tools","images/icons/icon__library.svg"),o=createSubNavButton("gw","images/icons/icon__guild-wars.svg"),r=createSubNavButton("land","images/icons/icon__storage.svg");return e.appendChild(t),e.appendChild(a),e.appendChild(i),e.appendChild(s),e.appendChild(n),e.appendChild(l),e.appendChild(o),e.appendChild(r),e}function createSubNavButton(e,t){let a=document.createElement("div");a.classList.add("voxels-sub-nav-button");var i=document.createElement("div");i.classList.add("voxels-sub-nav-button-icon","clickable"),a.appendChild(i);var s=document.createElement("img");i.appendChild(s),s.src=chrome.runtime.getURL(t);let n=limiter(function(){"tools"===e?openFullpage():changeTab(e)},2e3);return a.addEventListener("click",function(){n()}),a}function changeTab(e){closeFullpage(),reloadOverlay(),document.body.classList.contains("js-voxels-main-modal-active")||document.body.classList.add("js-voxels-main-modal-active");let t=document.querySelectorAll(".voxels-hover-box");t.forEach(function(e){e.parentNode&&e.parentNode.removeChild(e)});let a=document.querySelectorAll(".voxels-networth-hover");a.forEach(function(e){e.parentNode&&e.parentNode.removeChild(e)}),loadTitleSection(e),currentActiveTab=e,tabNumber=0,"timers"===e?loadTimers(0):"networth"===e?(tabNumber=1,loadNetworth(0)):"tasks"===e?(tabNumber=2,loadTasks(0)):"stats"===e?(tabNumber=3,loadStats(0)):"premium"===e?(tabNumber=4,loadPremium()):"gw"===e?(tabNumber=5,loadGuildWar()):"land"===e&&(tabNumber=6,loadLandPage(landData))}function reloadOverlay(){let e=document.querySelector(".voxels-main");e.innerHTML=""}function displayPremium(){let e=document.querySelector(".voxels-main");var t=document.createElement("div");t.classList.add("voxels-main-premium","pixel-border","voxels-premium-promo");var a=document.createElement("div");a.classList.add("voxels-premium-title"),a.innerText="VOXELS PREMIUM",t.appendChild(a);var i=document.createElement("div");i.classList.add("voxels-premium-content");var s=document.createElement("div");s.classList.add("voxels-premium-list");var n=["Player Networth","Stats and graphs","Leaderboard & Seasons","50 Plots","Auto-Detect collecting","Tasks overview","More coming soon!"],l=document.createElement("ul");for(let o=0;o<n.length;o++){var r=document.createElement("li"),d=document.createElement("img");d.src=chrome.runtime.getURL("images/Other/Premium_small.png"),r.appendChild(d),r.appendChild(document.createTextNode(n[o])),l.appendChild(r)}s.appendChild(l),i.appendChild(s);var c=document.createElement("div");c.classList.add("voxels-main-premium-button"),c.innerText="Get premium!",i.appendChild(c),t.appendChild(i),t.addEventListener("click",function(){switchFullPage("premium")}),e.appendChild(t)}function displayPageInfo(e,t,a,i){let s=document.querySelector(".voxels-main");var n=document.createElement("div");n.classList.add("voxels-main-check","clickable");var l=document.createElement("div");if(l.classList.add("voxels-main-check-title"),l.innerText=e,n.appendChild(l),t){var o=document.createElement("div");o.classList.add("voxels-main-check-text"),o.innerText=t,n.appendChild(o)}if(a){var r=document.createElement("img");r.classList.add("voxels-main-check-image"),r.src=a,n.appendChild(r)}"function"==typeof i&&n.addEventListener("click",i),s.appendChild(n)}function loadTitleSection(e){let t=document.querySelector(".voxels-main");var a=document.createElement("div");a.classList.add("voxels-main-top-section"),t.appendChild(a);var i=document.createElement("a");if(i.classList.add("voxels-main-title","voxels-main-url"),i.href="https://voxels-extension.com",i.target="_blank",i.textContent="Voxels-Extension.com",a.appendChild(i),"premium"!==e){var s=document.createElement("hr");a.appendChild(s),"gw"==e?e="Spore Sports":"land"==e&&(e="Industry limits");var n=e.charAt(0).toUpperCase()+e.slice(1),l=document.createElement("div");l.textContent=n,l.classList.add("voxels-main-title"),a.appendChild(l)}}