@browserless.io/browserless 2.24.1 → 2.24.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -4
- package/README.md +3 -4
- package/build/browsers/browsers.playwright.js +6 -1
- package/build/browsers/index.js +1 -1
- package/build/routes/chrome/http/content.post.body.json +8 -8
- package/build/routes/chrome/http/pdf.post.body.json +8 -8
- package/build/routes/chrome/http/scrape.post.body.json +8 -8
- package/build/routes/chrome/http/screenshot.post.body.json +8 -8
- package/build/routes/chromium/http/content.post.body.json +8 -8
- package/build/routes/chromium/http/pdf.post.body.json +8 -8
- package/build/routes/chromium/http/scrape.post.body.json +8 -8
- package/build/routes/chromium/http/screenshot.post.body.json +8 -8
- package/build/routes/management/http/meta.get.js +3 -1
- package/extensions/ublock/_locales/ar/messages.json +3 -3
- package/extensions/ublock/_locales/bg/messages.json +1 -1
- package/extensions/ublock/_locales/br_FR/messages.json +2 -2
- package/extensions/ublock/_locales/cy/messages.json +11 -11
- package/extensions/ublock/_locales/el/messages.json +2 -2
- package/extensions/ublock/_locales/hu/messages.json +1 -1
- package/extensions/ublock/_locales/id/messages.json +1 -1
- package/extensions/ublock/_locales/lv/messages.json +4 -4
- package/extensions/ublock/_locales/mk/messages.json +130 -130
- package/extensions/ublock/_locales/oc/messages.json +1 -1
- package/extensions/ublock/_locales/pt_BR/messages.json +1 -1
- package/extensions/ublock/_locales/pt_PT/messages.json +2 -2
- package/extensions/ublock/_locales/si/messages.json +100 -100
- package/extensions/ublock/_locales/sr/messages.json +4 -4
- package/extensions/ublock/_locales/vi/messages.json +19 -19
- package/extensions/ublock/_locales/zh_TW/messages.json +28 -28
- package/extensions/ublock/assets/assets.json +33 -29
- package/extensions/ublock/assets/thirdparties/easylist/easylist.txt +2984 -3287
- package/extensions/ublock/assets/thirdparties/easylist/easyprivacy.txt +150 -171
- package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/serverlist +37 -27
- package/extensions/ublock/assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat +802 -888
- package/extensions/ublock/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt +2355 -2071
- package/extensions/ublock/assets/ublock/badlists.txt +9 -1
- package/extensions/ublock/assets/ublock/badware.min.txt +354 -243
- package/extensions/ublock/assets/ublock/filters.min.txt +5837 -5737
- package/extensions/ublock/assets/ublock/privacy.min.txt +151 -38
- package/extensions/ublock/assets/ublock/quick-fixes.min.txt +83 -127
- package/extensions/ublock/assets/ublock/unbreak.min.txt +66 -50
- package/extensions/ublock/css/codemirror.css +4 -0
- package/extensions/ublock/document-blocked.html +3 -1
- package/extensions/ublock/js/arglist-parser.js +116 -0
- package/extensions/ublock/js/background.js +1 -1
- package/extensions/ublock/js/logger-ui.js +1 -1
- package/extensions/ublock/js/messaging.js +9 -2
- package/extensions/ublock/js/pagestore.js +3 -1
- package/extensions/ublock/js/redirect-engine.js +3 -1
- package/extensions/ublock/{assets/resources/set-attr.js → js/resources/attribute.js} +115 -11
- package/extensions/ublock/js/resources/base.js +38 -0
- package/extensions/ublock/js/resources/cookie.js +419 -0
- package/extensions/ublock/js/resources/href-sanitizer.js +188 -0
- package/extensions/ublock/js/resources/localstorage.js +235 -0
- package/extensions/ublock/js/resources/parse-replace.js +54 -0
- package/extensions/ublock/js/resources/prevent-settimeout.js +236 -0
- package/extensions/ublock/js/resources/proxy-apply.js +109 -0
- package/extensions/ublock/js/resources/replace-argument.js +120 -0
- package/extensions/ublock/{assets → js}/resources/run-at.js +20 -4
- package/extensions/ublock/{assets → js}/resources/safe-self.js +5 -4
- package/extensions/ublock/{assets → js}/resources/scriptlets.js +90 -1589
- package/extensions/ublock/js/resources/set-constant.js +287 -0
- package/extensions/ublock/js/resources/shared.js +44 -0
- package/extensions/ublock/js/resources/spoof-css.js +163 -0
- package/extensions/ublock/js/s14e-serializer.js +2 -1
- package/extensions/ublock/js/scriptlet-filtering-core.js +1 -1
- package/extensions/ublock/js/scriptlet-filtering.js +1 -31
- package/extensions/ublock/js/static-dnr-filtering.js +143 -129
- package/extensions/ublock/js/static-filtering-parser.js +27 -117
- package/extensions/ublock/js/static-net-filtering.js +53 -141
- package/extensions/ublock/js/traffic.js +1 -1
- package/extensions/ublock/js/urlskip.js +166 -0
- package/extensions/ublock/js/vapi-background-ext.js +38 -14
- package/extensions/ublock/manifest.json +1 -1
- package/package.json +12 -12
- package/src/browsers/browsers.playwright.ts +8 -1
- package/src/browsers/index.ts +1 -1
- package/src/routes/management/http/meta.get.ts +6 -1
- package/src/routes/management/http/static.get.ts +1 -1
- package/static/docs/swagger.json +10 -10
- package/static/docs/swagger.min.json +9 -9
- package/static/function/client.js +66 -186
- package/static/function/index.html +66 -186
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/*******************************************************************************
|
|
2
|
+
|
|
3
|
+
uBlock Origin - a comprehensive, efficient content blocker
|
|
4
|
+
Copyright (C) 2019-present Raymond Hill
|
|
5
|
+
|
|
6
|
+
This program is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
This program is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU General Public License
|
|
17
|
+
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
18
|
+
|
|
19
|
+
Home: https://github.com/gorhill/uBlock
|
|
20
|
+
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { registerScriptlet } from './base.js';
|
|
24
|
+
import { runAt } from './run-at.js';
|
|
25
|
+
import { safeSelf } from './safe-self.js';
|
|
26
|
+
import { urlSkip } from '../urlskip.js';
|
|
27
|
+
|
|
28
|
+
/******************************************************************************/
|
|
29
|
+
|
|
30
|
+
registerScriptlet(urlSkip, {
|
|
31
|
+
name: 'urlskip.fn',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @scriptlet href-sanitizer
|
|
36
|
+
*
|
|
37
|
+
* @description
|
|
38
|
+
* Set the `href` attribute to a value found in the DOM at, or below the
|
|
39
|
+
* targeted `a` element, and optionally with transformation steps.
|
|
40
|
+
*
|
|
41
|
+
* @param selector
|
|
42
|
+
* A plain CSS selector for elements which `href` property must be sanitized.
|
|
43
|
+
*
|
|
44
|
+
* @param source
|
|
45
|
+
* One or more tokens to lookup the source of the `href` property, and
|
|
46
|
+
* optionally the transformation steps to perform:
|
|
47
|
+
* - `text`: Use the text content of the element as the URL
|
|
48
|
+
* - `[name]`: Use the value of the attribute `name` as the URL
|
|
49
|
+
* - Transformation steps: see `urlskip` documentation
|
|
50
|
+
*
|
|
51
|
+
* If `text` or `[name]` is not present, the URL will be the value of `href`
|
|
52
|
+
* attribute.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* `example.org##+js(href-sanitizer, a)`
|
|
56
|
+
* `example.org##+js(href-sanitizer, a[title], [title])`
|
|
57
|
+
* `example.org##+js(href-sanitizer, a[href*="/away.php?to="], ?to)`
|
|
58
|
+
* `example.org##+js(href-sanitizer, a[href*="/redirect"], ?url ?url -base64)`
|
|
59
|
+
*
|
|
60
|
+
* */
|
|
61
|
+
|
|
62
|
+
function hrefSanitizer(
|
|
63
|
+
selector = '',
|
|
64
|
+
source = ''
|
|
65
|
+
) {
|
|
66
|
+
if ( typeof selector !== 'string' ) { return; }
|
|
67
|
+
if ( selector === '' ) { return; }
|
|
68
|
+
const safe = safeSelf();
|
|
69
|
+
const logPrefix = safe.makeLogPrefix('href-sanitizer', selector, source);
|
|
70
|
+
if ( source === '' ) { source = 'text'; }
|
|
71
|
+
const sanitizeCopycats = (href, text) => {
|
|
72
|
+
let elems = [];
|
|
73
|
+
try {
|
|
74
|
+
elems = document.querySelectorAll(`a[href="${href}"`);
|
|
75
|
+
}
|
|
76
|
+
catch(ex) {
|
|
77
|
+
}
|
|
78
|
+
for ( const elem of elems ) {
|
|
79
|
+
elem.setAttribute('href', text);
|
|
80
|
+
}
|
|
81
|
+
return elems.length;
|
|
82
|
+
};
|
|
83
|
+
const validateURL = text => {
|
|
84
|
+
if ( typeof text !== 'string' ) { return ''; }
|
|
85
|
+
if ( text === '' ) { return ''; }
|
|
86
|
+
if ( /[\x00-\x20\x7f]/.test(text) ) { return ''; }
|
|
87
|
+
try {
|
|
88
|
+
const url = new URL(text, document.location);
|
|
89
|
+
return url.href;
|
|
90
|
+
} catch(ex) {
|
|
91
|
+
}
|
|
92
|
+
return '';
|
|
93
|
+
};
|
|
94
|
+
const extractParam = (href, source) => {
|
|
95
|
+
if ( Boolean(source) === false ) { return href; }
|
|
96
|
+
const recursive = source.includes('?', 1);
|
|
97
|
+
const end = recursive ? source.indexOf('?', 1) : source.length;
|
|
98
|
+
try {
|
|
99
|
+
const url = new URL(href, document.location);
|
|
100
|
+
let value = url.searchParams.get(source.slice(1, end));
|
|
101
|
+
if ( value === null ) { return href }
|
|
102
|
+
if ( recursive ) { return extractParam(value, source.slice(end)); }
|
|
103
|
+
return value;
|
|
104
|
+
} catch(x) {
|
|
105
|
+
}
|
|
106
|
+
return href;
|
|
107
|
+
};
|
|
108
|
+
const extractURL = (elem, source) => {
|
|
109
|
+
if ( /^\[.*\]$/.test(source) ) {
|
|
110
|
+
return elem.getAttribute(source.slice(1,-1).trim()) || '';
|
|
111
|
+
}
|
|
112
|
+
if ( source === 'text' ) {
|
|
113
|
+
return elem.textContent
|
|
114
|
+
.replace(/^[^\x21-\x7e]+/, '') // remove leading invalid characters
|
|
115
|
+
.replace(/[^\x21-\x7e]+$/, '') // remove trailing invalid characters
|
|
116
|
+
;
|
|
117
|
+
}
|
|
118
|
+
if ( source.startsWith('?') === false ) { return ''; }
|
|
119
|
+
const steps = source.replace(/(\S)\?/g, '\\1?').split(/\s+/);
|
|
120
|
+
const url = steps.length === 1
|
|
121
|
+
? extractParam(elem.href, source)
|
|
122
|
+
: urlSkip(elem.href, false, steps);
|
|
123
|
+
if ( url === undefined ) { return; }
|
|
124
|
+
return url.replace(/ /g, '%20');
|
|
125
|
+
};
|
|
126
|
+
const sanitize = ( ) => {
|
|
127
|
+
let elems = [];
|
|
128
|
+
try {
|
|
129
|
+
elems = document.querySelectorAll(selector);
|
|
130
|
+
}
|
|
131
|
+
catch(ex) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
for ( const elem of elems ) {
|
|
135
|
+
if ( elem.localName !== 'a' ) { continue; }
|
|
136
|
+
if ( elem.hasAttribute('href') === false ) { continue; }
|
|
137
|
+
const href = elem.getAttribute('href');
|
|
138
|
+
const text = extractURL(elem, source);
|
|
139
|
+
const hrefAfter = validateURL(text);
|
|
140
|
+
if ( hrefAfter === '' ) { continue; }
|
|
141
|
+
if ( hrefAfter === href ) { continue; }
|
|
142
|
+
elem.setAttribute('href', hrefAfter);
|
|
143
|
+
const count = sanitizeCopycats(href, hrefAfter);
|
|
144
|
+
safe.uboLog(logPrefix, `Sanitized ${count+1} links to\n${hrefAfter}`);
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
};
|
|
148
|
+
let observer, timer;
|
|
149
|
+
const onDomChanged = mutations => {
|
|
150
|
+
if ( timer !== undefined ) { return; }
|
|
151
|
+
let shouldSanitize = false;
|
|
152
|
+
for ( const mutation of mutations ) {
|
|
153
|
+
if ( mutation.addedNodes.length === 0 ) { continue; }
|
|
154
|
+
for ( const node of mutation.addedNodes ) {
|
|
155
|
+
if ( node.nodeType !== 1 ) { continue; }
|
|
156
|
+
shouldSanitize = true;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
if ( shouldSanitize ) { break; }
|
|
160
|
+
}
|
|
161
|
+
if ( shouldSanitize === false ) { return; }
|
|
162
|
+
timer = safe.onIdle(( ) => {
|
|
163
|
+
timer = undefined;
|
|
164
|
+
sanitize();
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const start = ( ) => {
|
|
168
|
+
if ( sanitize() === false ) { return; }
|
|
169
|
+
observer = new MutationObserver(onDomChanged);
|
|
170
|
+
observer.observe(document.body, {
|
|
171
|
+
subtree: true,
|
|
172
|
+
childList: true,
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
runAt(( ) => { start(); }, 'interactive');
|
|
176
|
+
}
|
|
177
|
+
registerScriptlet(hrefSanitizer, {
|
|
178
|
+
name: 'href-sanitizer.js',
|
|
179
|
+
world: 'ISOLATED',
|
|
180
|
+
aliases: [
|
|
181
|
+
'urlskip.js',
|
|
182
|
+
],
|
|
183
|
+
dependencies: [
|
|
184
|
+
runAt,
|
|
185
|
+
safeSelf,
|
|
186
|
+
urlSkip,
|
|
187
|
+
],
|
|
188
|
+
});
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/*******************************************************************************
|
|
2
|
+
|
|
3
|
+
uBlock Origin - a comprehensive, efficient content blocker
|
|
4
|
+
Copyright (C) 2019-present Raymond Hill
|
|
5
|
+
|
|
6
|
+
This program is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
This program is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU General Public License
|
|
17
|
+
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
18
|
+
|
|
19
|
+
Home: https://github.com/gorhill/uBlock
|
|
20
|
+
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { getSafeCookieValuesFn } from './cookie.js';
|
|
24
|
+
import { registerScriptlet } from './base.js';
|
|
25
|
+
import { safeSelf } from './safe-self.js';
|
|
26
|
+
|
|
27
|
+
/******************************************************************************/
|
|
28
|
+
|
|
29
|
+
export function getAllLocalStorageFn(which = 'localStorage') {
|
|
30
|
+
const storage = self[which];
|
|
31
|
+
const out = [];
|
|
32
|
+
for ( let i = 0; i < storage.length; i++ ) {
|
|
33
|
+
const key = storage.key(i);
|
|
34
|
+
const value = storage.getItem(key);
|
|
35
|
+
return { key, value };
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
registerScriptlet(getAllLocalStorageFn, {
|
|
40
|
+
name: 'get-all-local-storage.fn',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/******************************************************************************/
|
|
44
|
+
|
|
45
|
+
export function setLocalStorageItemFn(
|
|
46
|
+
which = 'local',
|
|
47
|
+
trusted = false,
|
|
48
|
+
key = '',
|
|
49
|
+
value = '',
|
|
50
|
+
) {
|
|
51
|
+
if ( key === '' ) { return; }
|
|
52
|
+
|
|
53
|
+
// For increased compatibility with AdGuard
|
|
54
|
+
if ( value === 'emptyArr' ) {
|
|
55
|
+
value = '[]';
|
|
56
|
+
} else if ( value === 'emptyObj' ) {
|
|
57
|
+
value = '{}';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const trustedValues = [
|
|
61
|
+
'',
|
|
62
|
+
'undefined', 'null',
|
|
63
|
+
'{}', '[]', '""',
|
|
64
|
+
'$remove$',
|
|
65
|
+
...getSafeCookieValuesFn(),
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
if ( trusted ) {
|
|
69
|
+
if ( value.includes('$now$') ) {
|
|
70
|
+
value = value.replaceAll('$now$', Date.now());
|
|
71
|
+
}
|
|
72
|
+
if ( value.includes('$currentDate$') ) {
|
|
73
|
+
value = value.replaceAll('$currentDate$', `${Date()}`);
|
|
74
|
+
}
|
|
75
|
+
if ( value.includes('$currentISODate$') ) {
|
|
76
|
+
value = value.replaceAll('$currentISODate$', (new Date()).toISOString());
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
const normalized = value.toLowerCase();
|
|
80
|
+
const match = /^("?)(.+)\1$/.exec(normalized);
|
|
81
|
+
const unquoted = match && match[2] || normalized;
|
|
82
|
+
if ( trustedValues.includes(unquoted) === false ) {
|
|
83
|
+
if ( /^-?\d+$/.test(unquoted) === false ) { return; }
|
|
84
|
+
const n = parseInt(unquoted, 10) || 0;
|
|
85
|
+
if ( n < -32767 || n > 32767 ) { return; }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const storage = self[`${which}Storage`];
|
|
91
|
+
if ( value === '$remove$' ) {
|
|
92
|
+
const safe = safeSelf();
|
|
93
|
+
const pattern = safe.patternToRegex(key, undefined, true );
|
|
94
|
+
const toRemove = [];
|
|
95
|
+
for ( let i = 0, n = storage.length; i < n; i++ ) {
|
|
96
|
+
const key = storage.key(i);
|
|
97
|
+
if ( pattern.test(key) ) { toRemove.push(key); }
|
|
98
|
+
}
|
|
99
|
+
for ( const key of toRemove ) {
|
|
100
|
+
storage.removeItem(key);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
storage.setItem(key, `${value}`);
|
|
104
|
+
}
|
|
105
|
+
} catch(ex) {
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
registerScriptlet(setLocalStorageItemFn, {
|
|
109
|
+
name: 'set-local-storage-item.fn',
|
|
110
|
+
dependencies: [
|
|
111
|
+
getSafeCookieValuesFn,
|
|
112
|
+
safeSelf,
|
|
113
|
+
],
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/******************************************************************************/
|
|
117
|
+
|
|
118
|
+
export function removeCacheStorageItem(
|
|
119
|
+
cacheNamePattern = '',
|
|
120
|
+
requestPattern = ''
|
|
121
|
+
) {
|
|
122
|
+
if ( cacheNamePattern === '' ) { return; }
|
|
123
|
+
const safe = safeSelf();
|
|
124
|
+
const logPrefix = safe.makeLogPrefix('remove-cache-storage-item', cacheNamePattern, requestPattern);
|
|
125
|
+
const cacheStorage = self.caches;
|
|
126
|
+
if ( cacheStorage instanceof Object === false ) { return; }
|
|
127
|
+
const reCache = safe.patternToRegex(cacheNamePattern, undefined, true);
|
|
128
|
+
const reRequest = safe.patternToRegex(requestPattern, undefined, true);
|
|
129
|
+
cacheStorage.keys().then(cacheNames => {
|
|
130
|
+
for ( const cacheName of cacheNames ) {
|
|
131
|
+
if ( reCache.test(cacheName) === false ) { continue; }
|
|
132
|
+
if ( requestPattern === '' ) {
|
|
133
|
+
cacheStorage.delete(cacheName).then(result => {
|
|
134
|
+
if ( safe.logLevel > 1 ) {
|
|
135
|
+
safe.uboLog(logPrefix, `Deleting ${cacheName}`);
|
|
136
|
+
}
|
|
137
|
+
if ( result !== true ) { return; }
|
|
138
|
+
safe.uboLog(logPrefix, `Deleted ${cacheName}: ${result}`);
|
|
139
|
+
});
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
cacheStorage.open(cacheName).then(cache => {
|
|
143
|
+
cache.keys().then(requests => {
|
|
144
|
+
for ( const request of requests ) {
|
|
145
|
+
if ( reRequest.test(request.url) === false ) { continue; }
|
|
146
|
+
if ( safe.logLevel > 1 ) {
|
|
147
|
+
safe.uboLog(logPrefix, `Deleting ${cacheName}/${request.url}`);
|
|
148
|
+
}
|
|
149
|
+
cache.delete(request).then(result => {
|
|
150
|
+
if ( result !== true ) { return; }
|
|
151
|
+
safe.uboLog(logPrefix, `Deleted ${cacheName}/${request.url}: ${result}`);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
registerScriptlet(removeCacheStorageItem, {
|
|
160
|
+
name: 'remove-cache-storage-item.fn',
|
|
161
|
+
world: 'ISOLATED',
|
|
162
|
+
dependencies: [
|
|
163
|
+
safeSelf,
|
|
164
|
+
],
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
/*******************************************************************************
|
|
168
|
+
*
|
|
169
|
+
* set-local-storage-item.js
|
|
170
|
+
* set-session-storage-item.js
|
|
171
|
+
*
|
|
172
|
+
* Set a local/session storage entry to a specific, allowed value.
|
|
173
|
+
*
|
|
174
|
+
* Reference:
|
|
175
|
+
* https://github.com/AdguardTeam/Scriptlets/blob/master/src/scriptlets/set-local-storage-item.js
|
|
176
|
+
* https://github.com/AdguardTeam/Scriptlets/blob/master/src/scriptlets/set-session-storage-item.js
|
|
177
|
+
*
|
|
178
|
+
**/
|
|
179
|
+
|
|
180
|
+
export function setLocalStorageItem(key = '', value = '') {
|
|
181
|
+
setLocalStorageItemFn('local', false, key, value);
|
|
182
|
+
}
|
|
183
|
+
registerScriptlet(setLocalStorageItem, {
|
|
184
|
+
name: 'set-local-storage-item.js',
|
|
185
|
+
world: 'ISOLATED',
|
|
186
|
+
dependencies: [
|
|
187
|
+
setLocalStorageItemFn,
|
|
188
|
+
],
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
export function setSessionStorageItem(key = '', value = '') {
|
|
192
|
+
setLocalStorageItemFn('session', false, key, value);
|
|
193
|
+
}
|
|
194
|
+
registerScriptlet(setSessionStorageItem, {
|
|
195
|
+
name: 'set-session-storage-item.js',
|
|
196
|
+
world: 'ISOLATED',
|
|
197
|
+
dependencies: [
|
|
198
|
+
setLocalStorageItemFn,
|
|
199
|
+
],
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
/*******************************************************************************
|
|
203
|
+
*
|
|
204
|
+
* trusted-set-local-storage-item.js
|
|
205
|
+
*
|
|
206
|
+
* Set a local storage entry to an arbitrary value.
|
|
207
|
+
*
|
|
208
|
+
* Reference:
|
|
209
|
+
* https://github.com/AdguardTeam/Scriptlets/blob/master/src/scriptlets/trusted-set-local-storage-item.js
|
|
210
|
+
*
|
|
211
|
+
**/
|
|
212
|
+
|
|
213
|
+
export function trustedSetLocalStorageItem(key = '', value = '') {
|
|
214
|
+
setLocalStorageItemFn('local', true, key, value);
|
|
215
|
+
}
|
|
216
|
+
registerScriptlet(trustedSetLocalStorageItem, {
|
|
217
|
+
name: 'trusted-set-local-storage-item.js',
|
|
218
|
+
requiresTrust: true,
|
|
219
|
+
world: 'ISOLATED',
|
|
220
|
+
dependencies: [
|
|
221
|
+
setLocalStorageItemFn,
|
|
222
|
+
],
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
export function trustedSetSessionStorageItem(key = '', value = '') {
|
|
226
|
+
setLocalStorageItemFn('session', true, key, value);
|
|
227
|
+
}
|
|
228
|
+
registerScriptlet(trustedSetSessionStorageItem, {
|
|
229
|
+
name: 'trusted-set-session-storage-item.js',
|
|
230
|
+
requiresTrust: true,
|
|
231
|
+
world: 'ISOLATED',
|
|
232
|
+
dependencies: [
|
|
233
|
+
setLocalStorageItemFn,
|
|
234
|
+
],
|
|
235
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*******************************************************************************
|
|
2
|
+
|
|
3
|
+
uBlock Origin - a comprehensive, efficient content blocker
|
|
4
|
+
Copyright (C) 2019-present Raymond Hill
|
|
5
|
+
|
|
6
|
+
This program is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
This program is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU General Public License
|
|
17
|
+
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
18
|
+
|
|
19
|
+
Home: https://github.com/gorhill/uBlock
|
|
20
|
+
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { createArglistParser } from './shared.js';
|
|
24
|
+
import { registerScriptlet } from './base.js';
|
|
25
|
+
|
|
26
|
+
/******************************************************************************/
|
|
27
|
+
|
|
28
|
+
export function parseReplaceFn(s) {
|
|
29
|
+
if ( s.charCodeAt(0) !== 0x2F /* / */ ) { return; }
|
|
30
|
+
const parser = createArglistParser('/');
|
|
31
|
+
parser.nextArg(s, 1);
|
|
32
|
+
let pattern = s.slice(parser.argBeg, parser.argEnd);
|
|
33
|
+
if ( parser.transform ) {
|
|
34
|
+
pattern = parser.normalizeArg(pattern);
|
|
35
|
+
}
|
|
36
|
+
if ( pattern === '' ) { return; }
|
|
37
|
+
parser.nextArg(s, parser.separatorEnd);
|
|
38
|
+
let replacement = s.slice(parser.argBeg, parser.argEnd);
|
|
39
|
+
if ( parser.separatorEnd === parser.separatorBeg ) { return; }
|
|
40
|
+
if ( parser.transform ) {
|
|
41
|
+
replacement = parser.normalizeArg(replacement);
|
|
42
|
+
}
|
|
43
|
+
const flags = s.slice(parser.separatorEnd);
|
|
44
|
+
try {
|
|
45
|
+
return { re: new RegExp(pattern, flags), replacement };
|
|
46
|
+
} catch(_) {
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
registerScriptlet(parseReplaceFn, {
|
|
50
|
+
name: 'parse-replace.fn',
|
|
51
|
+
dependencies: [
|
|
52
|
+
createArglistParser,
|
|
53
|
+
],
|
|
54
|
+
});
|