[Greasemonkey] DOM question: figuring out how wide a page is

Mark Pilgrim pilgrim at gmail.com
Fri Apr 29 14:48:16 EDT 2005


On 4/29/05, Julien Couvreur <julien.couvreur at gmail.com> wrote:
> - I couldn't find a way of detecting that the page is currently too
> wide for my display (and thus creates a horizontal slide bar). Any
> ideas?

In DOM Inspector, I see
body.offsetTop/offsetLeft/offsetWidth/offsetHeight, as well as
body.scrollTop/scrollLeft/scrollWidth/scrollHeight.  Not to mention
body.clientHeight/clientWidth.  Surely some combination of those will
give you the information you need.

> - Is there something similar to the DOM but to navigate/edit the CSS?

Using DOM Inspector, I see document.styleSheets (note camelCase), and
using Javascript Shell, I see that it is traversable.  My Shell
session:

var s = document.styleSheets;

s
[object StyleSheetList]

props(s)
Fields: 0
Methods of prototype: item
Fields of prototype: length

s.item(0);
[object CSSStyleSheet]

s1 = s.item(0);
[object CSSStyleSheet]

s1
[object CSSStyleSheet]

props(s1)
Methods of prototype: insertRule, deleteRule
Fields of prototype: type, disabled, ownerNode, parentStyleSheet,
href, title, media, ownerRule, cssRules

s1.cssRules
[object CSSRuleList]

props(s1.cssRules)
Fields: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54
Methods of prototype: item
Fields of prototype: length

s1.cssRules(0)
TypeError: s1.cssRules is not a function

s1.cssRules[0]
[object CSSStyleRule]

rule = s1.cssRules[0]
[object CSSStyleRule]

props(rule)
Fields of prototype: type, cssText, parentStyleSheet, parentRule,
selectorText, style, UNKNOWN_RULE, STYLE_RULE, CHARSET_RULE,
IMPORT_RULE, MEDIA_RULE, FONT_FACE_RULE, PAGE_RULE

rule.cssText
html { margin: 0pt; padding: 0pt; }

rule.style
[object CSSStyleDeclaration]

rule.style.marginTop
0pt


-- 
Cheers,
-Mark


More information about the Greasemonkey mailing list