From ce74cda636395b60914a89bd206a7bf059a085eb Mon Sep 17 00:00:00 2001 From: shinigami-eyes <43276258+shinigami-eyes@users.noreply.github.com> Date: Sun, 6 Oct 2019 13:04:11 +0200 Subject: [PATCH] Initial support for site homepages --- extension/background.ts | 12 ++++++++ extension/content.ts | 68 ++++++++++++++++++++++++++--------------- extension/manifest.json | 14 ++++++--- 3 files changed, 66 insertions(+), 28 deletions(-) diff --git a/extension/background.ts b/extension/background.ts index d893ed8..60a2d58 100644 --- a/extension/background.ts +++ b/extension/background.ts @@ -384,6 +384,18 @@ function createContextMenu(text: string, id: ContextMenuCommand) { "*://*.google.com/*", "*://*.bing.com/*", "*://duckduckgo.com/*", + + "*://*/", + "*://*/about*", + "*://*/contact*", + "*://*/faq*", + "*://*/blog", + "*://*/blog/", + "*://*/news", + "*://*/news/", + "*://*/en/", + "*://*/index.html", + "*://*/index.php", ] }); } diff --git a/extension/content.ts b/extension/content.ts index a504150..7b51f51 100644 --- a/extension/content.ts +++ b/extension/content.ts @@ -9,6 +9,7 @@ if (hostname.endsWith('.facebook.com')) hostname = 'facebook.com'; if (hostname.endsWith('.youtube.com')) hostname = 'youtube.com'; var myself: string = null; +var isSocialNetwork: boolean = null; function fixupSiteStyles() { if (hostname == 'facebook.com') { @@ -81,6 +82,21 @@ function maybeDisableCustomCss() { } function init() { + isSocialNetwork = [ + 'facebook.com', + 'youtube.com', + 'reddit.com', + 'twitter.com', + 'medium.com', + 'disqus.com', + 'rationalwiki.org', + 'duckduckgo.com', + 'bing.com', + ].includes(hostname) || + domainIs(hostname, 'tumblr.com') || + domainIs(hostname, 'wikipedia.org') || + /^google(\.co)?\.\w+$/.test(hostname); + fixupSiteStyles(); if (domainIs(hostname, 'youtube.com')) { @@ -93,36 +109,38 @@ function init() { console.log('Self: ' + myself) + document.addEventListener('contextmenu', evt => { + lastRightClickedElement = evt.target; + }, true); + maybeDisableCustomCss(); updateAllLabels(); - var observer = new MutationObserver(mutationsList => { - maybeDisableCustomCss(); - for (const mutation of mutationsList) { - if (mutation.type == 'childList') { - for (const node of mutation.addedNodes) { - if (node instanceof HTMLAnchorElement) { - initLink(node); - } - if (node instanceof HTMLElement) { - for (const subnode of node.querySelectorAll('a')) { - initLink(subnode); + if (isSocialNetwork) { + var observer = new MutationObserver(mutationsList => { + maybeDisableCustomCss(); + for (const mutation of mutationsList) { + if (mutation.type == 'childList') { + for (const node of mutation.addedNodes) { + if (node instanceof HTMLAnchorElement) { + initLink(node); + } + if (node instanceof HTMLElement) { + for (const subnode of node.querySelectorAll('a')) { + initLink(subnode); + } } } } } - } - solvePendingLabels(); - }); + solvePendingLabels(); + }); - observer.observe(document.body, { - childList: true, - subtree: true - }); - - document.addEventListener('contextmenu', evt => { - lastRightClickedElement = evt.target; - }, true); + observer.observe(document.body, { + childList: true, + subtree: true + }); + } } var lastRightClickedElement: HTMLElement = null; @@ -178,8 +196,10 @@ function updateYouTubeChannelHeader() { function updateAllLabels(refresh?: boolean) { if (refresh) knownLabels = {}; - for (const a of document.getElementsByTagName('a')) { - initLink(a); + if (isSocialNetwork) { + for (const a of document.getElementsByTagName('a')) { + initLink(a); + } } solvePendingLabels(); } diff --git a/extension/manifest.json b/extension/manifest.json index 6538bd7..c36c225 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -25,7 +25,7 @@ "*://duckduckgo.com/*", "*://*.bing.com/*", - + "*://*.google.ar/*", "*://*.google.at/*", "*://*.google.be/*", @@ -44,12 +44,18 @@ "*://*.google.pt/*", "*://*.google.se/*" ], - "js": [ - "content.js" - ], "css": [ "content.css" ] + }, + { + "all_frames": true, + "matches": [ + "*://*/*" + ], + "js": [ + "content.js" + ] } ], "web_accessible_resources": [