LS (Local Storage)

Bu kütüphane, tarayıcının localStorage özelliğini daha akıllı ve güvenli bir şekilde kullanmanızı sağlar. Standart localStorage yalnızca düz metin (string) saklayabilirken, bu kütüphane nesne (object), dizi (array), sayı ve boolean gibi veri tiplerini otomatik olarak dönüştürerek kaydeder ve okur.

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/591381/1902888/LS%20%28Local%20Storage%29.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        LS (Local Storage)
// @namespace   http://tampermonkey.net/
// @version     1
// @description Bu kütüphane, tarayıcının localStorage özelliğini daha akıllı ve güvenli bir şekilde kullanmanızı sağlar. Standart localStorage yalnızca düz metin (string) saklayabilirken, bu kütüphane nesne (object), dizi (array), sayı ve boolean gibi veri tiplerini otomatik olarak dönüştürerek kaydeder ve okur.
// @author      Atilla
// @license     MIT
// ==/UserScript==
(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD (RequireJS vb.)
    define([], factory);
  } else if (typeof module === 'object' && module.exports) {
    // CommonJS (Node.js, Webpack, require)
    module.exports = factory();
  } else {
    // Tarayıcı Doğrudan Kullanım (<script src="...">)
    // Pencere (window) nesnesine "LS" adıyla ekler
    root.LS = factory();
  }
}(typeof self !== 'undefined' ? self : this, function () {
  
  // Kütüphane mantığı burada başlar
  return {
    /**
     * Veriyi JSON formatına çevirerek kaydeder.
     * @param {string} key 
     * @param {any} value 
     */
    set: function (key, value) {
      localStorage.setItem(key, JSON.stringify(value));
    },

    /**
     * Veriyi okur ve otomatik olarak orijinal tipine çözümler.
     * @param {string} key 
     * @returns {any}
     */
    get: function (key) {
      var value = localStorage.getItem(key);
      if (value === null) return null; // Veri yoksa direkt null dön
      
      try {
        return JSON.parse(value);
      } catch (e) {
        return value; // Veri düz metin ise direkt döndür
      }
    },

    /**
     * Belirtilen anahtardaki veriyi siler.
     * @param {string} key 
     */
    remove: function (key) {
      localStorage.removeItem(key);
    },

    /**
     * Tüm depolama alanını temizler.
     */
    clear: function () {
      localStorage.clear();
    }
  };

}));