Skip to content

Commit 61b10ca

Browse files
committed
Refactor into functions
1 parent a51cad0 commit 61b10ca

File tree

4 files changed

+51
-40
lines changed

4 files changed

+51
-40
lines changed

js/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ chrome.webNavigation.onHistoryStateUpdated.addListener(function(details) {
77
// Setup page for layout changes and show page action
88
if (match) {
99
chrome.tabs.executeScript(null, {
10-
file: 'js/setup-css.js'
10+
file: 'js/init.js'
1111
});
1212
}
1313
});
1414

1515
chrome.pageAction.onClicked.addListener(function(tab) {
1616
chrome.tabs.executeScript(null, {
17-
file: 'js/toggle-layout.js'
17+
code: 'toggleLayout()'
1818
});
1919
});
2020

js/init.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
function insertCss() {
2+
const cssFile = chrome.extension.getURL('css/layout.css');
3+
const cssId = 'layoutcss';
4+
5+
if (document.getElementById(cssId) === null) {
6+
let css = document.createElement('link');
7+
css.id = cssId;
8+
css.type = 'text/css';
9+
css.rel = 'stylesheet';
10+
css.href = cssFile;
11+
document.getElementsByTagName('head')[0].appendChild(css);
12+
}
13+
}
14+
15+
function syncState() {
16+
chrome.storage.sync.get('classList', function(result) {
17+
let board = document.getElementById('board');
18+
19+
if (result.classList) {
20+
board.classList.add(result.classList);
21+
}
22+
});
23+
}
24+
25+
function toggleLayout() {
26+
const classVertical = 'layout-trello-vertical';
27+
const classMixed = 'layout-trello-mixed';
28+
29+
let board = document.getElementById('board');
30+
31+
if (board.classList.contains(classMixed)) {
32+
board.classList.remove(classMixed);
33+
board.classList.add(classVertical);
34+
chrome.storage.sync.set({
35+
'classList': classVertical
36+
});
37+
} else if (board.classList.contains(classVertical)) {
38+
board.classList.remove(classVertical);
39+
chrome.storage.sync.remove('classList');
40+
} else {
41+
board.classList.add(classMixed);
42+
chrome.storage.sync.set({
43+
'classList': classMixed
44+
});
45+
}
46+
}
47+
48+
insertCss();
49+
syncState();

js/setup-css.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

js/toggle-layout.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)