forked from magicoflolis/Userscript-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.js
More file actions
209 lines (194 loc) · 6.84 KB
/
Copy pathstorage.js
File metadata and controls
209 lines (194 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
'use strict';
import { webext } from './ext.js';
let api = webext.storage.local;
// #region DEFAULT_CONFIG
/**
* @type { import("../typings/types.d.ts").config }
*/
export const DEFAULT_CONFIG = {
autofetch: true,
// autoinject: true,
autoSort: 'daily_installs',
clearTabCache: true,
// cache: true,
// autoexpand: false,
filterlang: false,
sleazyredirect: false,
// time: 10000,
blacklist: ['userjs-local', 'userjs-finance', 'userjs-social', 'userjs-unsupported'],
preview: {
code: false,
metadata: false
},
engines: [
{
enabled: true,
name: 'greasyfork',
query: encodeURIComponent('https://greasyfork.org/scripts/by-site/{host}.json?language=all')
},
{
enabled: false,
name: 'sleazyfork',
query: encodeURIComponent('https://sleazyfork.org/scripts/by-site/{host}.json?language=all')
},
// {
// enabled: false,
// name: 'openuserjs',
// query: encodeURIComponent('https://openuserjs.org/?q={host}')
// },
{
enabled: false,
name: 'github',
token: '',
query: encodeURIComponent(
'https://api.github.com/search/code?q="// ==UserScript=="+{host}+ "// ==/UserScript=="+in:file+language:js&per_page=30'
)
}
],
theme: {
'even-row': '',
'odd-row': '',
'even-err': '',
'odd-err': '',
'background-color': '',
'gf-color': '',
'sf-color': '',
'border-b-color': '',
'gf-btn-color': '',
'sf-btn-color': '',
'sf-txt-color': '',
'txt-color': '',
'chck-color': '',
'chck-gf': '',
'chck-git': '',
'chck-open': '',
placeholder: '',
'position-top': '',
'position-bottom': '',
'position-left': '',
'position-right': '',
'font-family': ''
},
recommend: {
author: true,
others: true
},
filters: {
ASCII: {
enabled: false,
name: 'Non-ASCII',
regExp: '[^\\x00-\\x7F\\s]+'
},
Latin: {
enabled: false,
name: 'Non-Latin',
regExp: '[^\\u0000-\\u024F\\u2000-\\u214F\\s]+'
},
Games: {
enabled: false,
name: 'Games',
flag: 'iu',
regExp:
'Aimbot|AntiGame|Agar|agar\\.io|alis\\.io|angel\\.io|ExtencionRipXChetoMalo|AposBot|DFxLite|ZTx-Lite|AposFeedingBot|AposLoader|Balz|Blah Blah|Orc Clan Script|Astro\\s*Empires|^\\s*Attack|^\\s*Battle|BiteFight|Blood\\s*Wars|Bloble|Bonk|Bots|Bots4|Brawler|\\bBvS\\b|Business\\s*Tycoon|Castle\\s*Age|City\\s*Ville|chopcoin\\.io|Comunio|Conquer\\s*Club|CosmoPulse|cursors\\.io|Dark\\s*Orbit|Dead\\s*Frontier|Diep\\.io|\\bDOA\\b|doblons\\.io|DotD|Dossergame|Dragons\\s*of\\s*Atlantis|driftin\\.io|Dugout|\\bDS[a-z]+\\n|elites\\.io|Empire\\s*Board|eRep(ublik)?|Epicmafia|Epic.*War|ExoPlanet|Falcon Tools|Feuerwache|Farming|FarmVille|Fightinfo|Frontier\\s*Ville|Ghost\\s*Trapper|Gladiatus|Goalline|Gondal|gota\\.io|Grepolis|Hobopolis|\\bhwm(\\b|_)|Ikariam|\\bIT2\\b|Jellyneo|Kapi\\s*Hospital|Kings\\s*Age|Kingdoms?\\s*of|knastv(o|oe)gel|Knight\\s*Fight|\\b(Power)?KoC(Atta?ck)?\\b|\\bKOL\\b|Kongregate|Krunker|Last\\s*Emperor|Legends?\\s*of|Light\\s*Rising|lite\\.ext\\.io|Lockerz|\\bLoU\\b|Mafia\\s*(Wars|Mofo)|Menelgame|Mob\\s*Wars|Mouse\\s*Hunt|Molehill\\s*Empire|MooMoo|MyFreeFarm|narwhale\\.io|Neopets|NeoQuest|Nemexia|\\bOGame\\b|Ogar(io)?|Pardus|Pennergame|Pigskin\\s*Empire|PlayerScripts|pokeradar\\.io|Popmundo|Po?we?r\\s*(Bot|Tools)|PsicoTSI|Ravenwood|Schulterglatze|Skribbl|slither\\.io|slitherplus\\.io|slitheriogameplay|SpaceWars|splix\\.io|Survivio|\\bSW_[a-z]+\\n|\\bSnP\\b|The\\s*Crims|The\\s*West|torto\\.io|Travian|Treasure\\s*Isl(and|e)|Tribal\\s*Wars|TW.?PRO|Vampire\\s*Wars|vertix\\.io|War\\s*of\\s*Ninja|World\\s*of\\s*Tanks|West\\s*Wars|wings\\.io|\\bWoD\\b|World\\s*of\\s*Dungeons|wtf\\s*battles|Wurzelimperium|Yohoho|Zombs'
},
SocialNetworks: {
enabled: false,
name: 'Social Networks',
flag: 'iu',
regExp:
'Face\\s*book|Google(\\+| Plus)|\\bHabbo|Kaskus|\\bLepra|Leprosorium|MySpace|meinVZ|odnoklassniki|Одноклассники|Orkut|sch(ue|ü)ler(VZ|\\.cc)?|studiVZ|Unfriend|Valenth|VK|vkontakte|ВКонтакте|Qzone|Twitter|TweetDeck'
},
Clutter: {
enabled: false,
name: 'Clutter',
flag: 'iu',
regExp:
"^\\s*(.{1,3})\\1+\\n|^\\s*(.+?)\\n+\\2\\n*$|^\\s*.{1,5}\\n|do\\s*n('|o)?t (install|download)|nicht installieren|(just )?(\\ban? |\\b)test(ing|s|\\d|\\b)|^\\s*.{0,4}test.{0,4}\\n|\\ntest(ing)?\\s*|^\\s*(\\{@|Smolka|Hacks)|\\[\\d{4,5}\\]|free\\s*download|theme|(night|dark) ?(mode)?"
}
}
};
// #endregion
/** @type {{ [prefix: string]: StorageArea }} */
export const storageByPrefix = {};
/**
* @param {function} [fnValue] - (value, newKey, obj) => newValue
* @param {function} [fnKey] - (key, val, obj) => newKey (if newKey is falsy the key is skipped)
* @param {Object} [thisObj] - passed as `this` to both functions
* @return {Object}
*/
function mapEntry(fnValue, fnKey, thisObj) {
const res = {};
for (let key of Object.keys(this)) {
const val = this[key];
if (!fnKey || (key = thisObj[fnKey](key, val, this))) {
res[key] = fnValue ? thisObj[fnValue](val, key, this) : val;
}
}
return res;
}
class StorageArea {
constructor(name, prefix) {
storageByPrefix[prefix] = this;
this.name = name;
this.prefix = prefix;
}
/** @return {string} */
toKey(id) {
return this.prefix + id;
}
/** @return {string} */
toId(key) {
return key.startsWith(this.prefix) ? key.slice(this.prefix.length) : '';
}
/**
* @param {string|number} id
* @return {Promise<?>}
*/
async getOne(id) {
const key = this.toKey(id);
return (await api.get([key]))[key];
}
/**
* @param {?string[]} [ids] - if null/absent, the entire storage is returned
* @param {function(val:?,key:string):?} [transform]
* @return {Promise<?>} - single value or object of id:value
*/
async getMulti(ids, transform) {
const keys = ids?.map(this.toKey, this);
const data = await api.get(keys);
return transform || this.prefix ? mapEntry.call(data, transform, 'toId', this) : data;
}
/**
* @param {string|number|Array<string|number>} id
* @return {Promise<void>}
*/
async remove(id) {
const keys = (Array.isArray(id) ? id : [id]).filter(Boolean).map(this.toKey, this);
if (keys.length) await api.remove(keys);
}
async setOne(id, value) {
if (id) return this.set({ [id]: value });
}
/**
* @param {Object} data
* @return {Promise<Object>} same object
*/
async set(data) {
await api.set(this.prefix ? mapEntry.call(data, null, 'toKey', this) : data);
return data;
}
}
const storage = {
get api() {
return api;
},
set api(val) {
api = val;
},
/** @return {?StorageArea} */
forKey: (key) => storageByPrefix[/^\w+:|$/.exec(key)[0]],
base: new StorageArea('base', ''),
config: new StorageArea('config', 'cfg:'),
cache: new StorageArea('cache', 'cac:')
};
export default storage;