-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirefox-downloads-sort.js
80 lines (66 loc) · 2.04 KB
/
firefox-downloads-sort.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function Rule(data) {
var rules = $('#rules > tbody');
this.node = $('#rule-template').clone();
this.node.removeAttr('id');
this.node.attr('class', 'rule');
Rule.next_id++;
this.node.find('.number').html(Rule.next_id);
rules.append(this.node);
if (data) {
this.node.find('.number').text(Rule.next_id);
this.node.find('.extension').val(data.extension);
this.node.find('.foldername').val(data.foldername);
}
this.node.find('.extension').on('keyup', () => storeRules());
this.node.find('.foldername').on('keyup', () => storeRules());
this.node.find('.remove').on('click', () => {
_this = $(this).parent().parent()
_this.nextAll().find('.number').each((index, element) => {
number = $(element).text();
number--;
$(element).text(number);
});
_this.remove();
Rule.next_id--;
storeRules();
});
storeRules();
}
Rule.next_id = 0;
function loadRules() {
var rules = localStorage.rules;
try {
JSON.parse(rules).forEach((rule) => {
new Rule(rule);
});
} catch (e) {
//localStorage.rules = JSON.stringify([]);
}
}
function storeRules() {
var rules = [];
$('.rule').each((index, element) => {
rules.push({
extension: $(element).find('.extension').val(),
foldername: $(element).find('.foldername').val()
});
});
localStorage.rules = JSON.stringify(rules);
browser.storage.sync.set({
'rules': JSON.stringify(rules)
});
}
function init() {
$('#defaultFolder').val(localStorage.defaultFolder);
$('#defaultFolder').on('keyup', () => {
localStorage.defaultFolder = $('#defaultFolder').val();
browser.storage.sync.set({
'defaultFolder': $('#defaultFolder').val()
});
});
$('#new').on('click', function() {
new Rule();
});
loadRules();
}
window.onload = () => init();