Chrome extension to make a small CSS change to *.google.com - google-chrome

I just wrote a simple extension that has permission to *.google.com and changes some CSS on one class, and I think I overlooked something simple. I'm changing the +1 button, which is implemented like so:
<button ... class="esw eswd BRowJd Jt">
In my style.css I say:
button.eswa { border: 2px solid #000000; }
the change never appears. I also tried switching the class to Jt in case that was overriding my CSS, no luck. The class that defines the unclicked +1 button is the "eswa", fyi.
As per the documentation I also set permissions to the sites I want to alter in my manifest.json
{
"name": "G+ Rebrander",
"version": "0.92",
"description": "Returns the original branding for G+ (pre March 2012) such as the +1 button.",
"browser_action": {
"default_icon": "g-plus.png"
},
"icons":{
"128":"g-plus128.png"
},
"permissions": [
"http://plus.google.com/",
"https://plus.google.com/",
"http://*.google.com/",
"https://*.google.com/",
"tabs"
]
}

In the future listing your whole manifest.json file would be extremely helpful, since your didnt its hard for me to know exactly what your doing and thus what your error could be....so Ill just list a few possibilities.
Using !important in your css rule is always a good idea when overriding css.
Permissions is for if your injecting code from say the background page, not content scripts that get automatically added. The docs are slightly vague on that.
For content scripts that get added automatically you only need to set the matches field of the content script.
Your matches dont have a * at the end of them and as such would only match the front page and not any search results, which is what I assume your targeting.
Keep in mind that google will typically redirect to a server in your country, so for me going to www.google.com will be redirected to www.google.com.au.
The unlicked +1 for me was ewsd, not ewsa.
If your only injecting css and not a script aswell then its a good idea to use the run_at field with a value of document_start. This will make sure your css is applied before the page is visible and thus avoid the page changing later when it gets applied. If you use this then you must use !important or the css added by the page later will override your css rule.
So with all that a working manifest and css file looks like this.....
manifest.json
{
"name": "css rules",
"content_scripts": [
{
"matches": [
"*://*.google.com/*",
"*://*.google.com.au/*"
],
"css": ["new.css"],
"run_at" : "document_start"
}
],
"version":"1.0"
}
new.css
button.eswd { border: 2px solid #000000 !important;}

Set !important on the element to overwrite Google's style.

Related

How do I enable only specific snippets in strings and why is my json snippet not working in json?

Ok, I am new to coding and just found out about costume snippets in VS-Code. I wrote some and they all worked pretty much as expected, but now I have some problems/questions. I have done some research but couldn't find any solutions.
1. how do I enable for example this snippet only in strings? Is there even a way? I don't want all my snippets to work in strings, just some.
"tab": {
"prefix": ["tab"],
"body": [
"${1|\\t,\\t\\t,\\t\\t\\t,\\t\\t\\t\\t,\\t\\t\\t\\t\\t,\\t\\t\\t\\t\\t\\t|}$0"
],
"description": "insert escaped tab"
},
adding this to the settings enables all snippets in strings which i don't want
"editor.quickSuggestions": {
"strings": true
},
2. I have written a snippet that should insert some lines into my launch.json file and it basically works the way I want, but only if I put the snippet in my global snippet file and not set the scope to json. It also does not work if I put it in the json snippet file (json.json). Why?
"launch json": {
// "scope": "json",
"prefix": "launch",
"body": [
"\"version\": \"0.2.0\",",
"\"configurations\": [",
"\t{",
"\t\t\"type\": \"${1|firefox,chrome|}\",",
"\t\t\"reAttach\": false,", // is there a way to auto remove this line if chrome is chosen
"\t\t\"request\": \"launch\",",
"\t\t\"name\": \"Launch index.html\",",
"\t\t\"file\": \"\\${workspaceFolder}/index.html\"",
"\t}",
"],",
"$0",
],
"description": "insert launch json"
},
that's the snippets output
"version": "0.2.0",
"configurations": [
{
"type": "firefox",
"reAttach": false,
"request": "launch",
"name": "Launch index.html",
"file": "${workspaceFolder}/index.html"
}
],
also is there a way to change the inserted lines depending on what option I chose from the list?
it's not really necessary, just wondering (the "reAttach": false, option only exists with firefox, so i don't need the line if i choose one of the other options)
3. Another problem I have is that I copied and then customized some already existing snippets (for java for example) and now it is showing both options in intellisense. I know, I know, I can press F1 -> insert snippet and click the eye symbol behind them to hide them from intellisense but that only works if the snippet actually is in the list, which isn't true for all of them. I just can't find some of them. Where can I find and disable them?
4. One last thing, I tried making a snippet for css with "prefix": ["*","somethingElse"], but i could not use the snippet with the * only the somethingElse worked, why is that? I already made two other snippets that use . and # as prefix and they also worked just fine. Is there something special about * when it comes to snippets?
I have no idea how to fix the main 4 problems or what causes them. But one way I thought about solving the optional line problem was something like this:
"\t\t\"type\": \"${1|firefox,chrome|}\",${2:\n\t\t\"reAttach\": false,}",
that way I can delete the line with one button if I don't need it. But the question was more about if it's possible in general so change some other lines depending on the option chosen from the list.

Disable wavy yellow underline in vs code for HTML

How do I ignore this error. I have used the id attribute for some tags in order to reference them by id in javascript, but it shows this error:
CSS id selector '...' not found.
Please tell me how to ignore or disable this error.
maybe your css is not formatted properly.
try:
<style>
#phone {
your css here;
}
</style>
You need to make sure you mark the code with # to show that it's an id and not a class or something else.
Update: First section of answer no longer valid as of the lastest updates since original post which removed the css.validation option. see
If you are using the HTML CSS Support extension by ecmel, you can go to .vscode/settings.json and add
"css.validation": {
"id": false,
"class": false
}
This will turn off css validation for class name and id.
More information on this at the Visual Studio MarketPlace for this extension under Selector Validation here or the Github repository readme Selector Validation Section
Note:
1) Also don't forget to add a comma after the setting that comes before (as JSON format is comma separated).
Example:
{
"java.codeGeneration.generateComments": true,
"css.styleSheets": [
// (1)
"https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css",
"src/main/resources/static/css/styles.css"
],
"css.validation": {
"id": false,
"class": true
}
}
Sometimes you need to restart / close and reopen vscode after saving changed to the file for them take effect.
There is a way to configure styleSheets. This next bit is taken from their documentation see Additional Styles Section:
Additional Style Sheets
If it is not possible to specify local or remote styles in HTML or via
template inheritance, they can be specified in VS Code settings per
workspace folder in .vscode/settings.json and will suggest for all
HTML files within that workspace folder:
.vscode/settings.json
"css.styleSheets": [
// (1)
"https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css",
// (2)
"/site.css",
// (3)
"site.css",
// (4)
"./site.css"
]

