您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Allows JSON data to be persisted easily by user scripts
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/10443/56962/DataCache%20-%20Simple%20storage%20wrapper.js
- function DataCache(key) {
- this._key = key;
- this._data = {};
- this.load();
- }
- DataCache.prototype = {
- getValue: function(k) {
- return this._data[k];
- },
- setValue: function(k, v) {
- this._data[k] = v;
- this.save();
- },
- deleteValue: function(k) {
- if (k in this._data) {
- delete this._data[k];
- this.save();
- }
- },
- hasValue: function(k) {
- return k in this._data;
- },
- listValues: function() {
- return Object.keys(this._data).sort();
- },
- clear: function() {
- this._data = {};
- this.save();
- },
- save: function() {
- var s = JSON.stringify(this._data);
- GM_setValue(this._key, s);
- console.info('Cache(' + this._key + ') saved: ' + s);
- },
- load: function(s) {
- try {
- this._data = JSON.parse(s || GM_getValue(this._key));
- }
- catch (ex) {
- this.clear();
- }
- },
- edit: function() {
- var res = window.prompt('Edit cached package URLs', JSON.stringify(this._data, null, 2));
- if (res !== null) {
- try {
- this._data = res ? JSON.parse(res) : {};
- this.save();
- }
- catch (ex) {
- console.warn('Failed to update cache data: %s %o', ex.toString(), ex);
- }
- }
- },
- toString: function() {
- return 'Cache(' + this._key + '): [' + this.listValues.join('\n') + ']';
- },
- dump: function() {
- console.log('Cache(' + this._key + '):\n' + JSON.stringify(this._data, null, 2));
- }
- };