From f48a0b5f4386795e3a54c5c48bb98ffe5d0c2abf Mon Sep 17 00:00:00 2001
From: knightofdemons <8983377+knightofdemons@users.noreply.github.com>
Date: Wed, 3 May 2023 20:09:15 +0200
Subject: [PATCH] a
---
Release/close.html | 3 +
Release/js/functions.js | 61 ++++++++++++
Release/js/main.js | 53 -----------
chatGPT/app.js | 201 ++++++++++++++++++++++++++++++++++++++++
chatGPT/index.html | 51 ++++++++++
chatGPT/styles.css | 84 +++++++++++++++++
6 files changed, 400 insertions(+), 53 deletions(-)
create mode 100644 Release/close.html
create mode 100644 chatGPT/app.js
create mode 100644 chatGPT/index.html
create mode 100644 chatGPT/styles.css
diff --git a/Release/close.html b/Release/close.html
new file mode 100644
index 0000000..33b0cf2
--- /dev/null
+++ b/Release/close.html
@@ -0,0 +1,3 @@
+
\ No newline at end of file
diff --git a/Release/js/functions.js b/Release/js/functions.js
index db1b71d..68faed9 100644
--- a/Release/js/functions.js
+++ b/Release/js/functions.js
@@ -676,3 +676,64 @@ async function getFireteam(){
}
}
}
+
+
+/*********************************************************************************/
+/* Browser Cache Saving/Reading (IndexedDB API) */
+/*********************************************************************************/
+
+function updateUserDB() {
+// updates userDB in storage from internal userDB
+ userDBtmp = Object.assign({},userDB);
+ delete userDBtmp.loadedPlayers;
+ userDBtmp.loadedPlayers = Object.keys(userDB['loadedPlayers']);
+ var jZ = new jsonZipper(JSON.stringify(userDBtmp));
+ jZ.zip();
+
+ console.log(jZ);
+ localStorage.setItem("userDB", jZ);
+}
+
+function saveSiteSettings(prop, val){
+ if(!userDB['siteSettings'].hasOwnProperty(prop)){
+ userDB['siteSettings'][prop] = {};
+ }
+ userDB['siteSettings'][prop] = val;
+ updateUserDB();
+}
+
+async function refreshPlayer(membershipId){
+ currentPlayer = await getPlayer(userDB['loadedPlayers'][membershipId]['membershipId'][0], userDB['loadedPlayers'][membershipId]['platformType'][0]);
+ userDB['loadedPlayers'][membershipId] = currentPlayer;
+ updateUserDB();
+}
+
+function deletePlayer(membershipID){
+ document.getElementById("acc-" + membershipID).remove();
+ delete userDB['loadedPlayers'][membershipID];
+ console.log("deleted " + membershipID + " from local player storage");
+ updateUserDB();
+}
+
+async function savePlayer(cP){
+ if(!userDB.hasOwnProperty('loadedPlayers')){
+ userDB['loadedPlayers'] = {};
+ }
+ if(!userDB['loadedPlayers'].hasOwnProperty(cP.membershipId)){
+ userDB['loadedPlayers'][cP.membershipId[0]] = cP;
+ console.log("saved " + cP.membershipId[0] + " to local player storage");
+ updateUserDB();
+ showPlayer(cP.membershipId[0]);
+ document.getElementById("playerBucket").innerHTML += "
" +
+ "" +
+ "" +
+ "" + cP.platformName[0] + "" +
+ "" +
+ "";
+ "";
+ }else{
+ console.log("already existing player");
+ }
+}
+
+const request = window.indexedDB.open("MyTestDatabase", 3);
\ No newline at end of file
diff --git a/Release/js/main.js b/Release/js/main.js
index b242964..5f3328b 100644
--- a/Release/js/main.js
+++ b/Release/js/main.js
@@ -163,59 +163,6 @@ function showLoginFrame(){
loginFrame.classList.toggle("closed");
}
-function updateUserDB() {
-// updates userDB in storage from internal userDB
- userDBtmp = Object.assign({},userDB);
- delete userDBtmp.loadedPlayers;
- userDBtmp.loadedPlayers = Object.keys(userDB['loadedPlayers']);
- var jZ = new jsonZipper(JSON.stringify(userDBtmp));
- jZ.zip();
-
- console.log(jZ);
- localStorage.setItem("userDB", jZ);
-}
-
-function saveSiteSettings(prop, val){
- if(!userDB['siteSettings'].hasOwnProperty(prop)){
- userDB['siteSettings'][prop] = {};
- }
- userDB['siteSettings'][prop] = val;
- updateUserDB();
-}
-
-async function refreshPlayer(membershipId){
- currentPlayer = await getPlayer(userDB['loadedPlayers'][membershipId]['membershipId'][0], userDB['loadedPlayers'][membershipId]['platformType'][0]);
- userDB['loadedPlayers'][membershipId] = currentPlayer;
- updateUserDB();
-}
-
-function deletePlayer(membershipID){
- document.getElementById("acc-" + membershipID).remove();
- delete userDB['loadedPlayers'][membershipID];
- console.log("deleted " + membershipID + " from local player storage");
- updateUserDB();
-}
-
-async function savePlayer(cP){
- if(!userDB.hasOwnProperty('loadedPlayers')){
- userDB['loadedPlayers'] = {};
- }
- if(!userDB['loadedPlayers'].hasOwnProperty(cP.membershipId)){
- userDB['loadedPlayers'][cP.membershipId[0]] = cP;
- console.log("saved " + cP.membershipId[0] + " to local player storage");
- updateUserDB();
- showPlayer(cP.membershipId[0]);
- document.getElementById("playerBucket").innerHTML += "" +
- "" +
- "" +
- "" + cP.platformName[0] + "" +
- "" +
- "";
- "";
- }else{
- console.log("already existing player");
- }
-}
function clearData() {
diff --git a/chatGPT/app.js b/chatGPT/app.js
new file mode 100644
index 0000000..b007b59
--- /dev/null
+++ b/chatGPT/app.js
@@ -0,0 +1,201 @@
+const apiKey = "50a74e4f4f23452c81f7a9cf6a73f124";
+const dbVersion = 1;
+const dbStoreName = "inventory";
+
+// Check for IndexedDB support
+if (!window.indexedDB) {
+ console.log("Your browser doesn't support IndexedDB.");
+}
+
+// Open the IndexedDB database
+const request = window.indexedDB.open(dbStoreName, dbVersion);
+let db;
+
+request.onerror = function (event) {
+ console.log("Database error: " + event.target.errorCode);
+};
+
+request.onsuccess = function (event) {
+ console.log("Database opened successfully.");
+ db = event.target.result;
+};
+
+request.onupgradeneeded = function (event) {
+ console.log("Database upgrade needed.");
+ db = event.target.result;
+ const store = db.createObjectStore(dbStoreName);
+};
+
+const searchForm = document.getElementById("search-form");
+const searchInput = document.getElementById("search-input");
+const searchResults = document.getElementById("search-results");
+const inventoryTitle = document.getElementById("inventory-title");
+const weaponsTitle = document.getElementById("weapons-title");
+const gearTitle = document.getElementById("gear-title");
+const inventoryList = document.getElementById("inventory-list");
+const weaponsList = document.getElementById("weapons-list");
+const gearList = document.getElementById("gear-list");
+const sidebarToggle = document.getElementById("sidebar-toggle");
+const sidebar = document.getElementById("sidebar");
+
+// Add event listener for input event on search input
+searchInput.addEventListener("input", function(event) {
+ event.preventDefault();
+ searchResults.innerHTML = ""; // Clear previous search results
+
+ const searchTerm = searchInput.value.trim(); // Get search term and remove whitespace
+ if (searchTerm.length < 3) return; // Don't search if search term is too short
+
+ // Make search request to Bungie API
+ const searchUrl = `https://www.bungie.net/Platform/Destiny2/SearchDestinyPlayer/-1/${encodeURIComponent(searchTerm)}/`;
+ fetch(searchUrl, {
+ headers: {
+ "X-API-Key": apiKey
+ }
+ })
+ .then(response => {
+ if (!response.ok) {
+ throw new Error("Network response was not ok");
+ }
+ return response.json();
+ })
+ .then(data => {
+ const searchResultsHtml = data.Response.map(player => {
+ return `
+
+
+ ${player.displayName} (${player.membershipType})
+
+
+ `;
+ }).join("");
+ searchResults.innerHTML = searchResultsHtml;
+ })
+ .catch(error => {
+ console.error("There was a problem with the search request:", error);
+ });
+});
+
+// Handle inventory button click
+inventoryTitle.addEventListener("click", () => {
+ inventory.scrollIntoView();
+});
+
+// Handle weapons button click
+weaponsTitle.addEventListener("click", () => {
+ document.querySelector("#weapons").scrollIntoView();
+});
+
+// Handle gear button click
+gearTitle.addEventListener("click", () => {
+ document.querySelector("#gear").scrollIntoView();
+});
+
+// Handle search result click
+searchResults.addEventListener("click", (event) => {
+ if (event.target.matches("li")) {
+ const membershipType = event.target.dataset.membershipType;
+ const membershipId = event.target.dataset.membershipId;
+ const displayName = event.target.dataset.displayName;
+ displayInventory(membershipType, membershipId, displayName);
+ }
+});
+
+// Search Bungie.net accounts
+async function searchAccounts(searchTerm) {
+ const url = `https://www.bungie.net/Platform/Destiny2/SearchDestinyPlayer/-1/${encodeURIComponent(
+ searchTerm
+ )}/`;
+ const response = await fetch(url, {
+ headers: {
+ "X-API-Key": apiKey,
+ },
+ });
+ const data = await response.json();
+ if (data.Response.length > 0) {
+ data.Response.forEach((result) => {
+ const li = document.createElement("li");
+ li.dataset.membershipType = result.membershipType;
+ li.dataset.membershipId = result.membershipId;
+ li.dataset.displayName = result.displayName;
+ li.textContent = result.displayName;
+ searchResults.appendChild(li);
+ });
+ } else {
+ const li = document.createElement("li");
+ li.textContent = "No results found.";
+ searchResults.appendChild(li);
+ }
+}
+
+// function to display player inventory
+function displayPlayerInventory(data) {
+ const characterId = data.Response.characterId;
+ const inventory = data.Response.inventory.data.items;
+ const equipped = data.Response.equipment.data.items;
+
+ const characterName = getCharacterName(characterId);
+ const characterClass = getClassFromType(data.Response.character.data.classType);
+
+ // display character name and class
+ const characterHeader = document.createElement("div");
+ characterHeader.classList.add("character-header");
+ characterHeader.innerHTML = `${characterName}
${characterClass}`;
+ mainContent.appendChild(characterHeader);
+
+ // display inventory categories
+ const categories = ["Weapons", "Armor", "General"];
+ for (let category of categories) {
+ const categoryHeader = document.createElement("div");
+ categoryHeader.classList.add("category-header");
+ categoryHeader.innerHTML = `${category}
`;
+ mainContent.appendChild(categoryHeader);
+
+ // display inventory items
+ const categoryItems = getCategoryItems(category, inventory);
+ const categoryEquippedItems = getCategoryItems(category, equipped);
+ for (let item of categoryItems) {
+ const itemElement = createInventoryItemElement(item, categoryEquippedItems);
+ mainContent.appendChild(itemElement);
+ }
+ }
+
+ // update indexedDB with new inventory data
+ const dbPromise = openDatabase();
+ dbPromise.then(db => {
+ const tx = db.transaction("playerInventory", "readwrite");
+ const store = tx.objectStore("playerInventory");
+ store.put({ membershipId: currentMembershipId, characterId: characterId, inventory: data.Response });
+ return tx.complete;
+ });
+}
+
+// function to retrieve player inventory data
+function getPlayerInventoryData(membershipId, characterId) {
+ const dbPromise = openDatabase();
+ dbPromise.then(db => {
+ const tx = db.transaction("playerInventory", "readonly");
+ const store = tx.objectStore("playerInventory");
+ const index = store.index("byMembershipAndCharacter");
+ return index.get([membershipId, characterId]);
+ }).then(data => {
+ if (data) {
+ // if inventory data exists in indexedDB, use it
+ displayPlayerInventory(data.inventory);
+ } else {
+ // if inventory data does not exist in indexedDB, request it from the API
+ const url = `https://www.bungie.net/Platform/Destiny2/${membershipType}/Profile/${membershipId}/Character/${characterId}/?components=Inventory,Character,Equipment`;
+ fetch(url, {
+ headers: {
+ "X-API-Key": apiKey
+ }
+ }).then(response => {
+ return response.json();
+ }).then(data => {
+ displayPlayerInventory(data);
+ }).catch(error => {
+ console.error(error);
+ });
+ }
+ });
+}
diff --git a/chatGPT/index.html b/chatGPT/index.html
new file mode 100644
index 0000000..041588e
--- /dev/null
+++ b/chatGPT/index.html
@@ -0,0 +1,51 @@
+
+
+
+ My Destiny Inventory
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/chatGPT/styles.css b/chatGPT/styles.css
new file mode 100644
index 0000000..b513bf4
--- /dev/null
+++ b/chatGPT/styles.css
@@ -0,0 +1,84 @@
+/* Sidebar */
+
+#sidebar {
+ position: fixed;
+ height: 100%;
+ width: 200px;
+ background-color: #202020;
+ color: #fff;
+ overflow: auto;
+}
+
+.search-container {
+ padding: 20px;
+}
+
+.search-container input[type="text"] {
+ width: 100%;
+ padding: 12px 20px;
+ margin: 8px 0;
+ box-sizing: border-box;
+ border: none;
+ border-radius: 4px;
+ background-color: #555;
+ color: #fff;
+}
+
+#search-results {
+ list-style-type: none;
+ padding: 0;
+ margin: 0;
+}
+
+#search-results li a {
+ display: block;
+ padding: 8px 16px;
+ text-decoration: none;
+ color: #fff;
+}
+
+#search-results li a:hover {
+ background-color: #ddd;
+ color: #000;
+}
+
+.navigation-container {
+ padding: 20px;
+}
+
+.navigation {
+ list-style-type: none;
+ padding: 0;
+ margin: 0;
+}
+
+.navigation li a {
+ display: block;
+ padding: 8px 16px;
+ text-decoration: none;
+ color: #fff;
+}
+
+.navigation li a:hover {
+ background-color: #ddd;
+ color: #000;
+}
+
+/* Main */
+
+#main {
+ margin-left: 200px;
+ padding: 20px;
+}
+
+.header {
+ text-align: center;
+}
+
+h1 {
+ margin-top: 0;
+ font-size: 36px;
+}
+
+.character-select-container {
+ margin-bottom:
\ No newline at end of file