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.

Ovu skriptu ne treba izravno instalirati. To je biblioteka za druge skripte koje se uključuju u meta direktivu // @require https://update.greasyfork.org/scripts/591381/1902888/LS%20%28Local%20Storage%29.js

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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();
    }
  };

}));