javascript - Inject JS function with Greasemonkey -


i have pretty simple html code displays browsers current working area:

<html> <head> </head> <body> <script type="text/javascript"> wwidth  = document.body.clientwidth; wheight = document.body.clientheight; alert("working area is: " + wwidth + "x" + wheight); </script> </body> </html> 

i trying tamper these values own ones using following greasemonkey script (i have used following topic reference) not seem work:

// ==userscript== // @name        resolution // @namespace   1 // @include     * // @version     1 // @grant       none // ==/userscript==  function main () { object.defineproperty(body, "clientwidth", {value: '1000'}); object.defineproperty(body, "clientheight", {value: '1000'}); }  var script = document.createelement('script'); script.appendchild(document.createtextnode('('+ main +')();')); (document.body || document.head ||document.documentelement).appendchild(script); 

this first work javascript , may find pretty simple issue can not find solution appreciated.

thank in advance!

you can use basic javascript this, see example https://jsfiddle.net/5os5r8e2/1/

<body>   <input type="button" value="change height" onclick="cheight()">   <input type="button" value="change width" onclick="cwidth()"> </body> <script>   wwidth = document.body.clientwidth;   wheight = document.body.clientheight;   alert("working area is: " + wwidth + "x" + wheight);    function cheight() {     document.body.style.height = "1000px";   }    function cwidth() {     document.body.style.width = "50%";   }  </script> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -