javascript - Chrome extension: Insert fixed div as UI -


i want insert div fixed position using chrome extension. overlay page viewing. concern want work on page without altering (other inserting fixed div), don't know if possible way i'm doing it. currently, button won't show up, , had lot of trouble getting div show up. way, positioning temp now, position correctly once on page! :) here's have:

here manifest:

{     "name":"poop",     "version":"0.1",     "manifest_version":2,     "description":"shitty app i'm making",     "background":{         "scripts":[             "scripts/modernizr.min.js",              "scripts/background.js"             ],         "persistent": false     },     "permissions":[         "contextmenus",          "tabs",         "http://*/*",         "https://*/*"         ],     "icons":{         "16":"images/icon_16.png",         "128":"images/icon_128.png"     } } 

here function in background.js performing functionality:

function insertuidiv() {            var prephtmlstyle   =   "document.documentelement.style.height = '100%';" +                             "document.body.style.height = '100%';" +                             "document.documentelement.style.width = '100%';" +                             "document.body.style.width = '100%';";      var insertdiv       =   "var div = document.createelement( 'div' );" +                             "var btnform = document.createelement( 'form' );" +                             "var btn = document.createelement( 'input' );" +                             //append elements                             "document.body.appendchild( div );" +                             "div.appendchild( btnform );" +                             "btnform.appendchild( btn );" +                             //set attributes div                             "div.id = 'mydivid';" +                             "div.style.position = 'fixed';" +                              "div.style.top = '50%';" +                             "div.style.left = '50%';" +                             "div.style.width = '100%';" +                                "div.style.height = '100%';" +                              "div.style.backgroundcolor = 'red';" +                              //set attributes btnform                             "btnform.action = '';" +                             //set attributes btn                             //"btn.removeattribute( 'style' );" +                             "btn.type = 'button';" +                             "btn.value = 'hello';" +                             "btn.style.position = 'absolute';" +                             "btn.style.top = '50%';" +                             "btn.style.left = '50%';";        chrome.tabs.executescript( null, { code: prephtmlstyle } );          chrome.tabs.executescript( null, { code: insertdiv } );               } 

manipulating content background.js bad idea. why don't use content script?

manifest.json

{     "name":"poop",     "version":"0.1",     "manifest_version":2,     "description":"shitty app i'm making",     "background":{         "scripts":[             "scripts/modernizr.min.js",              "scripts/background.js"             ],         "persistent": false     },     "content_scripts": [       {         "matches": ["https://*/*", "http://*/*"],         "js": ["content.js"],         "run_at": "document_end"       }     ],     "permissions":[         "contextmenus",          "tabs",         "http://*/*",         "https://*/*"         ],     "icons":{         "16":"images/icon_16.png",         "128":"images/icon_128.png"     } } 

content.js

document.documentelement.style.height = '100%'; document.body.style.height = '100%'; document.documentelement.style.width = '100%'; document.body.style.width = '100%';  var div = document.createelement( 'div' ); var btnform = document.createelement( 'form' ); var btn = document.createelement( 'input' );  //append elements document.body.appendchild( div ); div.appendchild( btnform ); btnform.appendchild( btn ); //set attributes div div.id = 'mydivid'; div.style.position = 'fixed'; div.style.top = '50%'; div.style.left = '50%'; div.style.width = '100%';    div.style.height = '100%'; div.style.backgroundcolor = 'red';  //set attributes btnform btnform.action = '';  //set attributes btn //"btn.removeattribute( 'style' ); btn.type = 'button'; btn.value = 'hello'; btn.style.position = 'absolute'; btn.style.top = '50%'; btn.style.left = '50%'; 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -