Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fork Sync: Update from parent repository #171

Merged
merged 6 commits into from
Sep 28, 2023
Merged

Conversation

github-actions[bot]
Copy link

@github-actions github-actions bot commented Sep 26, 2023

diff --git a/assets/assets.json b/assets/assets.json
index 9abb75a32..f644767a5 100644
--- a/assets/assets.json
+++ b/assets/assets.json
@@ -221,13 +221,13 @@
 		"group": "malware",
 		"title": "Online Malicious URL Blocklist",
 		"contentURL": [
-			"https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-online.txt",
+			"https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-ag-online.txt",
 			"assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt"
 		],
 		"cdnURLs": [
-			"https://curbengh.github.io/malware-filter/urlhaus-filter-online.txt",
-			"https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-online.txt",
-			"https://malware-filter.pages.dev/urlhaus-filter-online.txt"
+			"https://curbengh.github.io/malware-filter/urlhaus-filter-ag-online.txt",
+			"https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-ag-online.txt",
+			"https://malware-filter.pages.dev/urlhaus-filter-ag-online.txt"
 		],
 		"supportURL": "https://gitlab.com/malware-filter/urlhaus-filter#malicious-url-blocklist"
 	},
@@ -244,19 +244,6 @@
 		],
 		"supportURL": "https://gitlab.com/malware-filter/phishing-filter#phishing-url-blocklist"
 	},
