mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-02 00:42:45 +01:00
this fixes #1022
This commit is contained in:
parent
ac09dfadab
commit
83c6945ad5
@ -69,9 +69,30 @@ function allFiltersApplyHandler() {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var handleImportFilePicker = function() {
|
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 fileReaderOnLoadHandler = function() {
|
||||||
|
var sanitized = abpImporter(this.result);
|
||||||
var textarea = uDom('#userFilters');
|
var textarea = uDom('#userFilters');
|
||||||
textarea.val([textarea.val(), this.result].join('\n').trim());
|
textarea.val(textarea.val().trim() + '\n' + sanitized);
|
||||||
userFiltersChanged();
|
userFiltersChanged();
|
||||||
};
|
};
|
||||||
var file = this.files[0];
|
var file = this.files[0];
|
||||||
|
Loading…
Reference in New Issue
Block a user