Javascript for chrome extension -


i'm trying create button on page

my manifest.json has content script inject.js , inject.js this

var botao_comunidades = document.queryselector('a[href="#communities"]');  var botao_teste = document.createelement('p'); botao_teste.innerhtml = '<a href="#">test</a>'; botao_teste.classname = "themelighttransparency nsc"; botao_comunidades.insertadjacentelement('afterend',p); 

manifest.json

{ "name": "teste", "version": "0.0.1", "manifest_version": 2, "description": "teste", "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" }, "default_locale": "en", "permissions": [ "<all_urls>" ], "content_scripts": [ {   "matches": [     "https://www.orkut.com.br/*"   ],   "js": [     "src/inject/inject.js"   ]   ]  } ] } 

and nothing :(

from manifest, delete ] closes content_scripts.js (if want make exact code work, there few other steps mentioned @ end). when load script, console @ website says uncaught referenceerror: p not defined on line 6. change last line botao_comunidades.insertadjacentelement('afterend',botao_teste); , works.

other steps make this exact code work:

  • delete “icons” , “default_locale” manifest
  • change content_script.matches “http://www.orkut.com.br/*”
  • change first line of inject.js use queryselector('#signupviewport’);

here's finished product:

manifest.json:

{     "name": "teste",     "version": "0.0.1",     "manifest_version": 2,     "description": "teste",     "permissions": [     "<all_urls>"     ],     "content_scripts": [     {         "matches": [         "http://www.orkut.com.br/*"         ],         "js": [         "src/inject/inject.js"         ]     }     ] } 

src/inject/inject.js:

var botao_comunidades = document.queryselector('#signupviewport');  var botao_teste = document.createelement('p'); botao_teste.innerhtml = '<a href="#">test</a>'; botao_teste.classname = "themelighttransparency nsc"; botao_comunidades.insertadjacentelement('afterend',botao_teste); 

and screen shot ("test" in bottom left):

screen shot


now it's turn little more descriptive in how it's not working.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -