// ==UserScript== // @name Grepolis Resources Manager // @version 0.1_ALPHA // @include /http[s]{0,1}://[a-z]{2}[0-9]{1,2}\.grepolis\.com/game*/ // @include https://*.forum.grepolis.com/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js // @description A little handy script to help with resource management and more // @author Ezio76 // @copyright 2020+ // @grant unsafeWindow // @grant GM_addStyle // @namespace https://greasyfork.org/users/451401 // @downloadURL none // ==/UserScript== //TODO: fix dropdown for selecting levels // GM-API? GM = (typeof GM_info === 'object'); var uw = unsafeWindow GM_addStyle(` #GRM_window{background-color: #ffe2a2; display: block; height: 550px; width: 780px; z-index: 1100; position: absolute; top: 100px; left: 30vw; border: 2px black solid } #GRM_toolbar{ height: 30px; border-bottom: 2px black solid; } #GRM_toolbar_list{ list-style-type: none; margin: 0; padding-top:3px; padding-left: 1px; overflow: hidden; top: 10px; } #GRM_title{ padding-top: 3px; float: left; width: 40%; text-align: left; } .GRM_toolbar_item{ height: 25px; float: left; width: 27%; text-align: center; border-left: 1px solid black; border-right: 1px solid black; border-top: 1px solid black; border-top-left-radius: 5px 5px; border-top-right-radius: 5px 5px; margin: 1px } #GRM_close{ padding-top: 5px; float: left; } #GRM_close_img{ margin-left: 10px; } .GRM_building_image{ height: 40px; width: 40px; letter-spacing: -1px; margin: 0; display: inline-grid; } .GRM_building_level{ position: relative; bottom: -25px; right: -10px; color: white; font-weight: bolder; } .GRM_selector{ height: 40px; width: 30px; display: inline; } .GRM_input{ width: 25px; } `); function openGRMWindow(){ var grmWindow = document.querySelector("#GRM_window"); if (grmWindow === null) { initializeGRMWindow(); openGRMWindow(); return; } //console.log(uw.ITowns.getCurrentTown()); fillGRMWindow(uw.ITowns.getCurrentTown()); $("#GRM_window").css("display","block"); } function fillGRMWindow(town){ $("#GRM_city_name").text(`${town.getName()}`) const buildings = town.getBuildings().getLevels(); $("#GRM_main_level").text(`${buildings.main}`); $("#GRM_hide_level").text(`${buildings.hide}`); $("#GRM_place_level").text(`${buildings.place}`); $("#GRM_lumber_level").text(`${buildings.lumber}`); $("#GRM_stoner_level").text(`${buildings.stoner}`); $("#GRM_ironer_level").text(`${buildings.ironer}`); $("#GRM_market_level").text(`${buildings.market}`); $("#GRM_docks_level").text(`${buildings.docks}`); $("#GRM_barracks_level").text(`${buildings.barracks}`); $("#GRM_wall_level").text(`${buildings.wall}`); $("#GRM_storage_level").text(`${buildings.storage}`); $("#GRM_farm_level").text(`${buildings.farm}`); $("#GRM_academy_level").text(`${buildings.academy}`); $("#GRM_temple_level").text(`${buildings.temple}`); var json_data = uw.ITowns.getCurrentTown().getBuildings().getBuildings(); var result = []; var counter = 0; for(var i in json_data){ if(counter !== 14){ counter++; continue; } result.push([i, json_data [i]]); } var special1 = getSpecialBuilding(result.slice(0,4)); var special2= getSpecialBuilding(result.slice(4)); var specialImage1 = special1 === null ? 'url(https://i.imgur.com/ScMZ4ns.png)' : `url('https://gpnl.innogamescdn.com/images/game/main/${special1}.png')`; var specialImage2 = special2 === null ? 'url(https://i.imgur.com/L26ZuJ4.png)' : `url('https://gpnl.innogamescdn.com/images/game/main/${special2}.png')`; $("#GRM_special_1_background").css("background-image", specialImage1); $("#GRM_special_2_background").css("background-image", specialImage2); } function getSpecialBuilding(specialList){ var specialBuilding = null; for(let i in specialList){ if(specialList[i][1]===1) return specialList[i][0]; } return null; } function initializeGRMWindow(){ var left = document.querySelector("body").clientWidth; $("body").append(`
LEVEL
LEVEL
LEVEL
LEVEL
LEVEL
LEVEL
LEVEL
LEVEL
LEVEL
LEVEL
LEVEL
LEVEL
`); var grmWindow = document.querySelector("#GRM_window"); dragElement(grmWindow); var close = document.querySelector("#GRM_close_img"); close.addEventListener("click", function(){ $("#GRM_window").css("display","none"); }); } function addMenuItem(){ $("#ui_box > div.nui_main_menu > div.middle > div.content > ul").append( `
  • GRM
  • `); var li = document.querySelector("#GRM_Button"); li.addEventListener("click", openGRMWindow); } function dragElement(elmnt) { var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0; if (document.getElementById(elmnt.id + "header")) { // if present, the header is where you move the DIV from: document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown; } else { // otherwise, move the DIV from anywhere inside the DIV: elmnt.onmousedown = dragMouseDown; } function dragMouseDown(e) { e = e || window.event; e.preventDefault(); // get the mouse cursor position at startup: pos3 = e.clientX; pos4 = e.clientY; document.onmouseup = closeDragElement; // call a function whenever the cursor moves: document.onmousemove = elementDrag; } function elementDrag(e) { e = e || window.event; e.preventDefault(); // calculate the new cursor position: pos1 = pos3 - e.clientX; pos2 = pos4 - e.clientY; pos3 = e.clientX; pos4 = e.clientY; // set the element's new position: elmnt.style.top = (elmnt.offsetTop - pos2) + "px"; elmnt.style.left = (elmnt.offsetLeft - pos1) + "px"; } function closeDragElement() { // stop moving when mouse button is released: document.onmouseup = null; document.onmousemove = null; } } function startup() { 'use strict'; addMenuItem(); //console.log(uw.GameModels.TownIdList()); }; startup();