-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
54 lines (42 loc) · 1.52 KB
/
content.js
File metadata and controls
54 lines (42 loc) · 1.52 KB
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
const postContainer = document.querySelector('.scaffold-finite-scroll__content');
const all_posts = [];
let src={
link:null
}
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
src.link=message.message;
updateProfilePic(all_posts,src);
sendResponse({ response: "Hi there from content.js!" });
});
postContainer.childNodes.forEach(e => {
if (e.nodeName === 'DIV') {
all_posts.push(e);
}
})
updateProfilePic(all_posts,src);
const mutationObserver = new MutationObserver(entries => {
const posts = [];
entries.forEach(entry => {
if (entry.addedNodes[0] && entry.addedNodes[0].nodeName === 'DIV') {
posts.push(entry.addedNodes[0]);
all_posts.push(entry.addedNodes[0]);
}
})
updateProfilePic(posts,src);
})
mutationObserver.observe(postContainer, { childList: true, subtree: true });
function updateProfilePic(posts,src) {
posts.forEach(post => {
const actorComponent = post.querySelector('.update-components-actor');
console.log(actorComponent);
if (actorComponent) {
const imgWrappers = actorComponent.querySelectorAll('.ivm-view-attr__img-wrapper');
imgWrappers.forEach(imgWrapper=>{
if(imgWrapper.children[0] && imgWrapper.children[0].src && src.link){
imgWrapper.children[0].src=src.link;
imgWrapper.children[0].style.objectFit="cover";
}
})
}
})
}