javascript - Content script & jQuery. Download/get DOM from different web page -


I am trying to modify the img src attribute by getting the URL from a different page. I need to find it by inspecting DOM because it is not static data; I'm looking through classes and IDs.

My knowledge of Chrome Extensions is very limited over time. Basically I started just look at the "PSEUDO CODE" section of Background.js

manifest.json

  {"manifest_version": 2, "name": "# "####", "version": "1.0", "description": "#####", "browser_action": {"name": "#####", "icon": ["icon "[[jquery.min.js']," background.js "]," match ": [" http: //png "]," default_icon ":" icon_script "}," content_script " //www.youtube.com/watch?v=AzHzqqqqqqqqz) 

var l = document.getElementsByTagName ("div"); {var obj = l [i] for (var i = 0; i & lt; l.length; i ++) parentNode; If (l [i] .getAttribute ("class") & amp; amp; l [i] .getAttribute ("class") == "user_contact") {var div = l [i]; Var id = div.getAttribute ("id"). Replace ("u_", "0"); var profileUrl = "../" + id + "/"; Var imgs = div.getElementsByClassName ("userpic"); Log ("found img.userpic:" + imgs.length); If (IMG & IMGS.lmg> 0) {var img = imgs [0]; var alink = document.createElement ('a'); img.parentNode.appendChild (ALINK); alink.setAttribute ("href", profile url); alink.appendChild (img); // PSEUDO code - unknown // // Download profile page page html // search for given element // drag rr extract value from it // apply to iGG here}}}

So how to download different pages in a nutshell and work with it

Since you first I have already added and tagged my question with it, I am going to answer with the code jQuery , I hope That you do not have any brain. So first I write that what you have in the jQuery :

  $ ('div.user_contact'). Each (function () {var id = $ (this) [0] .id.replace ('_ u', '0'); var profile = approx .. = "../" + id + "/" var imgs = $ (this) .find ('. UserPic'); if (imgs.length & gt; 0) {var alink = $ (document.createElement ('a')); $ (this) .append (alink); $ ( alink) .attr ('href', profile url); $ (alink) .append (IMGS [0]); // This is the page where you can find the page and search for the diva that you want $. (Profile URL, Function (Data) {// Since I do not know what layout / I will just put in some placeholder $ (IMGS). Le (). Atr ('src', $ ('img.youWant', data). First (). Attr ('src'));}); // Since $. Is asynchronous, doing this creates this problem // if there is more than one div.user_contact. // In that case where they have fewer numbers and you are running OK / after synchronizing / synchronous code, you can do it with it instead : $$. Ajax (profile, {async: false, success: function (data) {}});   

You have permissions in your manifest for that site You will need to include the person whom you are $ From: Something like this:

  "permissions": ["*: //*.badoo.com/*"]    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -