Edit Edit - 6 months ago 24
HTML Question

Adding an image next to text if the text links to a certain page

So I've been working on a chrome extension that basically just changes up fonts and the color scheme of a certain website. I decided that as a kind of cool easter-eggy type thing it would be cool if the chrome extension's logo showed up next to my name when I posted on the site's forums.

What would be the best way of doing this? I'm able to inject CSS and JS into the site. I was thinking that a script looks for an a tag that links to my profile page, and then adds the icon the right of it or something. I have basically no experience with Javascript so any help is much appreciated.


Answer Source
var x = document.querySelectorAll("a");
for(var i=0;i<x.length;i++){
    if(x[i].href.indexOf('LINK_TO_YOUR_PROFILE')==-1) // skip if link is not a link to your profile
    var node = document.createElement("img");
    node.src = "http://via.placeholder.com/350x150";

try this code

It will search for all anchor tags and add them to array "x" and then it loops over the array and creates a new img node and adds it next to the a tag. You just have to change the img src of course!

hope my answer is what you are looking for!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download