-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolumns.js
56 lines (51 loc) · 1.31 KB
/
columns.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
function unMarkColumns() {
var classes = ['cols', 'cols-2', 'cols-3', 'cols-4', 'cols-5', 'cols-6'];
classes.forEach(function(name) {
$("." + name).removeClass(name);
});
}
function markColumns() {
for(var i=2; i<7; i++) {
$('.project:has(> .name > .content > span[title="Filter #cols-' + i + '"]) > .children').addClass("cols cols-" + i);
}
}
// main update function
function updateColumns() {
unMarkColumns();
markColumns();
}
// refresh stuff
var observer = new MutationObserver(function(mutations) { updateColumns(); });
function setupRefresh() {
observer.observe($('.mainTreeRoot')[0], {
childList: true,
attributes: false,
characterData: false,
subtree: true
});
}
function teardownRefresh() {
observer.disconnect();
}
// startup
window.addEventListener("load", async function go() {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// sleep 2 seconds so all workflowy's code loads
await sleep(2000);
// first time marking columns
markColumns();
// set up refresh
setupRefresh();
});
// listen for messages from background script
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message == "stop") {
teardownRefresh();
unMarkColumns();
} else {
markColumns();
setupRefresh();
}
});