From be2c4db0c7a20356b97f5b342299c207b647afd6 Mon Sep 17 00:00:00 2001 From: Gilmore Davidson Date: Sat, 2 Mar 2019 11:32:49 +1100 Subject: [PATCH] Add option to remove "Top highlight" markers Closes #47 --- content.js | 40 ++++++++++++++++++++++++++++++++++++++++ options.html | 7 ++++++- options.js | 12 ++++++++---- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/content.js b/content.js index 42cce91..672c8f3 100644 --- a/content.js +++ b/content.js @@ -37,6 +37,43 @@ var hideHighlightMenu = function() { document.head.insertAdjacentHTML('beforeend', ''); }; +var isTopHighlightNode = function(node) { + return ( + node.nodeType === Node.ELEMENT_NODE && + node.classList.contains('markup--quote') && + node.classList.contains('is-other') + ); +} + +var removeHighlight = function(node) { + node.classList.remove('markup--quote'); + var parentNode = node.parentNode; + var name = parentNode.getAttribute('name'); + if (name) { + var control = document.querySelector('.js-paragraphControl-' + name); + if (control) { + control.remove(); + } + } +} + +var hideTopHighlight = function() { + var highlightObserver = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + mutation.addedNodes.forEach(function(node) { + if (isTopHighlightNode(node)) { + removeHighlight(node); + } + }); + }); + }); + + highlightObserver.observe(document.body, { + childList: true, + subtree: true + }); +}; + var hideDickbar = function() { var dickbar = document.querySelector('.js-postShareWidget'); if (dickbar) { @@ -101,6 +138,9 @@ if (document.querySelector('head meta[property="al:ios:app_name"][content="mediu if (items.hideHighlightMenu) { hideHighlightMenu(); } + if (items.hideTopHighlight) { + hideTopHighlight(); + } }); observer.observe(document.body, config); diff --git a/options.html b/options.html index dbcc89b..ad99d12 100644 --- a/options.html +++ b/options.html @@ -1,6 +1,7 @@ + Make Medium Readable Again Settings