Skip to content

Commit 3861d05

Browse files
authored
Merge pull request gorhill#27 from gorhill/master
Re-sync with uBo master
2 parents 28341c8 + c45b93a commit 3861d05

File tree

116 files changed

+976
-576
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+976
-576
lines changed

.github/workflows/main.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: GitHub CI
2+
3+
on:
4+
create:
5+
branches: master
6+
7+
# I used the following project as template to get started:
8+
# https://github.com/dessant/search-by-image/blob/master/.github/workflows/ci.yml
9+
10+
jobs:
11+
build:
12+
name: Build packages
13+
runs-on: ubuntu-latest
14+
if: startsWith(github.ref, 'refs/tags/')
15+
steps:
16+
- name: Clone repository
17+
uses: actions/checkout@v2
18+
with:
19+
persist-credentials: false
20+
- name: Clone uAssets
21+
run: |
22+
pushd ..
23+
git clone --depth 1 https://github.com/uBlockOrigin/uAssets.git
24+
popd
25+
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
26+
- name: Get release information
27+
id: release_info
28+
run: |
29+
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
30+
- name: Create GitHub release
31+
id: create_release
32+
uses: actions/create-release@v1
33+
env:
34+
GITHUB_TOKEN: ${{ github.token }}
35+
with:
36+
tag_name: ${{ steps.release_info.outputs.VERSION }}
37+
release_name: ${{ steps.release_info.outputs.VERSION }}
38+
prerelease: true
39+
- name: Build all packages
40+
run: |
41+
tools/make-chromium.sh ${{ steps.release_info.outputs.VERSION }}
42+
tools/make-firefox.sh ${{ steps.release_info.outputs.VERSION }}
43+
tools/make-thunderbird.sh ${{ steps.release_info.outputs.VERSION }}
44+
- name: Upload Chromium package
45+
uses: actions/upload-release-asset@v1
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
with:
49+
upload_url: ${{ steps.create_release.outputs.upload_url }}
50+
asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.chromium.zip
51+
asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.chromium.zip
52+
asset_content_type: application/octet-stream
53+
- name: Upload Firefox package
54+
uses: actions/upload-release-asset@v1
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
with:
58+
upload_url: ${{ steps.create_release.outputs.upload_url }}
59+
asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.firefox.xpi
60+
asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.firefox.xpi
61+
asset_content_type: application/octet-stream
62+
- name: Upload Thunderbird package
63+
uses: actions/upload-release-asset@v1
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
with:
67+
upload_url: ${{ steps.create_release.outputs.upload_url }}
68+
asset_path: dist/build/uBlock0_${{ steps.release_info.outputs.VERSION }}.thunderbird.xpi
69+
asset_name: uBlock0_${{ steps.release_info.outputs.VERSION }}.thunderbird.xpi
70+
asset_content_type: application/octet-stream

.travis.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

assets/resources/scriptlets.js

Lines changed: 70 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,73 @@
583583
})();
584584

585585

