-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
44 lines (42 loc) · 1.47 KB
/
options.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
/*global chrome, document, $ */
(function (chrome, document, $) {
"use strict";
var replacementsTextarea = document.getElementById('replacements-textarea'),
recentReplacementsTable = $('#recent-replacements-table'),
saveOptions = function () {
var replacements = replacementsTextarea.value;
chrome.storage.sync.set({
replacements: replacements
}, function () {
chrome.runtime.sendMessage({
updated: 'replacements'
});
});
},
restoreOptions = function () {
chrome.storage.sync.get({
replacements: ''
}, function (items) {
replacementsTextarea.value = items.replacements;
});
},
titleReplaced = function (replaced) {
console.log(replaced);
var row = $('<tr></tr>');
row.append($('<td></td>').text(replaced.originalTitle));
row.append($('<td></td>').text(replaced.title));
if (replaced.rule !== null) {
row.append($('<td></td>').text(replaced.rule[0] + '-->' + replaced.rule[1]));
} else {
row.append($('<td></td>').text('None'));
}
recentReplacementsTable.prepend(row);
};
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message.replaced !== undefined) {
titleReplaced(message.replaced);
}
});
}(chrome, document, $));