Temporary-Script-Storage

Sets a maximum age (minimum one day) for script storage values, after which they are deleted

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greasyfork.org/scripts/562172/1881822/Temporary-Script-Storage.js

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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!)

ผู้เขียน
JasonMel
เวอร์ชัน
1.0.4
สร้างเมื่อ
11-01-2026
อัปเดตเมื่อ
21-07-2026
Size
31.2 กิโลไบต์
สัญญาอนุญาต
MIT (https://mit-license.org/)

สตอเรจที่ตั้งค่าและเข้าถึงผ่านอินสแตนซ์ของคลาสนี้จะมีอยู่เท่านั้นตราบเท่าที่อายุการใช้งานที่คุณตั้งค่าไว้ในตัวสร้าง แม้ว่าต้องมีอย่างน้อยหนึ่งวัน ค่าเริ่มต้นคือ 30 วัน หลังจากนั้น มันจะหมดอายุและถูกลบเมื่อเรียก sweepExpiredEntries() ซึ่งคุณสามารถกำหนดตารางได้โดยใช้ setInterval()

ไลบรารีนี้ไม่มีผลต่อสตอเรจของสคริปต์ที่ตั้งค่าโดยตรงผ่าน setValue() ของ GM ในทางปกติ สตอเรจดังกล่าวจะทำงานตามปกติ

ตัวอย่างการใช้งาน:

const persistentStorage = new TTLStorage();
await persistentStorage.ready();
setInterval(() => persistentStorage.sweepExpiredEntries(), 1000 * 60 * 60 * 24);

try { 
  await persistentStorage.set("key1", "hello"); // throws
  const msg = persistentStorage.get("key1");    // fast memory read
  await persistentStorage.delete("key1");       // throws
} catch {}

นอกจากนี้ สคริปต์ใดๆ ที่ใช้ไลบรารีนี้ต้องรวมเมตาดาต้าต่อไปนี้:

// @grant GM.getValue
// @grant GM.setValue
// @grant GM.deleteValue
// @grant GM.listValues
// @grant GM.info

สิ่งนี้จำเป็นเพราะการใส่สิ่งที่ไลบรารีแต่ละคนต้องการในเมตาดาต้าของตัวเองนั้นไม่เพียงพอ สคริปต์ระดับบนสุดต้องระบุ @require และ @grant ที่จำเป็นสำหรับการอ้างอิงทั้งหมด