Skip to content
This repository was archived by the owner on Sep 9, 2022. It is now read-only.

Commit a3abf7a

Browse files
committed
ship this with 0.9.1.1
1 parent f648727 commit a3abf7a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/js/1p-filters.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,30 @@ function allFiltersApplyHandler() {
6969
/******************************************************************************/
7070

7171
var handleImportFilePicker = function() {
72+
// https://github.com/gorhill/uBlock/issues/1004
73+
// Support extraction of filters from ABP backup file
74+
var abpImporter = function(s) {
75+
var reAbpExtractor = /\n\[Subscription\]\n+url=~[\x08-\x7E]+?\[Subscription filters\]([\x08-\x7E]*?)(?:\[Subscription\]|$)/ig;
76+
var matches = reAbpExtractor.exec(s);
77+
// Not an ABP backup file
78+
if ( matches === null ) {
79+
return s;
80+
}
81+
var out = [];
82+
while ( matches !== null ) {
83+
if ( matches.length !== 2 ) {
84+
continue;
85+
}
86+
out.push(matches[1].trim().replace(/\\\[/g, '['));
87+
matches = reAbpExtractor.exec(s);
88+
}
89+
return out.join('\n');
90+
};
91+
7292
var fileReaderOnLoadHandler = function() {
93+
var sanitized = abpImporter(this.result);
7394
var textarea = uDom('#userFilters');
74-
textarea.val([textarea.val(), this.result].join('\n').trim());
95+
textarea.val(textarea.val().trim() + '\n' + sanitized);
7596
userFiltersChanged();
7697
};
7798
var file = this.files[0];
@@ -150,4 +171,3 @@ uDom.onLoad(function() {
150171
// https://www.youtube.com/watch?v=UNilsLf6eW4
151172

152173
})();
153-

0 commit comments

Comments
 (0)