7e053c619259379d9c2f320703e0725be203b3ea
[project/luci.git] / applications / luci-app-adblock / htdocs / luci-static / resources / view / adblock / blacklist.js
1 'use strict';
2 'require fs';
3 'require ui';
4
5 return L.view.extend({
6 load: function() {
7 return L.resolveDefault(fs.read_direct('/etc/adblock/adblock.blacklist'), '');
8 },
9 handleSave: function(ev) {
10 var value = ((document.querySelector('textarea').value || '').trim().toLowerCase().replace(/\r\n/g, '\n').replace(/[^a-z0-9\.\-\#\n]/g, '')) + '\n';
11 return fs.write('/etc/adblock/adblock.blacklist', value)
12 .then(function(rc) {
13 document.querySelector('textarea').value = value;
14 ui.addNotification(null, E('p', _('Blacklist changes have been saved. Refresh your adblock lists that changes take effect.')), 'info');
15 }).catch(function(e) {
16 ui.addNotification(null, E('p', _('Unable to save changes: %s').format(e.message)));
17 });
18 },
19 render: function(blacklist) {
20 return E([
21 E('p', {},
22 _('This is the local adblock blacklist to always-deny certain (sub) domains.<br /> \
23 Please note: add only one domain per line. Comments introduced with \'#\' are allowed - ip addresses, wildcards and regex are not.')),
24 E('p', {},
25 E('textarea', {
26 'style': 'width: 100% !important; padding: 5px; font-family: monospace',
27 'wrap': 'off',
28 'rows': 25
29 }, [ blacklist != null ? blacklist : '' ])
30 )
31 ]);
32 },
33 handleSaveApply: null,
34 handleReset: null
35 });