For a long time I used a greasemonkey script to add some CSS to an XML file 
because it was a bit tedious to read the pure XML.

The script goes like this (stripped down a bit):

// ==UserScript==
// @name           checkloaded with style
// @namespace      checkloaded
// @include        */...my url here
// @grant          GM_setValue
// @grant          GM_getValue
// @grant          GM_deleteValue
// ==/UserScript==

if (GM_getValue(document.location.href, 0) == 1) {
     GM_deleteValue (document.location.href);
}
else {
    pi=document.createProcessingInstruction('xml-stylesheet', 'href="#" 
type="text/css"')
    
    document.documentElement.parentNode.insertBefore( pi, 
document.documentElement );
    
    var resultcode= document.getElementsByTagName('result-code')[0];
    resultcode.addEventListener("click", function() {
            GM_setValue(document.location.href, 1);
            history.go(0);
    }, true);

    resultcode.setAttribute("title", "Click to see raw XML");
    window.setTimeout(
        function() {
            var i=0;
            var css=document.styleSheets[0];
            css.rel='stylesheet';
            css.insertRule("response { \
                display: block;        \
                font-family: Arial;    \
                padding:2px;           \
                font-size: 8pt;        \
                color: white;             \
                background-color:#e60000; \
            }", i++);
            css.insertRule("response:after { \
                content: \"© by me \"; \
            }", i++);
            css.insertRule("result-code { \
                display: inline;           \
                padding:2px 2px 2px 20px; \
                color: white;             \
                font-size: 3em;           \
                cursor: pointer;          \
            }", i++);
            css.insertRule("loaded-list {            \
                display: table;                      \
                margin-left:auto; margin-right:auto; \
                border-collapse: collapse;           \
                color: black;             \
            }", i++);
            css.insertRule("property:nth-child(even) { \
                display: table-row;                   \
                background-color: #d0d0d0;            \
            }", i++);
            css.insertRule("property:nth-child(odd) { \
                display: table-row;                    \
                background-color: white;               \
            }", i++);
            css.insertRule("name {            \
                display: table-cell;          \
                font-weight: bold;            \
                padding: 3px;                 \
                min-width:20px;               \
                border-right: grey 1px solid; \
            }", i++);
            css.insertRule("mem-value { \
                display: table-cell;       \
                padding: 3px;              \
                min-width: 40px;           \
            }", i++);
    }, 1000);
}

And the XML looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<response>
    <result-code>OK</result-code>
    <loaded-list>
        <property>
            <name>sp.invalid.request.message</name>
            <mem-value>The request is invalid.  Please contact the Service 
Portal administrator.</mem-value>
        </property>
        <property>
            <name>maintenance.thread.sleep.seconds</name>
            <mem-value>30</mem-value>
        </property>
        <property>
            <name>log_level</name>
            <mem-value>ERROR</mem-value>
        </property>
        <property>
            <name>cookie.secure</name>
            <mem-value>false</mem-value>
        </property>
        <property>
            <name>metrics.enable</name>
            <mem-value>true</mem-value>
        </property>
    </loaded-list>
</response>

I THINK it has to do with my FireFox Upgrade, but I'm not sure. Maybe 
someone can show me a "better" way to apply CSS to XML using GreaseMonkey?

The strange thing is: Partly it works as I can see the font change and 
shrink one second after loading the page. 

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to