From 9e4ae827de64604ed9a781812d8ac6005d4131e4 Mon Sep 17 00:00:00 2001 From: Sam Sneed <163201376+sam-sneed@users.noreply.github.com> Date: Tue, 28 May 2024 18:43:07 +0000 Subject: [PATCH] Update and rename frontend.js to jspp.js --- frontend.js => jspp.js | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) rename frontend.js => jspp.js (91%) diff --git a/frontend.js b/jspp.js similarity index 91% rename from frontend.js rename to jspp.js index 7f4bc8d..cf816c0 100644 --- a/frontend.js +++ b/jspp.js @@ -1,3 +1,4 @@ +// JS++ // Created by Samuel Lord (NodeMixaholic/Sparksammy) // Now Maintained by Sneed Group // Licensed under Samuel Public License with <3 @@ -10,16 +11,40 @@ class JSPlusPlus { Function(js)() } readInternetText(url) { - var request = new XMLHttpRequest(); // Create a new XMLHttpRequest object - request.open('GET', url, false); // Open the request with synchronous mode - request.send(null); // Send the request with no additional data + try { + var request = new XMLHttpRequest(); // Create a new XMLHttpRequest object + request.open('GET', url, false); // Open the request with synchronous mode + request.send(null); // Send the request with no additional data - if (request.status === 200) { // Check if the request was successful - return request.responseText; // Return the response text - } else { - return 'Error: ' + request.status; // Return an error message if the request failed + if (request.status === 200) { // Check if the request was successful + return request.responseText; // Return the response text + } else { + return 'Error: ' + request.status; // Return an error message if the request failed + } + } catch { + try { + let http = require('http'); + let body = "" + let request = http.get(url, function (res) { + var data = ''; + res.on('data', function (chunk) { + data += chunk; + }); + res.on('end', function () { + body = data.toString() + }); + }); + request.on('error', function (e) { + body = e.message + }); + request.end(); + return body; + } catch { + return "Unknown error fetching URL! :'(" + } } } + require(jsURI) { try { let req = JSPlusPlus.JSPlusPlus.readInternetText(jsURI); @@ -445,7 +470,5 @@ class JSPlusPlus { JSPlusPlus.General.require("https://cdn.jsdelivr.net/npm/gun/gun.js") return Gun(relays) } - - } }