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/*", "*://*.google.com/*",
"*://*.bing.com/*", "*://*.bing.com/*",
"*://duckduckgo.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'; if (hostname.endsWith('.youtube.com')) hostname = 'youtube.com';
var myself: string = null; var myself: string = null;
var isSocialNetwork: boolean = null;
function fixupSiteStyles() { function fixupSiteStyles() {
if (hostname == 'facebook.com') { if (hostname == 'facebook.com') {
@ -81,6 +82,21 @@ function maybeDisableCustomCss() {
} }
function init() { 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(); fixupSiteStyles();
if (domainIs(hostname, 'youtube.com')) { if (domainIs(hostname, 'youtube.com')) {
@ -93,9 +109,14 @@ function init() {
console.log('Self: ' + myself) console.log('Self: ' + myself)
document.addEventListener('contextmenu', evt => {
lastRightClickedElement = <HTMLElement>evt.target;
}, true);
maybeDisableCustomCss(); maybeDisableCustomCss();
updateAllLabels(); updateAllLabels();
if (isSocialNetwork) {
var observer = new MutationObserver(mutationsList => { var observer = new MutationObserver(mutationsList => {
maybeDisableCustomCss(); maybeDisableCustomCss();
for (const mutation of mutationsList) { for (const mutation of mutationsList) {
@ -119,10 +140,7 @@ function init() {
childList: true, childList: true,
subtree: true subtree: true
}); });
}
document.addEventListener('contextmenu', evt => {
lastRightClickedElement = <HTMLElement>evt.target;
}, true);
} }
var lastRightClickedElement: HTMLElement = null; var lastRightClickedElement: HTMLElement = null;
@ -178,9 +196,11 @@ function updateYouTubeChannelHeader() {
function updateAllLabels(refresh?: boolean) { function updateAllLabels(refresh?: boolean) {
if (refresh) knownLabels = {}; if (refresh) knownLabels = {};
if (isSocialNetwork) {
for (const a of document.getElementsByTagName('a')) { for (const a of document.getElementsByTagName('a')) {
initLink(a); initLink(a);
} }
}
solvePendingLabels(); solvePendingLabels();
} }

View File

@ -44,12 +44,18 @@
"*://*.google.pt/*", "*://*.google.pt/*",
"*://*.google.se/*" "*://*.google.se/*"
], ],
"js": [
"content.js"
],
"css": [ "css": [
"content.css" "content.css"
] ]
},
{
"all_frames": true,
"matches": [
"*://*/*"
],
"js": [
"content.js"
]
} }
], ],
"web_accessible_resources": [ "web_accessible_resources": [