Last active
March 29, 2022 23:28
-
-
Save Tro95/c3641b7b991c64d9a7b218f0fe3690a5 to your computer and use it in GitHub Desktop.
Pardus Mission NPCs Highlighter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Pardus Mission NPCs Highlighter | |
// @namespace Tro | |
// @description Highlights NPCs for whjich you have an active mission to kill | |
// @include http*://*.pardus.at/main.php | |
// @include http*://*.pardus.at/overview_jobs.php | |
// @version 1 | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
var missions = []; | |
var universe = document.getElementsByTagName("body")[0].getAttribute("onload").slice(check.lastIndexOf("=")+1,check.length).toLowerCase(); | |
var i, j; | |
if (document.referrer.indexOf("/main.php") == -1) { | |
load_missions(); | |
} | |
switch (location.pathname) { | |
case "/main.php": { | |
missions = JSON.parse(GM_getValue("active_missions", [])); | |
var nav_area = document.getElementById('navarea').childNodes[1]; | |
var num_of_vertical_tiles = nav_area.rows.length; | |
var num_of_horizontal_tiles = nav_area.rows[0].cells.length; | |
var nav_grid = []; | |
var npcs_looking_for = []; | |
// Create an object to refer to the navigation grid | |
for (i = 0; i < num_of_vertical_tiles; i++) { | |
nav_grid.push([]); | |
for (j = 0; j < num_of_horizontal_tiles; j++) { | |
nav_grid[i].push(nav_area.rows[i].cells[j]); | |
} | |
} | |
var npcs_found = []; | |
for (i = 0; i < num_of_vertical_tiles; i++) { | |
for (j = 0; j < num_of_horizontal_tiles; j++) { | |
// If the tile is not passable, ignore it | |
if (nav_grid[i][j].childNodes[0].childElementCount == 0) { | |
continue; | |
} | |
// Does the tile contain an NPC, if so log it and its position | |
var img_url_split = nav_grid[i][j].childNodes[0].childNodes[0].src.split('/'); | |
if (img_url_split[5] == "opponents") { | |
npcs_found.push({ | |
npc: img_url_split[6].split('.')[0], | |
y_coord: i, | |
x_coord: j, | |
}); | |
} | |
} | |
} | |
for (i = 0; i < missions.length; i++) { | |
if (npcs_looking_for.indexOf(missions[i].npc == -1)) { | |
npcs_looking_for.push(missions[i].npc); | |
} | |
} | |
for (i = 0; i < npcs_found.length; i++) { | |
if (npcs_looking_for.indexOf(npcs_found[i].npc) != -1) { | |
highlight_tile(npcs_found[i].x_coord, npcs_found[i].y_coord); | |
} | |
} | |
function highlight_tile(x, y) { | |
nav_grid[y][x].childNodes[0].childNodes[0].setAttribute('style', 'background:#00B448'); | |
} | |
} | |
case "/overview_jobs.php": { | |
var missions_taken = document.getElementById('div_missions').getElementsByClassName('messagestyle'); | |
for (i = 0; i < missions_taken.length; i++) { | |
if (missions_taken[i].childNodes[0].rows[0].childNodes[0].textContent.indexOf('Assassination') != -1) { | |
if (missions_taken[i].childNodes[0].rows.length == 4) { | |
var npc_to_target = missions_taken[i].childNodes[0].rows[1].cells[0].childNodes[0].src.split('/')[6].split('.')[0]; | |
var number_to_kill = missions_taken[i].childNodes[0].rows[2].cells[0].textContent.split(' / ')[1]; | |
missions.push({ | |
npc: npc_to_target, | |
number: number_to_kill, | |
}); | |
} | |
} | |
} | |
GM_setValue("active_missions", JSON.stringify(missions)); | |
console.log(missions); | |
} | |
} | |
function load_missions() { | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: "https://" + universe + ".pardus.at/overview_jobs.php", | |
onerror: function(response) { | |
console.log("Something went wrong!"); | |
}, | |
onload: function(response) { | |
parser = new DOMParser(); | |
htmlDoc = parser.parseFromString(response.responseText, "text/html"); | |
var missions_taken = htmlDoc.getElementById('div_missions').getElementsByClassName('messagestyle'); | |
missions = []; | |
for (i = 0; i < missions_taken.length; i++) { | |
if (missions_taken[i].childNodes[0].rows[0].childNodes[0].textContent.indexOf('Assassination') != -1) { | |
if (missions_taken[i].childNodes[0].rows.length == 4) { | |
var npc_to_target = missions_taken[i].childNodes[0].rows[1].cells[0].childNodes[0].src.split('/')[6].split('.')[0]; | |
var number_to_kill = missions_taken[i].childNodes[0].rows[2].cells[0].textContent.split(' / ')[1]; | |
missions.push({ | |
npc: npc_to_target, | |
number: number_to_kill, | |
}); | |
} | |
} | |
} | |
GM_setValue("active_missions", JSON.stringify(missions)); | |
console.log(missions); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment