This repository was archived by the owner on Sep 9, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -69,9 +69,30 @@ function allFiltersApplyHandler() {
6969/******************************************************************************/
7070
7171var 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 \[ S u b s c r i p t i o n \] \n + u r l = ~ [ \x08 - \x7E ] + ?\[ S u b s c r i p t i o n f i l t e r s \] ( [ \x08 - \x7E ] * ?) (?: \[ S u b s c r i p t i o n \] | $ ) / 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-
You can’t perform that action at this time.
0 commit comments