diff options
author | gorhill <rhill@raymondhill.net> | 2015-03-15 14:07:30 -0400 |
---|---|---|
committer | gorhill <rhill@raymondhill.net> | 2015-03-15 14:07:30 -0400 |
commit | a3abf7aa2b1167968c98ca72fa73701f9df64101 (patch) | |
tree | eb17d9053c027773f01fb522864602e65fbdf4f3 /src | |
parent | f6487270428570f5603f0559f574efef5ab4a060 (diff) | |
download | uBlock-a3abf7aa2b1167968c98ca72fa73701f9df64101.zip uBlock-a3abf7aa2b1167968c98ca72fa73701f9df64101.tar.gz uBlock-a3abf7aa2b1167968c98ca72fa73701f9df64101.tar.bz2 |
ship this with 0.9.1.1
Diffstat (limited to 'src')
-rw-r--r-- | src/js/1p-filters.js | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/js/1p-filters.js b/src/js/1p-filters.js index c22e729..24709a0 100644 --- a/src/js/1p-filters.js +++ b/src/js/1p-filters.js @@ -69,9 +69,30 @@ function allFiltersApplyHandler() { /******************************************************************************/ var handleImportFilePicker = function() { + // https://github.com/gorhill/uBlock/issues/1004 + // Support extraction of filters from ABP backup file + var abpImporter = function(s) { + var reAbpExtractor = /\n\[Subscription\]\n+url=~[\x08-\x7E]+?\[Subscription filters\]([\x08-\x7E]*?)(?:\[Subscription\]|$)/ig; + var matches = reAbpExtractor.exec(s); + // Not an ABP backup file + if ( matches === null ) { + return s; + } + var out = []; + while ( matches !== null ) { + if ( matches.length !== 2 ) { + continue; + } + out.push(matches[1].trim().replace(/\\\[/g, '[')); + matches = reAbpExtractor.exec(s); + } + return out.join('\n'); + }; + var fileReaderOnLoadHandler = function() { + var sanitized = abpImporter(this.result); var textarea = uDom('#userFilters'); - textarea.val([textarea.val(), this.result].join('\n').trim()); + textarea.val(textarea.val().trim() + '\n' + sanitized); userFiltersChanged(); }; var file = this.files[0]; @@ -150,4 +171,3 @@ uDom.onLoad(function() { // https://www.youtube.com/watch?v=UNilsLf6eW4 })(); - |