-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
49 lines (42 loc) · 1.37 KB
/
content.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
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
// fired when a mutation occurs
console.log(mutations, observer);
$("div.PostSummary__reblogged_by").parent().parent().hide();
// ...
});
var target = document.getElementById('posts_list');
var state = "blank";
checkState();
var li=document.createElement("li");
firstParent = document.querySelector("#posts_list > ul");
firstChild = document.querySelector("#posts_list > ul > li:nth-child(1)");
firstParent.insertBefore(li,firstChild);
li.id="togglediv";
function checkState(){
chrome.runtime.sendMessage({greeting: "checkstate"}, function(response) {
if (response.check == "show") {
observer.disconnect();
$("div.PostSummary__reblogged_by").parent().parent().show();
li.innerText="hide resteems";
li.onclick= toggleState;
} else if (response.check == "hide") {
$("div.PostSummary__reblogged_by").parent().parent().hide();
// watch for any incoming ajax loaded posts to hide resteemed
observer.observe(target, {
subtree: true,
childList: true,
attributes: true
//...
});
li.innerText="show resteems";
li.onclick= toggleState;
} else {
li.innerText="NA";
}
});
}
function toggleState(){
chrome.runtime.sendMessage({greeting: "togglestate"});
checkState();
}