586+
/// no-fetch-if.js
587+
(function() {
588+
let arg1 = '{{1}}';
589+
if ( arg1 === '{{1}}' ) { arg1 = ''; }
590+
const needles = [];
591+
for ( const condition of arg1.split(/\s+/) ) {
592+
if ( condition === '' ) { continue; }
593+
const pos = condition.indexOf(':');
594+
let key, value;
595+
if ( pos !== -1 ) {
596+
key = condition.slice(0, pos);
597+
value = condition.slice(pos + 1);
598+
} else {
599+
key = 'url';
600+
value = condition;
601+
}
602+
if ( value === '' ) {
603+
value = '^';
604+
} else if ( value.startsWith('/') && value.endsWith('/') ) {
605+
value = value.slice(1, -1);
606+
} else {
607+
value = value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
608+
}
609+
needles.push({ key, re: new RegExp(value) });
610+
}
611+
const log = needles.length === 0 ? console.log.bind(console) : undefined;
612+
self.fetch = new Proxy(self.fetch, {
613+
apply: function(target, thisArg, args) {
614+
let proceed = true;
615+
try {
616+
const url = args[0] instanceof self.Request
617+
? args[0].url
618+
: args[0];
619+
const props = new Map([ [ 'url', url ] ]);
620+
const init = args[1];
621+
if ( init instanceof Object ) {
622+
for ( const prop in init ) {
623+
if ( init.hasOwnProperty(prop) === false ) { continue; }
624+
props.set( prop, init[prop]);
625+
}
626+
}
627+
if ( log !== undefined ) {
628+
const out = Array.from(props)
629+
.map(a => `${a[0]}:${a[1]}`)
630+
.join(' ');
631+
log(`uBO: fetch(${out})`);
632+
}
633+
proceed = needles.length === 0;
634+
for ( const { key, re } of needles ) {
635+
if (
636+
props.has(key) === false ||
637+
re.test(props.get(key)) === false
638+
) {
639+
proceed = true;
640+
break;
641+
}
642+
}
643+
} catch(ex) {
644+
}
645+
return proceed
646+
? Reflect.apply(target, thisArg, args)
647+
: Promise.resolve(new Response());
648+
}
649+
});
650+
})();
651+
652+
586653
/// remove-attr.js
587654
/// alias ra.js
588655
(function() {
@@ -593,10 +660,7 @@
593660
if ( selector === '' || selector === '{{2}}' ) {
594661
selector = `[${tokens.join('],[')}]`;
595662
}
596-
const rmattr = function(ev) {
597-
if ( ev ) {
598-
window.removeEventListener(ev.type, rmattr, true);
599-
}
663+
const rmattr = function() {
600664
try {
601665
const nodes = document.querySelectorAll(selector);
602666
for ( const node of nodes ) {
@@ -608,7 +672,7 @@
608672
}
609673
};
610674
if ( document.readyState === 'loading' ) {
611-
window.addEventListener('DOMContentLoaded', rmattr, true);
675+
window.addEventListener('DOMContentLoaded', rmattr, { once: true });
612676
} else {
613677
rmattr();
614678
}
@@ -646,36 +710,6 @@
646710
})();
647711

648712

649-
/// requestAnimationFrame-if.js
650-
/// alias raf-if.js
651-
// Deprecated, use "no-requestAnimationFrame-if.js"
652-
(function() {
653-
let needle = '{{1}}';
654-
const not = needle.charAt(0) === '!';
655-
if ( not ) { needle = needle.slice(1); }
656-
if ( needle === '' || needle === '{{1}}' ) {
657-
needle = '.?';
658-
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
659-
needle = needle.slice(1,-1);
660-
} else {
661-
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
662-
}
663-
const log = needle === '.?' && not === false ? console.log : undefined;
664-
needle = new RegExp(needle);
665-
window.requestAnimationFrame = new Proxy(window.requestAnimationFrame, {
666-
apply: function(target, thisArg, args) {
667-
const a = String(args[0]);
668-
if ( log !== undefined ) {
669-
log('uBO: requestAnimationFrame("%s")', a);
670-
} else if ( needle.test(a) === not ) {
671-
args[0] = function(){};
672-
}
673-
return target.apply(thisArg, args);
674-
}
675-
});
676-
})();
677-
678-
679713
/// no-requestAnimationFrame-if.js
680714
/// alias norafif.js
681715
(function() {
@@ -827,32 +861,6 @@
827861
})();
828862

829863

830-
/// setInterval-defuser.js
831-
/// alias sid.js
832-
(function() {
833-
let needle = '{{1}}';
834-
const delay = parseInt('{{2}}', 10);
835-
if ( needle === '' || needle === '{{1}}' ) {
836-
needle = '.?';
837-
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
838-
needle = needle.slice(1,-1);
839-
} else {
840-
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
841-
}
842-
needle = new RegExp(needle);
843-
window.setInterval = new Proxy(window.setInterval, {
844-
apply: function(target, thisArg, args) {
845-
const a = args[0];
846-
const b = args[1];
847-
if ( (isNaN(delay) || b === delay) && needle.test(a.toString()) ) {
848-
args[0] = function(){};
849-
}
850-
return target.apply(thisArg, args);
851-
}
852-
});
853-
})();
854-
855-
856864
/// no-setInterval-if.js
857865
/// alias nosiif.js
858866
(function() {
@@ -902,34 +910,9 @@
902910
})();
903911

904912

905-
/// setTimeout-defuser.js
906-
/// alias std.js
907-
(function() {
908-
let needle = '{{1}}';
909-
const delay = parseInt('{{2}}', 10);
910-
if ( needle === '' || needle === '{{1}}' ) {
911-
needle = '.?';
912-
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
913-
needle = needle.slice(1,-1);
914-
} else {
915-
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
916-
}
917-
needle = new RegExp(needle);
918-
window.setTimeout = new Proxy(window.setTimeout, {
919-
apply: function(target, thisArg, args) {
920-
const a = args[0];
921-
const b = args[1];
922-
if ( (isNaN(delay) || b === delay) && needle.test(a.toString()) ) {
923-
args[0] = function(){};
924-
}
925-
return target.apply(thisArg, args);
926-
}
927-
});
928-
})();
929-
930-
931913
/// no-setTimeout-if.js
932914
/// alias nostif.js
915+
/// alias setTimeout-defuser.js
933916
(function() {
934917
let needle = '{{1}}';
935918
const needleNot = needle.charAt(0) === '!';

dist/firefox/updates.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
44
"updates": [
55
{
6-
"version": "1.31.1.11",
6+
"version": "1.31.3.14",
77
"browser_specific_settings": { "gecko": { "strict_min_version": "55" } },
8-
"update_info_url": "https://github.com/gorhill/uBlock/releases/tag/1.31.1b11",
9-
"update_link": "https://github.com/gorhill/uBlock/releases/download/1.31.1b11/uBlock0_1.31.1b11.firefox.signed.xpi"
8+
"update_link": "https://github.com/gorhill/uBlock/releases/download/1.31.3b14/uBlock0_1.31.3b14.firefox.signed.xpi"
109
}
1110
]
1211
}

dist/firefox/updates.template.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{
66
"version": "$ext_version",
77
"browser_specific_settings": { "gecko": { "strict_min_version": "55" } },
8-
"update_info_url": "https://github.com/gorhill/uBlock/releases/tag/$tag_version",
98
"update_link": "https://github.com/gorhill/uBlock/releases/download/$tag_version/uBlock0_$tag_version.firefox.signed.xpi"
109
}
1110
]

dist/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.31.1.12
1+
1.31.3.14

platform/chromium/vapi-background.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ vAPI.messaging = {
959959
try {
960960
port.postMessage(messageWrapper);
961961
} catch(ex) {
962-
this.ports.delete(port.name);
962+
this.onPortDisconnect(port);
963963
}
964964
}
965965
},
@@ -985,7 +985,11 @@ vAPI.messaging = {
985985
msg.tabId = tabId;
986986
for ( const { port: toPort } of this.ports.values() ) {
987987
if ( toPort === port ) { continue; }
988-
toPort.postMessage(request);
988+
try {
989+
toPort.postMessage(request);
990+
} catch (ex) {
991+
this.onPortDisconnect(toPort);
992+
}
989993
}
990994
break;
991995
case 'connectionBroken':
@@ -1006,6 +1010,7 @@ vAPI.messaging = {
10061010
case 'extendClient':
10071011
vAPI.tabs.executeScript(tabId, {
10081012
file: '/js/vapi-client-extra.js',
1013+
frameId: portDetails.frameId,
10091014
}).then(( ) => {
10101015
callback();
10111016
});
@@ -1020,22 +1025,29 @@ vAPI.messaging = {
10201025
}
10211026
case 'userCSS':
10221027
if ( tabId === undefined ) { break; }
1023-
const details = {
1024-
code: undefined,
1025-
frameId: portDetails.frameId,
1026-
matchAboutBlank: true
1027-
};
1028-
if ( msg.add ) {
1029-
details.runAt = 'document_start';
1030-
}
10311028
const promises = [];
1032-
for ( const cssText of msg.add ) {
1033-
details.code = cssText;
1034-
promises.push(vAPI.tabs.insertCSS(tabId, details));
1029+
if ( msg.add ) {
1030+
const details = {
1031+
code: undefined,
1032+
frameId: portDetails.frameId,
1033+
matchAboutBlank: true,
1034+
runAt: 'document_start',
1035+
};
1036+
for ( const cssText of msg.add ) {
1037+
details.code = cssText;
1038+
promises.push(vAPI.tabs.insertCSS(tabId, details));
1039+
}
10351040
}
1036-
for ( const cssText of msg.remove ) {
1037-
details.code = cssText;
1038-
promises.push(vAPI.tabs.removeCSS(tabId, details));
1041+
if ( msg.remove ) {
1042+
const details = {
1043+
code: undefined,
1044+
frameId: portDetails.frameId,
1045+
matchAboutBlank: true,
1046+
};
1047+
for ( const cssText of msg.remove ) {
1048+
details.code = cssText;
1049+
promises.push(vAPI.tabs.removeCSS(tabId, details));
1050+
}
10391051
}
10401052
Promise.all(promises).then(( ) => {
10411053
callback();

0 commit comments

Comments
 (0)