sorry if this has already been asked - I looked extensively, but can't find anything that seems to address it. Though it's quite possible it's been asked a dozen times already and the language used just went completely over my head. Which brings me to this: I'm not technologically stupid or anything, but as far as coding anything goes, that's another story entirely and I know virtually zero terminology regarding Chrome extensions. I just started googling about an hour ago.
Anyway, the question. I'm trying to make an extension to replace a single gif on a website I frequent. It's a loading image, so it appears on virtually every page, and it's just atrocious. The image is called (is that the right word?) by a script...rocket-script, I think it's called, which refers to it as ajax_loader, from browsing the page source? And the CSS stylesheet gave me the URL for the image.
So, here is the code I have, based on googling:
manifest.json
{
"manifest_version": 2,
"version": "1.0",
"name": "extensioname",
"description": "extensiondescription",
"content_scripts": [
{
"matches": ["websiteitselfurl.com*","URLofimagetobeblocked.gif"],
"js": ["part2.js"]
}
]
}
And then there's
part2.js
document.images[0].src = "replacementimage.gif";
document.images[0].height = "300";
document.images[0].width = "300";
Obviously those aren't the actual URLs, but...
All this ends up doing is replacing an image on every webpage, regardless of where it is, with the replacement gif. And not even the loading image in question on the site I am trying to replace in the first place.
I've tried changing the values in the "matches" line to a few different things, including at the end as in the example I found, and...that's literally all I can think to do.
I'd like to reiterate that I'm a complete know-nothing moron about this, so I apologize if it's already been asked, but I really cannot find an answer anywhere, and for the life of me I cannot get this to work myself and I'm out of ideas at this point. I registered here just to ask because I'm like ripping my hair out over it.
Any guidance whatsoever would be tremendously appreciated. Thank you!
Considering you are referring gif hosted in external site(imgur), you should use the full path of that image: https://i.imgur.com/Li7isRP.gif
manifest.json
{
"manifest_version": 2,
"version": "1.0",
"name": "extensioname",
"description": "extensiondescription",
"content_scripts": [
{
"matches": [
"http://websiteitselfurl.com/*", "https://websiteitselfurl.com/*"
],
"js": [
"content.js"
]
}
]
}
content.js
var ajax_loader = document.getElementById("ajax-loader");
ajax_loader.style.setProperty('background', 'url("https://i.imgur.com/Li7isRP.gif")', 'important');
// If needed, you could also change width/height of ajax_loader to better match the new image.
Just thought I would throw in another possible avenue for a solution. Since you want to replace a gif that loads in dynamically, it might be better to just redirect the request rather than try to alter the page after it is called. Something using the webRequest api would work well for this. For example:
manifest.json
{
"name": "VF Sample",
"version": "1.0.0",
"description": "A sample for VF gif replacement",
"manifest_version": 2,
"permissions": [
"webRequest","webRequestBlocking","http://vampirefreaks.com/*"
],
"background": {
"scripts": ["bgp.js"]
}
}
bgp.js
chrome.webRequest.onBeforeRequest.addListener(function(details){
return {redirectUrl:"http://i.imgur.com/Li7isRP.gif"};
},
{urls: ["http://vampirefreaks.com/_img/site/ajax-loader*"]},["blocking"]);
Related
Redoc is a great tool, but I'm struggling to understand how it works. Currently I've been tasked with copying some docs from api-docs.io to be self served using redoc.
However, my issue is that the schemas aren't appearing in the side bar as they do on the api-docs site. I'm not sure how I can get models to show on the side as well... And I'm fairly new to api documentation. You can also check out how the models are displayed here. And see another example below.
I've taken a look to see if this is a feature of redoc and came across this merged PR which (based on the discussion in the PR's issue) states that we should add an html element, SchemaDefinition. I am using the basic html file (suggested in the readme of the redoc repo), but we want to use a json schema (which is referenced with spec-url) to render the docs on redoc so I'm struggling to understand how I can manipulate the side bar using just the html element.
Maybe it's just my understanding of how redoc works that is lacking. If you feel that's the case, a quick explanation would be wonderful.
You have to modify the json with additional information.
Sample json (without sidebar model section): https://petstore3.swagger.io/api/v3/openapi.json
Add to "tags" array
{
"name": "pet_model",
"description": <SchemaDefinition schemaRef="#/components/schemas/Pet" />,
"x-displayName": "Pet"
},
{
"name": "user_model",
"description": <SchemaDefinition schemaRef="#/components/schemas/User" />,
"x-displayName": "User"
}
Then to group the sidebar add the x-tagGroups extension
...
"tags": [...],
"x-tagGroups": [{
"name": "Api",
"tags": ["pet", "store", "user"]
},
{
"name": "Models",
"tags": ["pet_model", "user_model"]
}],
"paths": ...
This question is more for the benefit of others and my own curiosity, as I have synthesized a workaround for now (using "matches": ["http://*/*", "https://*/*"] and if (location.hostname == "www.youtube.com").
Anyway, when I have an issue like this I break the code down into simpler and simpler forms until it starts to work. Then I can figure out what's tripping up the code. But I've hit that point now where it can't get simpler and it still doesn't work. Chrome just won't inject a content script into any of YouTube's pages.
Files (link to ZIP of the following)
manifest.json:
{
"name": "test",
"version": "0",
"manifest_version": 2,
"content_scripts": [
{
"js": [
"test.js"
],
"matches": [
"*://youtube.com/*"
],
"run_at": "document_end",
"all_frames": true
}
]
}
test.js:
alert("test");
Progress
Doesn't work:
Varying the values and statically defining (no wildcards) the matches URL
Varying the values of run_at
Varying the values of all_frames
Varying the scripting in test.js
Fresh install of Chrome v24.0.1312.57 on a fresh install of Windows 7 x64
Does work:
Changing the matches value to ANYTHING other than YouTube
Changing the matches value to "http://*/*", "https://*/*"
I feel like I'm missing something really obvious here, but it's been days.. ;/
This works for me if you define the match in the manifest as "http://www.youtube.com/*"
I'm having a problem controlling what pages my content scripts are injected into. The chrome extension developer guide specifies that I can use an "exclude_matches" directive in my manifest.json to exclude certain pages from injection.
However, this doesn't seem to have any effect. My content script still executes on pages that I have specified as ignored.
I have put the steps to reproduce in a Gist. The code is also available on Github.
Any ideas what I'm doing wrong?
manifest.json
{
"name": "Testing Extension",
"version": "1.0",
"description": "Test the chrome extensions exclude_matches.",
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"exclude_matches": ["http://news.ycombinator.com/"],
"js": ["content.js"]
}]
}
content.js
console.log("hello from the content script");
This is Bug #100106. exclude_matches do not function properly.
To solve the problem, use exclude_globs instead of exclude_matches.
Also, your exclude_matches rule does only match http://news.ycombinator.com/.
Suffice the pattern with an asterisk to match the whole site: http://news.ycombinator.com/*.
See also: Match patterns.
I'm trying to write a simple Chrome extension. I learnt how to write the "hello world" extension that Google put out, but how do I write an extension that will actually do something? Nothing online seems to explain it well. I know it involves HTML and CSS(? ), but what do I do? Say I want to write an extension that will enlarge everything--do I write an HTML file that does this and stick it in my extension folder? And what do I write in the manifest.json file so that it actually uses the HTML file?
Also, I'm a total beginner (I don't know HTML, all I know is a bit of Java) if you couldn't tell from the basic-ness of my questions.
In order to interact with the DOM of the site the user is viewing once the extension is installed you need to use content scripts. Look at the added lines in the manifest here:
http://code.google.com/chrome/extensions/content_scripts.html
Those lines let you indicate what js and css you want to use for the site and also specify what specific domains with 'matches':
"content_scripts": [
{
"matches": ["http://www.google.com/*"],
"css": ["mystyles.css"],
"js": ["jquery.js", "myscript.js"]
}
],
Files needed:
icon.png ( http://www.mediafire.com/imageview.php?quickkey=37phkkdmd1dv1zf&thumb=4 )
manifest.json
popup.html
Put all in a folder together.
.
in the manifest.json:
{
"name": "My First Extension",
"version": "1.0",
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png"
},
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
}
}
put in popup.html:
hello world
Save both files.
go to extentions ( chrome://extensions/ )
And click developer mode. http://snpr.cm/HBuhYF.jpg
Click "load unpacked extention". and locate the folder.
It should load fine.
Click on the new extention and see the glory :)
edit, just read your post - you learned a hello world /facepalm
I'm developing a google chrome extension and I'm running into a relative path problem.
If I give a relative path to an image and open the plugin in a certain page it will look for that image in the website's path rather than the extension's.
Any ideas?
If you're using CSS in your extension pages (background, popup, infobar, etc) then you can use relative paths with a slash (/):
background-image:url("/sprites.png");
The above should work, everyone uses it. But, if your using it for content scripts and you can do the same for any css, you would need to use the predefined message like:
background-image:url('chrome-extension://__MSG_##extension_id__/sprites.png');
If you want to programmatically set it, you can use the chrome.extension.getURL syntax as following:
var url = chrome.extension.getURL('sprites.png');
These are the ways that you can refer to a specific url/image.
In addition, as mentioned in this answer, if you place your image assets in a directory, these files are not accessible in the web page DOM automatically. The developer should specify the resources that can be loaded the page by using the "web_accessible_resources" setting in the manifest.json file:
#mohamed's answer worked for me but it took my a while to put it all together. I've answered this else where but here is the solution that worked for me.
My solution.
With Menifest v2 you need to add web_accessible_resources to the file and then use chrome-extension://__MSG_##extension_id__/images/pattern.png as the url in your css file.
CSS:
#selector {
background: #fff url('chrome-extension://__MSG_##extension_id__/images/pattern.png');
}
Manifest.json
{
"manifest_version": 2,
"name": "My Extension Name",
"description": "My Description",
"version": "1.0",
"content_scripts": [
{
"matches": ["https://mydomain.com/*"],
"css": ["style.css"]
}
],
"permissions": [
"https://mydomain.com/"
],
"browser_action": {
"default_icon": {
"19": "images/icon19.png",
"38": "images/icon38.png"
},
"default_title": "My Extension Name"
},
"web_accessible_resources": [
"images/pattern.png"
]
}
p.s. Your manifest.json might look different to this one.
In some cases you might even use inline base64 encoding of the image. For example,
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB..." />
Same you can apply to your CSS. You can find image encoders all over the web.