Ad
Excluding Domains From Content_scripts In Manifest.json Doesn't Work For CSS Files?
I want to write a chrome extension to force all websites to use given CSS style except Gmail page. However the following code from content scripts in manifest.json
doesn't work (Gmail page will still use the style given in font.css
).
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"exclude_matches": ["*://mail.google.com/*"],
"css": ["font.css"]
}]
This cannot be fixed even adopting the strategy advised here by replacing exclude_matches with exclude_globs.
I know this bug existing for a while, so-called Bug #100106. Any idea on how to fix this? Or are there any alternative ways I can use to achieve my goal?
Ad
Answer
You can filter pages manually if you inject CSS from some content JavaScript code. I've just did a quick test, and the following works in Chrome 31.0.1650.63:
manifest.json:
{
"manifest_version": 2,
"name": "My Style",
"description": "Insert custom CSS",
"version": "0.1",
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["font.js"],
"run_at":"document_start"
}],
"web_accessible_resources": ["font.css"]
}
font.js
if (location.hostname.indexOf(".google.com") == -1) {
var link = document.createElement("link");
link.href = chrome.extension.getURL("font.css");
link.type = "text/css";
link.rel = "stylesheet";
document.documentElement.insertBefore(link);
}
font.css
body {
color: red;
}
This way font.css script is injected into all non-Google pages.
Ad
source: stackoverflow.com
Related Questions
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → How to dynamically add class to parent div of focused input field?
- → Expanding search bar not expanding before search
- → Include external javaScript CSS in laravel 5
- → Using css modules how do I define a global class
- → How to add a timer in HTML5 and Javascript?
- → Conditional BG Color on AngularJS
- → Divs aren't aware of screen resizing
- → Setting the height of a textarea inside a table
- → How can I get Greasemonkey to highlight visited image links?
- → How to handle onclick event of a button?
Ad