Initial support for site homepages

This commit is contained in:
shinigami-eyes 2019-10-06 13:04:11 +02:00
parent 825274213a
commit ce74cda636
3 changed files with 66 additions and 28 deletions

View File

@ -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",
]
});
}

View File

@ -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 = <HTMLElement>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 = <HTMLElement>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();
}

View File

@ -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": [