0

I have a pretty simple HTML code that 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 am trying to tamper these values with my own ones using the following Greasemonkey script (I have used the following topic as a reference) which does not seem to work:

// ==UserScript==
// @name        Resolution
// @namespace   One
// @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 is my first work with javascript and some may find this to be a pretty simple issue but I simply can not find a solution to it so any help would be really appreciated.

Thank you in advance!

Community
  • 1
  • 1

1 Answers1

0

You can use basic javascript for 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>
Adam Buchanan Smith
  • 9,422
  • 5
  • 19
  • 39