How does weava highlighter extension works under the hood?

There's weava highlighter extension which make it possible to highlights articles/pdf and store highlight on the server.
I can't understand how does it keep highlights after the page reloaded. What does need to be stored to find the highlighted section after the page reloaded? I can't store text, because text can be duplicated. CSS selectors not enough too, how does it work?
Tried to debug the extension, but the code is highly uglified and it's difficult to understand what's going on.
Actually, it stores enough text to describe the beginning and the end of the section to ensure uniqueness, found following traces in the console:
"-MI0L15LAX*************": {
"accessRight": {
"HZTU1cv32******************": "owner"
},
"createDate": 1600971612666,
"creator": "HZTU1cv32******************",
"favIconUrl": "https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196",
"highlights": {
"d1311a13-d334-467c-8915-5faf412a689f": {
"colorNum": 3,
"creator": "HZTU1cv32p******************",
"date": 1600972075045,
"endStr": "afterthepagereloaded?ican'tsto",
"startStr": "tobestoredtofindthehighlighted",
"text": "section"
}
},
"title": "html - How does weava highlighter extension works under the hood? - Stack Overflow",
"url": "https://stackoverflow.com/questions/64052135/how-does-weava-highlighter-extension-works-under-the-hood",
"version": "0.0.3"
}
It isn't perfect, and error-prone (I was able to trick it to highlight the wrong section), but it looks that there's enough for most people.
Another drawback of such an approach, if the article changed a little bit (typo, etc...) the highlights can be lost.