-	"curben-pup": {
-		"content": "filters",
-		"group": "malware",
-		"off": true,
-		"title": "PUP Domains Blocklist",
-		"contentURL": "https://malware-filter.gitlab.io/pup-filter/pup-filter.txt",
-		"cdnURLs": [
-			"https://curbengh.github.io/pup-filter/pup-filter.txt",
-			"https://malware-filter.gitlab.io/pup-filter/pup-filter.txt",
-			"https://pup-filter.pages.dev/pup-filter.txt"
-		],
-		"supportURL": "https://gitlab.com/malware-filter/pup-filter#pup-domains-blocklist"
-	},
 	"adguard-social": {
 		"content": "filters",
 		"group": "annoyances",
diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js
index aecae66d8..e22b8950e 100644
--- a/assets/resources/scriptlets.js
+++ b/assets/resources/scriptlets.js
@@ -68,7 +68,7 @@ function safeSelf() {
             if ( pattern === '' ) {
                 return { matchAll: true };
             }
-            const expect = (options.canNegate === true && pattern.startsWith('!') === false);
+            const expect = (options.canNegate !== true || pattern.startsWith('!') === false);
             if ( expect === false ) {
                 pattern = pattern.slice(1);
             }
@@ -1441,11 +1441,12 @@ function evaldataPrune(
 /******************************************************************************/
 
 builtinScriptlets.push({
-    name: 'nano-setInterval-booster.js',
+    name: 'adjust-setInterval.js',
     aliases: [
+        'nano-setInterval-booster.js',
         'nano-sib.js',
     ],
-    fn: nanoSetIntervalBooster,
+    fn: adjustSetInterval,
     dependencies: [
         'safe-self.fn',
     ],
@@ -1462,7 +1463,7 @@ builtinScriptlets.push({
 // boostRatio - The delay multiplier when there is a match, 0.5 speeds up by
 //      2 times and 2 slows down by 2 times, defaults to 0.05 or speed up
 //      20 times. Speed up and down both cap at 50 times.
-function nanoSetIntervalBooster(
+function adjustSetInterval(
     needleArg = '',
     delayArg = '',
     boostArg = ''
@@ -1493,11 +1494,12 @@ function nanoSetIntervalBooster(
 /******************************************************************************/
 
 builtinScriptlets.push({
-    name: 'nano-setTimeout-booster.js',
+    name: 'adjust-setTimeout.js',
     aliases: [
+        'nano-setTimeout-booster.js',
         'nano-stb.js',
     ],
-    fn: nanoSetTimeoutBooster,
+    fn: adjustSetTimeout,
     dependencies: [
         'safe-self.fn',
     ],
@@ -1515,7 +1517,7 @@ builtinScriptlets.push({
 // boostRatio - The delay multiplier when there is a match, 0.5 speeds up by
 //      2 times and 2 slows down by 2 times, defaults to 0.05 or speed up
 //      20 times. Speed up and down both cap at 50 times.
-function nanoSetTimeoutBooster(
+function adjustSetTimeout(
     needleArg = '',
     delayArg = '',
     boostArg = ''
@@ -1650,15 +1652,18 @@ function noFetchIf(
 /******************************************************************************/
 
 builtinScriptlets.push({
-    name: 'refresh-defuser.js',
-    fn: refreshDefuser,
+    name: 'prevent-refresh.js',
+    aliases: [
+        'refresh-defuser.js',
+    ],
+    fn: preventRefresh,
     world: 'ISOLATED',
     dependencies: [
         'run-at.fn',
     ],
 });
 // https://www.reddit.com/r/uBlockOrigin/comments/q0frv0/while_reading_a_sports_article_i_was_redirected/hf7wo9v/
-function refreshDefuser(
+function preventRefresh(
     arg1 = ''
 ) {
     if ( typeof arg1 !== 'string' ) { return; }
@@ -2294,8 +2299,12 @@ function noWindowOpenIf(
 /******************************************************************************/
 
 builtinScriptlets.push({
-    name: 'window-close-if.js',
-    fn: windowCloseIf,
+    name: 'close-window.js',
+    aliases: [
+        'window-close-if.js',
+    ],
+    fn: closeWindow,
+    world: 'ISOLATED',
     dependencies: [
         'safe-self.fn',
     ],
@@ -2303,7 +2312,7 @@ builtinScriptlets.push({
 // https://github.com/uBlockOrigin/uAssets/issues/10323#issuecomment-992312847
 // https://github.com/AdguardTeam/Scriptlets/issues/158
 // https://github.com/uBlockOrigin/uBlock-issues/discussions/2270
-function windowCloseIf(
+function closeWindow(
     arg1 = ''
 ) {
     if ( typeof arg1 !== 'string' ) { return; }
@@ -3379,6 +3388,70 @@ function setAttr(
     runAt(( ) => { start(); }, 'idle');
 }
 
+/*******************************************************************************
+ * 
+ * @scriptlet prevent-canvas
+ * 
+ * @description
+ * Prevent usage of specific or all (default) canvas APIs.
+ *
+ * ### Syntax
+ * 
+ * ```text
+ * example.com##+js(prevent-canvas [, contextType])
+ * ```
+ * 
+ * - `contextType`: A specific type of canvas API to prevent (default to all
+ *   APIs). Can be a string or regex which will be matched against the type
+ *   used in getContext() call. Prepend with `!` to test for no-match.
+ * 
+ * ### Examples
+ * 
+ * 1. Prevent `example.com` from accessing all canvas APIs
+ * 
+ * ```adblock
+ * example.com##+js(prevent-canvas)
+ * ```
+ * 
+ * 2. Prevent access to any flavor of WebGL API, everywhere
+ * 
+ * ```adblock
+ * *##+js(prevent-canvas, /webgl/)
+ * ```
+ * 
+ * 3. Prevent `example.com` from accessing any flavor of canvas API except `2d`
+ * 
+ * ```adblock
+ * example.com##+js(prevent-canvas, !2d)
+ * ```
+ * 
+ * ### References
+ * 
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
+ * 
+ * */
+
+builtinScriptlets.push({
+    name: 'prevent-canvas.js',
+    fn: preventCanvas,
+    dependencies: [
+        'safe-self.fn',
+    ],
+});
+function preventCanvas(
+    contextType = ''
+) {
+    const safe = safeSelf();
+    const pattern = safe.initPattern(contextType, { canNegate: true });
+    const proto = globalThis.HTMLCanvasElement.prototype;
+    proto.getContext = new Proxy(proto.getContext, {
+        apply(target, thisArg, args) {
+            if ( safe.testPattern(pattern, args[0]) ) { return null; }
+            return Reflect.apply(target, thisArg, args);
+        }
+    });
+}
+
 
 /*******************************************************************************
  * 

Prevent usage of specific or all (default) canvas APIs.

Syntax

```text
example.com##+js(prevent-canvas [, contextType])
```

- `contextType`: A specific type of canvas API to prevent (default to all
  APIs). Can be a string or regex which will be matched against the type
  used in getContext() call. Prepend with `!` to test for no-match.

Examples

1. Prevent `example.com` from accessing all canvas APIs

```adblock
example.com##+js(prevent-canvas)
```

2. Prevent access to any flavor of WebGL API, everywhere

```adblock
*##+js(prevent-canvas, /webgl/)
```

3. Prevent `example.com` from accessing any flavor of canvas API except `2d`

```adblock
example.com##+js(prevent-canvas, !2d)
```

References

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
Copy link
Collaborator

@pes10k pes10k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

  • new canvas scriptlet
  • list changes

@thypon thypon merged commit bbf41a1 into brave:master Sep 28, 2023
antonok-edm added a commit that referenced this pull request Oct 3, 2023
done manually to unbreak history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants