blob: c97483b12c868c0ae75d840d63149b8a7b80aadb [file] [log] [blame]
avm99963cbea3142019-03-28 00:48:15 +01001var mutationObserver, intersectionObserver, options;
2
avm99963af7860e2019-06-04 03:33:26 +02003function parseUrl(url) {
4 var forum_a = url.match(/forum\/([0-9]+)/i);
5 var thread_a = url.match(/thread\/([0-9]+)/i);
6
7 if (forum_a === null || thread_a === null) {
8 return false;
9 }
10
11 return {
12 "forum": forum_a[1],
13 "thread": thread_a[1]
14 };
15}
16
avm99963847ee632019-03-27 00:57:44 +010017function mutationCallback(mutationList, observer) {
18 mutationList.forEach((mutation) => {
19 if (mutation.type == "childList") {
20 mutation.addedNodes.forEach(function (node) {
avm99963d0757252019-03-30 20:13:00 +010021 if (typeof node.classList !== "undefined") {
avm99963d0757252019-03-30 20:13:00 +010022 if (options.thread && node.classList.contains("load-more-bar")) {
23 intersectionObserver.observe(node.querySelector(".load-more-button"));
24 }
25
avm999636d9c5fe2019-06-04 00:35:53 +020026 if (options.threadall && node.classList.contains("load-more-bar")) {
27 intersectionObserver.observe(node.querySelector(".load-all-button"));
28 }
29
avm99963d0757252019-03-30 20:13:00 +010030 if (options.history && ("parentNode" in node) && node.parentNode !== null && ("tagName" in node.parentNode) && node.parentNode.tagName == "EC-USER") {
31 var nameElement = node.querySelector(".name span");
32 if (nameElement !== null) {
avm9996318d043a2020-05-29 12:20:47 +020033 var name = nameElement.innerHTML;
avm9996351c95852019-06-17 21:37:41 +020034 var query = encodeURIComponent("(creator:\""+name+"\" | replier:\""+name+"\") -forum:0");
35 var urlpart = encodeURIComponent("query="+query);
avm99963d0757252019-03-30 20:13:00 +010036 var link = document.createElement("a");
avm9996351c95852019-06-17 21:37:41 +020037 link.setAttribute("href", "https://support.google.com/s/community/search/"+urlpart);
avm99963a3d1ef32019-03-30 23:33:29 +010038 link.innerText = chrome.i18n.getMessage("inject_previousposts");
avm999637beddb32020-01-18 19:52:46 +010039 node.querySelector(".main-card-content").appendChild(document.createElement("br"));
40 node.querySelector(".main-card-content").appendChild(link);
avm99963d0757252019-03-30 20:13:00 +010041 }
42 }
43 }
avm99963847ee632019-03-27 00:57:44 +010044 });
45 }
46 });
47}
48
avm99963adf90862020-04-12 13:27:45 +020049function intersectionCallback(entries, observer) {
avm99963847ee632019-03-27 00:57:44 +010050 entries.forEach(entry => {
51 if (entry.isIntersecting) {
52 entry.target.click();
53 }
54 });
55};
56
avm99963ae6a26d2020-04-12 14:03:51 +020057function injectStyles(css) {
58 var link = document.createElement('link');
59 link.setAttribute("rel", "stylesheet");
60 link.setAttribute("href", "data:text/css;charset=UTF-8,"+encodeURIComponent(css));
61 document.head.appendChild(link);
62}
63
avm99963847ee632019-03-27 00:57:44 +010064var observerOptions = {
65 childList: true,
66 attributes: true,
67 subtree: true
68}
69
avm99963847ee632019-03-27 00:57:44 +010070var intersectionOptions = {
71 root: document.querySelector('.scrollable-content'),
72 rootMargin: '0px',
73 threshold: 1.0
74}
75
avm99963cbea3142019-03-28 00:48:15 +010076chrome.storage.sync.get(null, function(items) {
77 options = items;
78
79 mutationObserver = new MutationObserver(mutationCallback);
80 mutationObserver.observe(document.querySelector(".scrollable-content"), observerOptions);
81
82 intersectionObserver = new IntersectionObserver(intersectionCallback, intersectionOptions);
avm99963122dc9b2019-03-30 18:44:18 +010083
84 if (options.fixedtoolbar) {
avm99963ae6a26d2020-04-12 14:03:51 +020085 injectStyles("ec-bulk-actions{position: sticky; top: 0; background: white; z-index: 96;}");
86 }
87
88 if (options.increasecontrast) {
89 injectStyles(".thread-summary.read{background: #ecedee!important;}");
avm99963122dc9b2019-03-30 18:44:18 +010090 }
avm999630f9503f2020-07-27 13:56:52 +020091
92 if (options.stickysidebarheaders) {
93 injectStyles("material-drawer .main-header{background: #fff; position: sticky; top: 0; z-index: 1;}");
94 }
avm99963cbea3142019-03-28 00:48:15 +010095});