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.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greasyfork.org/scripts/591381/1902888/LS%20%28Local%20Storage%29.js

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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

}));