blob: 7c0d33989d5874748305581043e2e12a55b3ee18 [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
avm999636d9c5fe2019-06-04 00:35:53 +020016 if (options.threadall && node.classList.contains("load-more-bar")) {
17 intersectionObserver.observe(node.querySelector(".load-all-button"));
18 }
19
avm99963d0757252019-03-30 20:13:00 +010020 if (options.history && ("parentNode" in node) && node.parentNode !== null && ("tagName" in node.parentNode) && node.parentNode.tagName == "EC-USER") {
21 var nameElement = node.querySelector(".name span");
22 if (nameElement !== null) {
23 var name = encodeURIComponent(nameElement.innerText);
24 var link = document.createElement("a");
25 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");
avm99963a3d1ef32019-03-30 23:33:29 +010026 link.innerText = chrome.i18n.getMessage("inject_previousposts");
avm99963d0757252019-03-30 20:13:00 +010027 node.querySelector(".main-card").appendChild(document.createElement("br"));
28 node.querySelector(".main-card").appendChild(link);
29 }
30 }
31 }
avm99963847ee632019-03-27 00:57:44 +010032 });
33 }
34 });
35}
36
37function intersectionCallback(entries, observer) {
38 entries.forEach(entry => {
39 if (entry.isIntersecting) {
40 entry.target.click();
41 }
42 });
43};
44
45var observerOptions = {
46 childList: true,
47 attributes: true,
48 subtree: true
49}
50
avm99963847ee632019-03-27 00:57:44 +010051var intersectionOptions = {
52 root: document.querySelector('.scrollable-content'),
53 rootMargin: '0px',
54 threshold: 1.0
55}
56
avm99963cbea3142019-03-28 00:48:15 +010057chrome.storage.sync.get(null, function(items) {
58 options = items;
59
60 mutationObserver = new MutationObserver(mutationCallback);
61 mutationObserver.observe(document.querySelector(".scrollable-content"), observerOptions);
62
63 intersectionObserver = new IntersectionObserver(intersectionCallback, intersectionOptions);
avm99963122dc9b2019-03-30 18:44:18 +010064
65 if (options.fixedtoolbar) {
66 var link = document.createElement('link');
67 link.setAttribute("rel", "stylesheet");
avm999638a3a6152019-03-31 21:12:02 +020068 link.setAttribute("href", "data:text/css;charset=UTF-8,ec-bulk-actions{position: sticky; top: 0; background: white; z-index: 96;}");
avm99963b21f6252019-03-30 22:06:21 +010069 document.head.appendChild(link);
avm99963122dc9b2019-03-30 18:44:18 +010070 }
avm99963cbea3142019-03-28 00:48:15 +010071});