* Common: IndexedDB

Stellt Funktionen zum Speichern und Abrufen von Daten in der IndexedDB bereit

이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greasyfork.org/scripts/553985/1685377/%2A%20Common%3A%20IndexedDB.js을(를) 사용하여 포함하는 라이브러리입니다.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name        * Common: IndexedDB (Fork by Shihu)
// @namespace   Shihu
// @version     1.0.1
// @license     BSD-3-Clause
// @author      BOS-Ernie (Original), Shihu (Fork/Maintainer)
// @description Funktionen zum Speichern und Abrufen von Daten in der IndexedDB
// @icon        https://www.google.com/s2/favicons?sz=64&domain=leitstellenspiel.de
// @run-at      document-idle
// @grant       none
// ==/UserScript==

const databaseName = "BosErnie";
const objectStoreName = "GebäudeUndFahrzeugVerwalter";

function openDB() {
  return new Promise((resolve, reject) => {
    const request = window.indexedDB.open(databaseName, 1);

    request.onerror = () => {
      reject("Failed to open the database");
    };

    request.onsuccess = event => {
      const db = event.target.result;
      resolve(db);
    };

    request.onupgradeneeded = event => {
      const db = event.target.result;
      const objectStore = db.createObjectStore(objectStoreName);
      objectStore.createIndex("IndexName", "propertyName", { unique: false });
    };
  });
}

async function storeData(data, key) {
  const db = await openDB();

  return new Promise((resolve, reject) => {
    const transaction = db.transaction([objectStoreName], "readwrite");
    const objectStore = transaction.objectStore(objectStoreName);

    const request = objectStore.put(data, key);

    request.onsuccess = () => {
      resolve("Data stored successfully");
    };

    request.onerror = () => {
      reject("Failed to store data");
    };
  });
}

async function retrieveData(key) {
  const db = await openDB();

  return new Promise((resolve, reject) => {
    const transaction = db.transaction([objectStoreName], "readonly");
    const objectStore = transaction.objectStore(objectStoreName);

    const request = objectStore.get(key);

    request.onsuccess = event => {
      const data = event.target.result;
      resolve(data);
    };

    request.onerror = () => {
      reject("Failed to retrieve data");
    };
  });
}

/**
 * @license
 * BSD 3-Clause License
 * 
 * Original work Copyright (c) [Jahr], BOS-Ernie
 * Modified and maintained by [Dein Name], 2025
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * 3. Neither the name of BOS-Ernie nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific
 *    prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * ...
 */