Browse Source

Adding some modified files, not sure if working

main
Levi Olson 3 months ago
parent
commit
3e218cce93
2 changed files with 125 additions and 40 deletions
  1. +124
    -39
      unpacked/panel/assets/javascripts/app.js
  2. +1
    -1
      unpacked/panel/assets/javascripts/panel.js

+ 124
- 39
unpacked/panel/assets/javascripts/app.js View File

@ -1,52 +1,137 @@
var BNPChrome = angular
.module("BNPChrome", [])
.factory("parse", function () {
const parser = function (input, level, depthOverride) {
chrome.extension.getBackgroundPage().console.debug(`In parser: Attempting Parse %s/%s`, level, depthOverride);
const depth = depthOverride || 3;
if (level > depth) return input;
if (!input || typeof input === "number" || typeof input === "boolean") {
return input;
function convertToJSON(input) {
let jsonString;
// Try to parse the input as JSON
try {
jsonString = JSON.parse(input);
return jsonString;
} catch (error) {
// Parsing failed, assume input is a query string
}
if (Array.isArray(input)) {
// loop and parse each node
for (var i = 0; i < input.length; i++) {
input[i] = parser(input[i], level ? level + 1 : 1, depth);
}
return input;
// Decode URL-encoded string n times until no more encoding is found
let decodedInput = decodeURIComponent(input);
while (decodedInput !== input) {
input = decodedInput;
decodedInput = decodeURIComponent(input);
}
if (typeof input === "string") {
// Convert the query string to a JSON object
const keyValuePairs = input.split('&');
const jsonObject = {};
keyValuePairs.forEach(keyValuePair => {
const [key, value] = keyValuePair.split('=');
jsonObject[key] = value;
});
return jsonObject;
}
function queryStringToJson(queryString) {
let decoded = decodeURIComponent(queryString);
let pairs = decoded.split('&');
let result = {};
pairs.forEach(function(pair) {
pair = pair.split('=');
let name = pair[0];
let value = pair[1];
if (name.length > 0) {
name = name.replace(/\[([^\]]*)\]/g, function($0, $1) {
if ($1.length > 0) {
return "." + $1;
} else {
return "";
}
});
try {
chrome.extension.getBackgroundPage().console.debug("In parser: Attempting String Parse");
input = parser(JSON.parse(input), level ? level + 1 : 1, depth);
return input;
value = decodeURIComponent(value);
} catch (e) {
// not a stringified node
// could be URL Encoded
try {
chrome.extension.getBackgroundPage().console.debug("In parser: Attempting URL Decode", decodeURI(input), level, depth);
input = parser(decodeURI(input), level ? level + 1 : 1, depth);
return input;
} catch(e) {
// not url encoded
chrome.extension.getBackgroundPage().console.debug("In parser: Could Not Decode");
return input;
// Do nothing, use the original value instead
}
let keys = name.split('.');
let obj = result;
let key;
while ((key = keys.shift())) {
if (keys.length === 0) {
if (obj[key] === undefined) {
obj[key] = value;
} else if (Array.isArray(obj[key])) {
obj[key].push(value);
} else {
obj[key] = [obj[key], value];
}
} else {
if (obj[key] === undefined) {
obj[key] = {};
}
return input;
obj = obj[key];
}
}
} else if (typeof input === "object") {
Object.keys(input).forEach(function (item) {
input[item] = parser(input[item], level ? level + 1 : 1, depth);
return item;
});
} else {
// unless there is a datatype I'm not checking for....
chrome.extension.getBackgroundPage().console.debug('In parser: Data Type Unaccounted For');
}
}
});
return result;
}
const parseQueryParams = function(queryString) {
// Extract query params using a regular expression
const params = queryString.split('&');
if (params.length == 0) return queryString;
const queryParams = {};
for (let i = 0; i < params.length; i++) {
let [key, value] = params[i].split('=');
let decodedInput = decodeURIComponent(value);
while (decodedInput !== value) {
value = decodedInput;
decodedInput = decodeURIComponent(value);
}
queryParams[key] = decodedInput;
}
return queryParams;
};
const parser = function (input, depth, maxDepth) {
// If the input is a string, try to parse it as JSON
if (typeof input === 'string') {
try {
return parser(JSON.parse(input), depth + 1, maxDepth);
} catch (err) {
// If the input is not valid JSON return the input
return input
}
}
// If the input is an array, recursively parse each item in the array
if (Array.isArray(input)) {
return input.map(item => parser(item, depth + 1, maxDepth));
}
// If the input is an object, recursively parse each value in the object
if (typeof input === 'object') {
const parsedJson = {};
for (const [key, value] of Object.entries(input)) {
if (typeof value === 'string') {
// If the value is a string, then it might be a serialized JSON string, so try to parse it
try {
parsedJson[key] = parser(JSON.parse(value), depth + 1, maxDepth);
} catch (err) {
if (value.includes("&") && value.includes("="))
parsedJson[key] = parser(convertToJSON(value), depth + 1, maxDepth);
else
parsedJson[key] = value;
}
} else {
// If the value is not a string, recursively parse it
parsedJson[key] = parser(value, depth + 1, maxDepth);
}
}
return parsedJson;
}
// If the input is not a string, array, or object, return it unchanged
return input;
};

+ 1
- 1
unpacked/panel/assets/javascripts/panel.js View File

@ -455,7 +455,7 @@ BNPChrome.controller("PanelController", function PanelController($scope, toolbar
if (input) {
let content;
if ($scope.showOriginal) {
content = parse(input, 0, 1);
content = input;
} else {
content = parse(input, 0, depth);
}

Loading…
Cancel
Save