Temporary-Script-Storage

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

Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta // @require https://update.greasyfork.org/scripts/562172/1881822/Temporary-Script-Storage.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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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

Tác giả
JasonMel
Phiên bản
1.0.4
Đã tạo
11-01-2026
Đã cập nhật
21-07-2026
Kích thước
30 KB
Giấy phép
MIT (https://mit-license.org/)

Bộ lưu trữ được đặt và truy cập thông qua một instance của lớp này sẽ chỉ tồn tại trong suốt thời gian bạn đặt trong constructor, mặc dù nó phải ít nhất một ngày. Giá trị mặc định là 30 ngày. Sau thời gian đó, nó sẽ hết hạn và bị xóa khi sweepExpiredEntries() được gọi, bạn có thể lên lịch với setInterval().

Thư viện này không có tác dụng đối với bộ lưu trữ script được đặt trực tiếp thông qua setValue() của GM theo cách thông thường. Bộ lưu trữ như vậy sẽ hoạt động bình thường.

Ví dụ sử dụng:

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 {}

Ngoài ra, bất kỳ script nào sử dụng thư viện này phải bao gồm siêu dữ liệu sau:

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

Điều này là cần thiết vì việc đặt những gì mà mỗi thư viện cần trong siêu dữ liệu riêng của nó là không đủ. Kịch bản cấp cao nhất phải cung cấp các @require@grant cần thiết cho tất cả các phụ thuộc của nó.