Skip to content

Instantly share code, notes, and snippets.

@stripedpurple
Last active January 18, 2019 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stripedpurple/ef4d8e4e15542e32601fda8d0021db5f to your computer and use it in GitHub Desktop.
Save stripedpurple/ef4d8e4e15542e32601fda8d0021db5f to your computer and use it in GitHub Desktop.
Simple User script that gives the dimensions of the current window.
// ==UserScript==
// @name Window Dimensions
// @namespace http://stripedpurple.io
// @version 2.0
// @description adds a dimension list to screen
// @author Austin Barrett
// @match *://localhost/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var createDimensions = function() {
var dimension = document.createElement("span"); // Create a <button> element
dimension.setAttribute("id", "myDimensions");
var t = document.createTextNode((function() {
var w = window.innerWidth;
var h = window.innerHeight;
return w + ' x ' + h;
})());
dimension.appendChild(t);
dimension.style.background = "#333";
dimension.style.color = "white";
dimension.style.position = "fixed";
dimension.style.bottom = "0";
dimension.style.right = "0";
dimension.style.zIndex = "100000";
dimension.style.padding = "3px";
dimension.style.fontSize = "12px";
dimension.style.fontFamily = "Arial";
document.body.appendChild(dimension);
};
var updateDimensions = function() {
var w = window.innerWidth;
var h = window.innerHeight;
document.getElementById("myDimensions").innerHTML = w + ' x ' + h;
};
window.onload = createDimensions;
window.onresize = updateDimensions;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment