/
popup.js
47 lines (37 loc) · 1.58 KB
/
popup.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
function click(e) {
load_url_configuration();
var p_line_height = document.getElementById('spacing').value;
var p_offset = document.getElementById('offset').value;
var canvas = document.getElementById("bgcanvas");
canvas.width = 1;
canvas.height = p_line_height;
var context = canvas.getContext("2d");
context.fillStyle = "rgba(0, 0, 0, .1)";
context.fillRect(0, 0, p_line_height, 1);
context.fillStyle = "rgba(255, 0, 0, .1)";
context.fillRect(0, p_line_height/2, p_line_height, 1);
var image = canvas.toDataURL()
set_url_configuration(p_line_height, p_offset, window.location.host);
chrome.tabs.executeScript(null,
{code:"document.body.style.backgroundImage='url("+ image +")';document.body.style.backgroundPosition='0 " + p_offset + "px';"});
}
function set_url_configuration(spacing, offset, url) {
var site_config = {};
site_config['spacing'] = spacing;
site_config['offset'] = offset;
var current_url = url;
chrome.storage.sync.set({current_url: site_config});
}
function load_url_configuration() {
chrome.storage.sync.get(window.location.host, function(site_configuration) {
if (typeof site_configuration != 'undefined') {
document.getElementById('spacing').value = site_configuration['spacing'];
document.getElementById('offset').value = site_configuration['offset'];
}
});
}
document.addEventListener('DOMContentLoaded', function () {
load_url_configuration();
click();
document.querySelector('#apply').addEventListener('click', click);
});