Re-Direct a page but not subdomain

I would like to be able to redirect a page to a subdomain using a chrome extension. After numerous attempts, nothing works.
Ideally, I want:
"https://www.facebook.com" -> "https://www.facebook.com/groups/123456789"
and "https://www.facebook.com/*" to be left alone (where * is a wild card).
To me it should be simple as there are no variables, but it doesn't appear to be. A further complication is that I started learning java yesterday, I am okay at html, c++, c, vb etc.
Why? Because I use facebook to keep up to date with solutions to problem sheets and things on my course, but my news feed is a) Distracting and b) rubbish.
If you can help you'd be a star (if you could comment your code that'd be awsome as I can learn a bit then as well) :D
So far I have, but it doesn't work :(
manifest.json
{
"name": "Tabber",
"manifest_version" : 2,
"version": "1.0",
"description": "MyExtension",
"chrome_url_overrides": {
"*www.facebook.com*": "my.html"
},
"permissions": [
"tabs"
]
}
my.html
<!DOCTYPE html>
<html>
<head>
<head>
<meta http-equiv="refresh"content="0;URL=http://www.google.com">
</head>
</head>
<body>
</body>
</html>
First, your mistakes.
chrome_url_overrides can only override bookmarks, history or newtab pages.
https://www.facebook.com/groups/123456789 is not a "subdomain"
It's JavaScript, not Java
Second, how to do it.
It's relatively easy to do with a content script. You don't need a tabs permission even, just the host permission for Facebook.
Manifest:
{
"name": "Tabber",
"manifest_version" : 2,
"version": "1.0",
"description": "MyExtension",
"content_scripts": [
{
matches: ["*://www.facebook.com/*"],
js: ["myscript.js"],
runAt: "document_start"
}
]
}
Then, your script will be injected when any tab navigates to any facebook page.
The script itself should check the URL and navigate away if needed:
// myscript.js
if(window.location.pathname == "/") {
window.location.replace("https://www.facebook.com/groups/123456789");
}
I don't use FB myself, so not sure if it will break any logic; but it's what you were trying to do.

twitter bootstrap css clashes while in chrome extensions

I am using bootstrap for a chrome extension I am writing. When imported as content script the css seem to clash with alot of the sites I am viewing (even in google search result page).
Wondering if there is anything i can do to scope this to just the dom elements I inject using content script?
The solution is to use <style scoped>.
Essentially it allows you to apply a style to a DOM node and its children, but not its parent nodes. There's a nice article on CSS-Tricks explaining how to use it.
The problem is that it's not very well supported, even in Chrome, so you'll have to use a jQuery polyfill. This is basically a jQuery plugin that simulates the functionality you'd expect from <style scoped>.
Here's a working JSFiddle doing exactly that using Bootstrap.
Here's an example of how you could implement it in your extension:
content_script.js:
$.scoped(); // Initialize the plugin
...
bootstrapped = document.createElement("div");
bootstrapped.innerHTML = "<style scoped>";
bootstrapped.innerHTML += "#import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');";
bootstrapped.innerHTML += "</style>";
document.body.appendChild(bootstrapped);
...
document.body.appendChild(myDOM); // Will not possess Bootstrap styles
bootstrapped.appendChild(myDOM); // Will possess Bootstrap styles
For now, make sure to include jQuery in your page, as well as the Scoped Plugin:
"content_scripts": [ {
"js": [ "jquery.min.js", "jquery.scoped.min.js", "content_script.js" ],
"matches": [ "http://*" ]
}]