Add layer based filtering and updates for portals JSON export
This commit is contained in:
parent
4c5144c8c3
commit
f602757ea5
|
@ -0,0 +1,2 @@
|
|||
portals-JSON-export/meta.sh
|
||||
.gitignore
|
|
@ -0,0 +1,14 @@
|
|||
// ==UserScript==
|
||||
// @name Portals JSON Export
|
||||
// @category Info
|
||||
// @author cyi1341
|
||||
// @version 1703430468
|
||||
// @description Exports a JSON file of all visible portals with full details about the team, resonators, links, etc.
|
||||
// @id portals-JSON
|
||||
// @namespace https://git.disroot.org/cyi1341
|
||||
// @updateURL https://git.disroot.org/cyi1341/random-stuff/raw/branch/main/portals-JSON-export/portals-JSON-export.meta.js
|
||||
// @downloadURL https://git.disroot.org/cyi1341/random-stuff/raw/branch/main/portals-JSON-export/portals-JSON-export.user.js
|
||||
// @match https://intel.ingress.com/*
|
||||
// @match https://intel-x.ingress.com/*
|
||||
// @grant none
|
||||
// ==/UserScript==
|
|
@ -2,10 +2,11 @@
|
|||
// @name Portals JSON Export
|
||||
// @category Info
|
||||
// @author cyi1341
|
||||
// @version stuff
|
||||
// @version 1703430468
|
||||
// @description Exports a JSON file of all visible portals with full details about the team, resonators, links, etc.
|
||||
// @id portals-JSON
|
||||
// @namespace https://git.disroot.org/cyi1341
|
||||
// @updateURL https://git.disroot.org/cyi1341/random-stuff/raw/branch/main/portals-JSON-export/portals-JSON-export.meta.js
|
||||
// @downloadURL https://git.disroot.org/cyi1341/random-stuff/raw/branch/main/portals-JSON-export/portals-JSON-export.user.js
|
||||
// @match https://intel.ingress.com/*
|
||||
// @match https://intel-x.ingress.com/*
|
||||
|
@ -45,7 +46,7 @@ function wrapper(plugin_info) {
|
|||
case 2:
|
||||
return 'Enlightened';
|
||||
case 3:
|
||||
return '_MACHINA_';
|
||||
return '__MACHINA__';
|
||||
default:
|
||||
return 'Unknown';
|
||||
}
|
||||
|
@ -154,6 +155,23 @@ function wrapper(plugin_info) {
|
|||
];
|
||||
|
||||
window.plugin.portalsJSON.processPortal = function(portal) {
|
||||
|
||||
const portalLevels = Array.from({length: 8}, (_, i) => i + 1);
|
||||
const teams = {
|
||||
"Unclaimed/Placeholder Portals": 0,
|
||||
"Enlightened": 2,
|
||||
"Resistance": 1,
|
||||
"__MACHINA__": 3
|
||||
};
|
||||
|
||||
for (let level of portalLevels) {
|
||||
if (!overlayStatus[`Level ${level} Portals`] && portal.options.data.level === level) return;
|
||||
}
|
||||
|
||||
for (let [teamName, teamId] of Object.entries(teams)) {
|
||||
if (!overlayStatus[teamName] && portal.options.team === teamId) return;
|
||||
}
|
||||
|
||||
if (!('title' in portal.options.data)) return;
|
||||
var portalData = {};
|
||||
window.plugin.portalsJSON.fields.forEach(function(field) {
|
||||
|
@ -355,7 +373,7 @@ function wrapper(plugin_info) {
|
|||
exportTime = new Date();
|
||||
}
|
||||
|
||||
window.plugin.portalsJSON.loadPortalDetails = async function(guid, retries = 3) {
|
||||
window.plugin.portalsJSON.loadPortalDetails = async function(guid, retries = 5) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let retryCount = 0;
|
||||
const loadDetails = () => {
|
||||
|
@ -370,7 +388,7 @@ function wrapper(plugin_info) {
|
|||
const errorHandler = (error) => {
|
||||
if (retryCount < retries) {
|
||||
retryCount++;
|
||||
setTimeout(loadDetails, 1000);
|
||||
setTimeout(loadDetails, 50);
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
|
@ -386,7 +404,6 @@ function wrapper(plugin_info) {
|
|||
for (const portal of Object.values(window.portals)) {
|
||||
if (!displayBounds.contains(portal.getLatLng())) continue;
|
||||
await window.plugin.portalsJSON.processPortalWithDetails(portal);
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
|
||||
var jsonData = JSON.stringify(Array.from(portalsData.values()), null, 2);
|
||||
|
@ -466,7 +483,6 @@ function wrapper(plugin_info) {
|
|||
});
|
||||
if (found) {
|
||||
await window.plugin.portalsJSON.processPortalWithDetails(portal);
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -487,12 +503,38 @@ function wrapper(plugin_info) {
|
|||
};
|
||||
|
||||
window.plugin.portalsJSON.processPortalWithDetails = async function(portal) {
|
||||
const portalLevels = Array.from({length: 8}, (_, i) => i + 1);
|
||||
const teams = {
|
||||
"Unclaimed/Placeholder Portals": 0,
|
||||
"Enlightened": 2,
|
||||
"Resistance": 1,
|
||||
"__MACHINA__": 3
|
||||
};
|
||||
|
||||
for (let level of portalLevels) {
|
||||
if (!overlayStatus[`Level ${level} Portals`] && portal.options.data.level === level) return;
|
||||
}
|
||||
|
||||
for (let [teamName, teamId] of Object.entries(teams)) {
|
||||
if (!overlayStatus[teamName] && portal.options.team === teamId) return;
|
||||
}
|
||||
|
||||
if (!('title' in portal.options.data)) return;
|
||||
var portalData = {};
|
||||
window.plugin.portalsJSON.fields.forEach(function(field) {
|
||||
var value = field.value(portal);
|
||||
portalData[field.title] = value;
|
||||
});
|
||||
if (portal.options.team === 0) {
|
||||
// Neutral portal - use processPortal
|
||||
window.plugin.portalsJSON.processPortal(portal);
|
||||
return;
|
||||
}
|
||||
var portalData = {};
|
||||
window.plugin.portalsJSON.fields.forEach(function(field) {
|
||||
var value = field.value(portal);
|
||||
portalData[field.title] = value;
|
||||
});
|
||||
try {
|
||||
const details = await window.plugin.portalsJSON.loadPortalDetails(portal.options.guid);
|
||||
portalData['Mods'] = details.mods.map(mod => mod ? {
|
||||
|
|
Loading…
Reference in New Issue