// Exemple de script GreaseMonkey sur sebsauvage.net
//
// ==UserScript==
// @name          Exemple de script GreaseMonkey sur sebsauvage.net
// @namespace     http://sebsauvage.net
// @description	  Exemple de script GreaseMonkey sur sebsauvage.net
// @include       http://www.sebsauvage.net/*
// @include       http://sebsauvage.net/*
// ==/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
    {
        // Supprimer un élément précis:
        // On supprime le gros oeil.
        removeElement("//img[@src='images/nbt_gros_oeil.gif']");
        
        // Supprimer le parent d'un élément (éloigné ou non):
        // On supprime le tableau "Ce site est hébergé gracieusement par..."
        removeElement("//img[@alt='Digital Networks']/../../../../..");
        // On remonte la balise image avec ..         A  TD TR TBODY TABLE
        // et c'est le <table> qu'on supprime.
        
        // Supprimer l'attribut d'un élément:
        // On supprimer l'attribut align="center" de la cellule <td>
        // contenant le texte: Dernière mise à jour... (en bas à droite)
        removeAttributeOfElement('align',"//td[contains(.,'Dernière mise à jour :')]")
        
        // Injecter ses propres CSS:
        injectCSS('body{background-color:#eef; color:#f80;')        
    }
    catch (e)
    {
        alert("Exception:\n" + e);
    }

})();

