1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 07:22:28 +02:00

Code maintenance: remove now unused ABP-related code path

This commit is contained in:
Raymond Hill 2023-05-14 09:41:35 -04:00
parent a3a80e3b3f
commit 7bc06fec8c
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -90,26 +90,24 @@ let cachedUserFilters = '';
/******************************************************************************/ /******************************************************************************/
const getEditorText = function() { function getEditorText() {
const text = cmEditor.getValue().replace(/\s+$/, ''); const text = cmEditor.getValue().replace(/\s+$/, '');
return text === '' ? text : text + '\n'; return text === '' ? text : text + '\n';
}; }
const setEditorText = function(text) { function setEditorText(text) {
cmEditor.setValue(text.replace(/\s+$/, '') + '\n\n'); cmEditor.setValue(text.replace(/\s+$/, '') + '\n\n');
}; }
/******************************************************************************/ /******************************************************************************/
// This is to give a visual hint that the content of user blacklist has changed. function userFiltersChanged(changed) {
const userFiltersChanged = function(changed) {
if ( typeof changed !== 'boolean' ) { if ( typeof changed !== 'boolean' ) {
changed = self.hasUnsavedData(); changed = self.hasUnsavedData();
} }
qs$('#userFiltersApply').disabled = !changed; qs$('#userFiltersApply').disabled = !changed;
qs$('#userFiltersRevert').disabled = !changed; qs$('#userFiltersRevert').disabled = !changed;
}; }
/******************************************************************************/ /******************************************************************************/
@ -118,7 +116,7 @@ const userFiltersChanged = function(changed) {
// made in the editor. The code assumes that no deletion occurred in the // made in the editor. The code assumes that no deletion occurred in the
// background. // background.
const threeWayMerge = function(newContent) { function threeWayMerge(newContent) {
const prvContent = cachedUserFilters.trim().split(/\n/); const prvContent = cachedUserFilters.trim().split(/\n/);
const differ = new self.diff_match_patch(); const differ = new self.diff_match_patch();
const newChanges = differ.diff( const newChanges = differ.diff(
@ -158,11 +156,11 @@ const threeWayMerge = function(newContent) {
out.push(change[1]); out.push(change[1]);
} }
return out.join('\n'); return out.join('\n');
}; }
/******************************************************************************/ /******************************************************************************/
const renderUserFilters = async function(merge = false) { async function renderUserFilters(merge = false) {
const details = await vAPI.messaging.send('dashboard', { const details = await vAPI.messaging.send('dashboard', {
what: 'readUserFilters', what: 'readUserFilters',
}); });
@ -179,34 +177,13 @@ const renderUserFilters = async function(merge = false) {
} }
cachedUserFilters = newContent; cachedUserFilters = newContent;
}; }
/******************************************************************************/ /******************************************************************************/
const handleImportFilePicker = function() { function handleImportFilePicker() {
// https://github.com/chrisaljoudi/uBlock/issues/1004
// Support extraction of filters from ABP backup file
const abpImporter = function(s) {
const reAbpSubscriptionExtractor = /\n\[Subscription\]\n+url=~[^\n]+([\x08-\x7E]*?)(?:\[Subscription\]|$)/ig;
const reAbpFilterExtractor = /\[Subscription filters\]([\x08-\x7E]*?)(?:\[Subscription\]|$)/i;
let matches = reAbpSubscriptionExtractor.exec(s);
// Not an ABP backup file
if ( matches === null ) { return s; }
const out = [];
do {
if ( matches.length === 2 ) {
let filterMatch = reAbpFilterExtractor.exec(matches[1].trim());
if ( filterMatch !== null && filterMatch.length === 2 ) {
out.push(filterMatch[1].trim().replace(/\\\[/g, '['));
}
}
matches = reAbpSubscriptionExtractor.exec(s);
} while ( matches !== null );
return out.join('\n');
};
const fileReaderOnLoadHandler = function() { const fileReaderOnLoadHandler = function() {
let content = abpImporter(this.result); let content = this.result;
content = uBlockDashboard.mergeNewLines(getEditorText(), content); content = uBlockDashboard.mergeNewLines(getEditorText(), content);
cmEditor.operation(( ) => { cmEditor.operation(( ) => {
const cmPos = cmEditor.getCursor(); const cmPos = cmEditor.getCursor();
@ -221,22 +198,20 @@ const handleImportFilePicker = function() {
const fr = new FileReader(); const fr = new FileReader();
fr.onload = fileReaderOnLoadHandler; fr.onload = fileReaderOnLoadHandler;
fr.readAsText(file); fr.readAsText(file);
}; }
/******************************************************************************/ function startImportFilePicker() {
const startImportFilePicker = function() {
const input = qs$('#importFilePicker'); const input = qs$('#importFilePicker');
// Reset to empty string, this will ensure an change event is properly // Reset to empty string, this will ensure an change event is properly
// triggered if the user pick a file, even if it is the same as the last // triggered if the user pick a file, even if it is the same as the last
// one picked. // one picked.
input.value = ''; input.value = '';
input.click(); input.click();
}; }
/******************************************************************************/ /******************************************************************************/
const exportUserFiltersToFile = function() { function exportUserFiltersToFile() {
const val = getEditorText(); const val = getEditorText();
if ( val === '' ) { return; } if ( val === '' ) { return; }
const filename = i18n$('1pExportFilename') const filename = i18n$('1pExportFilename')
@ -246,11 +221,11 @@ const exportUserFiltersToFile = function() {
'url': 'data:text/plain;charset=utf-8,' + encodeURIComponent(val + '\n'), 'url': 'data:text/plain;charset=utf-8,' + encodeURIComponent(val + '\n'),
'filename': filename 'filename': filename
}); });
}; }
/******************************************************************************/ /******************************************************************************/
const applyChanges = async function() { async function applyChanges() {
const details = await vAPI.messaging.send('dashboard', { const details = await vAPI.messaging.send('dashboard', {
what: 'writeUserFilters', what: 'writeUserFilters',
content: getEditorText(), content: getEditorText(),
@ -262,25 +237,25 @@ const applyChanges = async function() {
vAPI.messaging.send('dashboard', { vAPI.messaging.send('dashboard', {
what: 'reloadAllFilters', what: 'reloadAllFilters',
}); });
}; }
const revertChanges = function() { function revertChanges() {
setEditorText(cachedUserFilters); setEditorText(cachedUserFilters);
}; }
/******************************************************************************/ /******************************************************************************/
const getCloudData = function() { function getCloudData() {
return getEditorText(); return getEditorText();
}; }
const setCloudData = function(data, append) { function setCloudData(data, append) {
if ( typeof data !== 'string' ) { return; } if ( typeof data !== 'string' ) { return; }
if ( append ) { if ( append ) {
data = uBlockDashboard.mergeNewLines(getEditorText(), data); data = uBlockDashboard.mergeNewLines(getEditorText(), data);
} }
cmEditor.setValue(data); cmEditor.setValue(data);
}; }
self.cloud.onPush = getCloudData; self.cloud.onPush = getCloudData;
self.cloud.onPull = setCloudData; self.cloud.onPull = setCloudData;
@ -312,6 +287,7 @@ dom.on('#userFiltersRevert', 'click', revertChanges);
if ( typeof line === 'number' ) { if ( typeof line === 'number' ) {
cmEditor.setCursor(line, 0); cmEditor.setCursor(line, 0);
} }
cmEditor.focus();
} }
// https://github.com/gorhill/uBlock/issues/3706 // https://github.com/gorhill/uBlock/issues/3706