Temporary-Script-Storage

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

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.greasyfork.org/scripts/562172/1881822/Temporary-Script-Storage.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

作者
JasonMel
版本
1.0.4
建立日期
2026-01-11
更新日期
2026-07-21
尺寸
31.2 KB
授權條款
MIT (https://mit-license.org/)

透過此類別的實例設定和存取的儲存空間將僅在您在建構函式中設定的生命週期內存在,但至少必須是一天。預設值為 30 天。之後,當呼叫 sweepExpiredEntries() 時,它將過期並被刪除,您可以使用 setInterval() 排程此呼叫。

此程式庫對透過 GM 的 setValue() 直接設定的指令碼儲存空間沒有任何影響。這樣的儲存空間將正常運作。

使用範例:

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