greasemonkey
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
greasemonkey [2013/05/14 18:42] – créée sebsauvage | greasemonkey [2014/07/12 12:26] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== GreaseMonkey ====== | ====== GreaseMonkey ====== | ||
+ | |||
+ | Cette page (succincte) s' | ||
+ | |||
===== C'est quoi ? ===== | ===== C'est quoi ? ===== | ||
- | GreaseMonkey est une extension Firefox qui permet de modifier à la volée n' | + | [[https:// |
===== Comment ça marche ? ===== | ===== Comment ça marche ? ===== | ||
- | Installez d' | + | Installez d' |
:!: **ATTENTION**: | :!: **ATTENTION**: | ||
Ligne 15: | Ligne 18: | ||
C'est le but de cette page. | C'est le but de cette page. | ||
- | Généralement, | + | Généralement, |
+ | |||
+ | L' | ||
+ | * **@name** : Nom du script. | ||
+ | * **@namespace** : Namespace de votre script (mettez l'URL de votre site, ça fera l' | ||
+ | * **@include** : Indique sur quelles URLs il doit s' | ||
+ | |||
+ | <file javascript monscript.js>// | ||
+ | // @name Essai | ||
+ | // @namespace | ||
+ | // @include | ||
+ | // ==/ | ||
+ | |||
+ | |||
+ | (function () { | ||
+ | // Removes all occurences of elements whose XPath is provided from the document. | ||
+ | // | ||
+ | // Example: Remove all tables which use the CSS class ' | ||
+ | // removeElement("// | ||
+ | function removeElement(ElementXpath) | ||
+ | { | ||
+ | var alltags = document.evaluate(ElementXpath, | ||
+ | for (i=0; i< | ||
+ | { | ||
+ | element = alltags.snapshotItem(i); | ||
+ | element.parentNode.removeChild(element); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // 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 < | ||
+ | // removeAttributeOfElement(' | ||
+ | // Remove the fixed with of all tables or cells:: | ||
+ | // removeAttributeOfElement(' | ||
+ | function removeAttributeOfElement(attributeName, | ||
+ | { | ||
+ | var alltags = document.evaluate(ElementXpath, | ||
+ | for (i=0; 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(' | ||
+ | function setAttributeOfElement(attributeName, | ||
+ | { | ||
+ | var alltags = document.evaluate(ElementXpath, | ||
+ | for (i=0; i< | ||
+ | alltags.snapshotItem(i).setAttribute(attributeName, | ||
+ | } | ||
+ | |||
+ | // Inject your own CSS in the page. | ||
+ | // Example: Do not underline link: | ||
+ | // injectCSS(" | ||
+ | function injectCSS(cssdata) | ||
+ | { | ||
+ | head = document.getElementsByTagName(" | ||
+ | style = document.createElement(" | ||
+ | style.setAttribute(" | ||
+ | style.innerHTML = cssdata; | ||
+ | head.appendChild(style); | ||
+ | } | ||
+ | |||
+ | // Converts an image to text. | ||
+ | // Attributes, links and javascript actions are preserved. | ||
+ | // | ||
+ | // Examples: imageToText("// | ||
+ | // | ||
+ | function imageToText(ElementXpath, | ||
+ | { | ||
+ | var alltags = document.evaluate(ElementXpath, | ||
+ | for (i=0; i< | ||
+ | { | ||
+ | tag = alltags.snapshotItem(i) | ||
+ | lien = document.createTextNode(text) | ||
+ | tag.parentNode.replaceChild(lien, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | try | ||
+ | { | ||
+ | // Mettez votre code ici. EXEMPLES: | ||
+ | |||
+ | // Supprimer des actions Javascript sur certains éléments d'un formulaire. | ||
+ | removeAttributeOfElement(' | ||
+ | removeAttributeOfElement(' | ||
+ | |||
+ | // Supprimer toutes les couleurs de fond: | ||
+ | injectCSS(' | ||
+ | |||
+ | // supprimer les couleurs des tableaux: | ||
+ | removeAttributeOfElement(' | ||
+ | removeAttributeOfElement(' | ||
+ | |||
+ | // forcer la largeur d'un textarea: | ||
+ | setAttributeOfElement(' | ||
+ | |||
+ | // Convertir une image en texte: | ||
+ | imageToText("// | ||
+ | |||
+ | // et divers autres exemples en vrac, histoire de montrer quelques possibilité de XPath: | ||
+ | removeElement("// | ||
+ | removeElement("// | ||
+ | setAttributeOfElement(' | ||
+ | setAttributeOfElement(' | ||
+ | removeElement("// | ||
+ | removeElement("// | ||
+ | } | ||
+ | catch (e) | ||
+ | { | ||
+ | alert(" | ||
+ | } | ||
+ | |||
+ | })(); | ||
+ | </ | ||
+ | |||
+ | Pour trouver quels éléments atteindre, utilisez l' | ||
+ | |||
+ | A titre d' | ||
+ | |||
+ | <code javascript>// | ||
+ | // @name Essai | ||
+ | // @namespace | ||
+ | // @include | ||
+ | // ==/ | ||
+ | |||
+ | (function () { | ||
+ | ...code supprimé... | ||
+ | try | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | catch (e) | ||
+ | { | ||
+ | alert(" | ||
+ | } | ||
+ | })();</ | ||
+ | |||
+ | ou encore forcer tous les liens en bleu: | ||
+ | |||
+ | <code javascript> | ||
+ | |||
+ | À vous de jouer ! | ||
+ | |||
+ | ===== Autres exemples ===== | ||
+ | |||
+ | ==== Redirection de page dans Tumblr ==== | ||
+ | |||
+ | Si vous êtes sur une page tumblr du genre: < | ||
+ | |||
+ | <code javascript> | ||
+ | // ==UserScript== | ||
+ | // @name Tumblr image redirector (/image --> direct image URL) | ||
+ | // @namespace | ||
+ | // @include | ||
+ | // @version | ||
+ | // ==/ | ||
+ | |||
+ | try { | ||
+ | var alltags = document.evaluate("// | ||
+ | if (alltags.snapshotItem(0) != null) | ||
+ | { | ||
+ | document.location=alltags.snapshotItem(0).src; | ||
+ | } | ||
+ | } | ||
+ | catch (e) | ||
+ | { | ||
+ | alert(" | ||
+ | } | ||
+ | </ | ||
+ | |||
greasemonkey.1368553353.txt.gz · Dernière modification : 2014/07/12 12:26 (modification externe)