blob: aab2eb6ded428402d23ddf01df7bc35b6dafb394 [file] [log] [blame]
avm99963cbea3142019-03-28 00:48:15 +01001var mutationObserver, intersectionObserver, options;
2
avm99963847ee632019-03-27 00:57:44 +01003function mutationCallback(mutationList, observer) {
4 mutationList.forEach((mutation) => {
5 if (mutation.type == "childList") {
6 mutation.addedNodes.forEach(function (node) {
avm99963d0757252019-03-30 20:13:00 +01007 if (typeof node.classList !== "undefined") {
8 if (options.list && node.classList.contains("view-more-button-container")) {
9 intersectionObserver.observe(node.querySelector(".view-more-button"));
10 }
Nico Sinisterra4ae1c572019-03-27 12:57:13 -030011
avm99963d0757252019-03-30 20:13:00 +010012 if (options.thread && node.classList.contains("load-more-bar")) {
13 intersectionObserver.observe(node.querySelector(".load-more-button"));
14 }
15
16 if (options.history && ("parentNode" in node) && node.parentNode !== null && ("tagName" in node.parentNode) && node.parentNode.tagName == "EC-USER") {
17 var nameElement = node.querySelector(".name span");
18 if (nameElement !== null) {
19 var name = encodeURIComponent(nameElement.innerText);
20 var link = document.createElement("a");
21 link.setAttribute("href", "https://support.google.com/s/community/search/query%3D%2528creator%253A%2522"+name+"%2522%2B%257C%2Breplier%253A%2522"+name+"%2522%2529%2B-forum%253A0");
22 link.innerText = "Previous posts";
23 node.querySelector(".main-card").appendChild(document.createElement("br"));
24 node.querySelector(".main-card").appendChild(link);
25 }
26 }
27 }
avm99963847ee632019-03-27 00:57:44 +010028 });
29 }
30 });
31}
32
33function intersectionCallback(entries, observer) {
34 entries.forEach(entry => {
35 if (entry.isIntersecting) {
36 entry.target.click();
37 }
38 });
39};
40
41var observerOptions = {
42 childList: true,
43 attributes: true,
44 subtree: true
45}
46
avm99963847ee632019-03-27 00:57:44 +010047var intersectionOptions = {
48 root: document.querySelector('.scrollable-content'),
49 rootMargin: '0px',
50 threshold: 1.0
51}
52
avm99963cbea3142019-03-28 00:48:15 +010053chrome.storage.sync.get(null, function(items) {
54 options = items;
55
56 mutationObserver = new MutationObserver(mutationCallback);
57 mutationObserver.observe(document.querySelector(".scrollable-content"), observerOptions);
58
59 intersectionObserver = new IntersectionObserver(intersectionCallback, intersectionOptions);
avm99963122dc9b2019-03-30 18:44:18 +010060
61 if (options.fixedtoolbar) {
62 var link = document.createElement('link');
63 link.setAttribute("rel", "stylesheet");
64 link.setAttribute("href", "data:text/css;charset=UTF-8,ec-bulk-actions{position: sticky; top: 0; background: white; z-index: 99;}");
65 }
66
67 document.head.appendChild(link);
avm99963cbea3142019-03-28 00:48:15 +010068});