avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 1 | var mutationObserver, intersectionObserver, options; |
| 2 | |
avm99963 | 847ee63 | 2019-03-27 00:57:44 +0100 | [diff] [blame] | 3 | function mutationCallback(mutationList, observer) { |
| 4 | mutationList.forEach((mutation) => { |
| 5 | if (mutation.type == "childList") { |
| 6 | mutation.addedNodes.forEach(function (node) { |
avm99963 | d075725 | 2019-03-30 20:13:00 +0100 | [diff] [blame] | 7 | 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 Sinisterra | 4ae1c57 | 2019-03-27 12:57:13 -0300 | [diff] [blame] | 11 | |
avm99963 | d075725 | 2019-03-30 20:13:00 +0100 | [diff] [blame] | 12 | 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"); |
avm99963 | a3d1ef3 | 2019-03-30 23:33:29 +0100 | [diff] [blame] | 22 | link.innerText = chrome.i18n.getMessage("inject_previousposts"); |
avm99963 | d075725 | 2019-03-30 20:13:00 +0100 | [diff] [blame] | 23 | node.querySelector(".main-card").appendChild(document.createElement("br")); |
| 24 | node.querySelector(".main-card").appendChild(link); |
| 25 | } |
| 26 | } |
| 27 | } |
avm99963 | 847ee63 | 2019-03-27 00:57:44 +0100 | [diff] [blame] | 28 | }); |
| 29 | } |
| 30 | }); |
| 31 | } |
| 32 | |
| 33 | function intersectionCallback(entries, observer) { |
| 34 | entries.forEach(entry => { |
| 35 | if (entry.isIntersecting) { |
| 36 | entry.target.click(); |
| 37 | } |
| 38 | }); |
| 39 | }; |
| 40 | |
| 41 | var observerOptions = { |
| 42 | childList: true, |
| 43 | attributes: true, |
| 44 | subtree: true |
| 45 | } |
| 46 | |
avm99963 | 847ee63 | 2019-03-27 00:57:44 +0100 | [diff] [blame] | 47 | var intersectionOptions = { |
| 48 | root: document.querySelector('.scrollable-content'), |
| 49 | rootMargin: '0px', |
| 50 | threshold: 1.0 |
| 51 | } |
| 52 | |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 53 | chrome.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); |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 60 | |
| 61 | if (options.fixedtoolbar) { |
| 62 | var link = document.createElement('link'); |
| 63 | link.setAttribute("rel", "stylesheet"); |
avm99963 | 8a3a615 | 2019-03-31 21:12:02 +0200 | [diff] [blame] | 64 | link.setAttribute("href", "data:text/css;charset=UTF-8,ec-bulk-actions{position: sticky; top: 0; background: white; z-index: 96;}"); |
avm99963 | b21f625 | 2019-03-30 22:06:21 +0100 | [diff] [blame] | 65 | document.head.appendChild(link); |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 66 | } |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 67 | }); |