// CCM-Forums
//
// This is a GreaseMonkey user file.
// It can only be used in the GreaseMonkey extension for Firefox.
// See http://greasemonkey.mozdev.org/ and http://mozilla.org
//
// This script is in public domain.
// Author: Sebastien SAUVAGE, webmaster of http://sebsauvage/net
//
// ==UserScript==
// @name          CCM-Forums
// @namespace     http://sebsauvage.net
// @description	  Modifie les pages du site Comment Ça Marche
// @include       http://www.commentcamarche.net/*
// @include       http://www.commentcamarche.com/*
// @include       http://www.commentcamarche.org/*
// ==/UserScript==


(function () {
    // Removes all occurences of elements whose XPath is provided from the document.
    //
    // Example: Remove all tables which use the CSS class 'toto':
    //          removeElement("//table[@class='toto']");
    function removeElement(ElementXpath)
    {
        var alltags = document.evaluate(ElementXpath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
        for (i=0; i<alltags.snapshotLength; i++)
        {
            element = alltags.snapshotItem(i);
            element.parentNode.removeChild(element);  // Remove this element from its parent.
        }
    }  
    
    // Removes an attribute from all occurences of elements whose XPath is provided.
    // (All occurences of this elements are processed.)
    //
    // Example: Remove the bgcolor of all <table>:
    //          removeAttributeOfElement('bgcolor',"//table[@bgcolor]")
    //          Remove the fixed with of all tables or cells::
    //          removeAttributeOfElement('width',"//table[@width]|//td[@width]")
    function removeAttributeOfElement(attributeName,ElementXpath)
    {
        var alltags = document.evaluate(ElementXpath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
        for (i=0; i<alltags.snapshotLength; i++)
            alltags.snapshotItem(i).removeAttribute(attributeName);    
    }
    
    // Set an attribute from all occurences of elements to a specified value.
    // The previous value of this attribute is discarded.
    // (All occurences of this elements are processed.)
    //
    // Example: Set with to 80 columns on all texteareas:
    //          setAttributeOfElement('cols',80,"//textarea")
    function setAttributeOfElement(attributeName,attributeValue,ElementXpath)
    {
        var alltags = document.evaluate(ElementXpath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
        for (i=0; i<alltags.snapshotLength; i++)
            alltags.snapshotItem(i).setAttribute(attributeName, attributeValue)
    }    
      
    // Inject your own CSS in the page.
    // Example: Do not underline link:
    //          injectCSS("a{text-decoration: none;}")
    function injectCSS(cssdata)
    {
        head = document.getElementsByTagName("head")[0];
        style = document.createElement("style");
        style.setAttribute("type", 'text/css');
        style.innerHTML = cssdata;
        head.appendChild(style);
    }
      
    try
    {
        // Agrandissement de la zone de saisie du message
        setAttributeOfElement('rows','40',"//textarea[@name='message']");
        setAttributeOfElement('cols','120',"//textarea[@name='message']");
        
        // Dans la liste des discussion, on met en gras les discussion qui n'ont reçu aucune réponse.
        setAttributeOfElement('style','font-weight:bold;',"//td[text()='0']/../td[1]/a");    
    }
        
    catch (e)
    {
        alert("UserScript exception:\n" + e);
    }

})();

