Differenze

Queste sono le differenze tra la revisione selezionata e la versione corrente della pagina.

— script_greasemonkey 2009/07/22 15:45 versione corrente
Linea 1: Linea 1:
 +====== Script Greasemonkey per il FdT ======
 +Grazie a [[https://addons.mozilla.org/it/firefox/addon/748|greasemonkey]] è possibile personalizzare il funzionamento del FdT, grazie a javascript è infatti possibile accedere al [[struttura_dei forum|DOM della pagina]] e modificarne gli attributi.
 +  * [[script_greasemonkey#script base]]
 +  * [[script_greasemonkey#repository]]
 +
 +===== Repository =====
 +E' stato creato un [[http://fdt.dev.kom.pl/|Repository per gli script]] e le estensioni del FdT, in particolare si veda l'apposita [[http://fdt.dev.kom.pl/b/|board di sviluppo]].
 +
 +===== Script base =====
 +Dopo la correzione del [[lista_dei_bug|bug //Achille97//]] la redazione di PI ha implementato la visualizzazione dei filmati youtube anche sul FdT, pertanto lo script base è considerato //superato//. Viene qui riportato a fini didattici:
 +
 +<code java>
 + // ==UserScript==
 + // @name          FDT
 + // @namespace      http://forumdeitroll.it
 + // @description    FDT Enhancer (versione 0.5)
 + // @include        http://*.forumdeitroll.it/*
 + // ==/UserScript==
 +
 + // FDT
 + // Copyright (C) 2008 Wakko Warner (http://thewakkowarner.netsons.org/)
 + //
 + // This program is free software: you can redistribute it and/or modify
 + // it under the terms of the GNU General Public License as published by
 + // the Free Software Foundation, either version 3 of the License, or
 + // (at your option) any later version.
 + //
 + // This program is distributed in the hope that it will be useful,
 + // but WITHOUT ANY WARRANTY; without even the implied warranty of
 + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + // GNU General Public License for more details.
 + //
 + // You should have received a copy of the GNU General Public License
 + // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 +
 +
 + //-----------------------------------------------------------------
 + //---------------------------- OPZIONI ----------------------------
 + //-----------------------------------------------------------------
 + var ytTimeout = 1000;
 + var colorTimeout = 500;
 + var colori = true; //Se impostato a false mostrerà la parte quotata in grigetto
 + //-----------------------------------------------------------------
 + //------------------------- FINE OPZIONI --------------------------
 + //-----------------------------------------------------------------
 +
 +
 + var Url = document.URL; //Non usato per ora
 +
 + //Cerchiamo il TD del contenuto
 + var td = document.getElementsByTagName("td");
 + var tr = document.getElementsByTagName("tr");
 + var tdcontent = null;
 + var tdaction = null;
 + var i = 0;
 + for (c=0; c<(td.length); c++) {
 + if ((td[c].className == "content")) {
 + tdcontent = td[c];
 + if (i==1) {
 + break;
 + }
 + i++;
 + }
 + }
 +
 + for (c=0; c<(tr.length); c++) {
 + if ((tr[c].className == "paginazione")) {
 + tdaction = tr[c].firstChild.nextSibling.nextSibling.nextSibling;
 + break;
 + }
 + }
 +
 + if (tdcontent != null) { //Se al passo precedente l'ho trovato...
 + iframe = document.createElement("iframe");
 + iframe.innerHTML = "Non puo' essere che il tuo FF non supporti gli iFrame :/";
 + iframe.src = "";
 + iframe.setAttribute("style","width: 100%; height: 23em; display: none;");
 + iframe.id = "motorino";
 + tdcontent.insertBefore(iframe, tdcontent.firstChild);
 + if (tdaction != null) {
 + tdaction.innerHTML = "<a id=\"showHideMotorino\" class=\"textfolder\" href=\"./\" onclick=\"motorino = document.getElementById('motorino'); showHideMotorino = document.getElementById('showHideMotorino'); if (motorino.getAttribute('style').search('block') < 0) {motorino.setAttribute('style','width: 100%; height: 23em; display: block;'); showHideMotorino.innerHTML = 'Nascondi Motorino'; motorino.src='http://fdt.freehostia.com/carburatore/wakaba/wakaba.html';} else {motorino.setAttribute('style','width: 100%; height: 23em; display: none;'); showHideMotorino.innerHTML = 'Mostra Motorino';}; return false;\">Mostra Motorino</a> | <a href='http://embed.mibbit.com/?server=irc.freenode.org&channel=%23%23fdt' target='_blank' class=\"textfolder\">FDT-Chat</a> | " + tdaction.innerHTML;
 + }
 + }
 +
 + //Gestione Youtube
 + var body = document.getElementsByTagName("body")[0];
 + var ytscript = document.createElement("script");
 + ytscript.innerHTML="function youtube() {\n var body = document.getElementsByTagName(\"body\")[0];\n var div = document.getElementsByTagName(\"div\");\n for(c=0; c<(div.length); c++) {\n if ((div[c].parentNode.nodeName==\"TD\") && (div[c].innerHTML.match(/\\[yt\\]((.){11})\\[\\/yt\\]/g) != null)) {\n div[c].innerHTML = div[c].innerHTML.replace(/\\[yt\\]((.){11})\\[\\/yt\\]/g, '<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/$1\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/$1\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed></object>');\n }\n }\n}\n";
 + body.appendChild(ytscript);
 +
 + setTimeout('youtube()', ytTimeout);
 +
 + //Gestione Colori
 + var colorizescript = document.createElement("script");
 + var colorstring = "";
 + if (colori) {
 + colorstring = " level1 = \"#007BDF\";\n level2 = \"#00AF59\";\n level3 = \"#9A00EF\";\n level4 = \"#AF6F00\";\n";
 + } else {
 + colorstring = " level1 = \"#9F9F9F\";\n level2 = \"#9F9F9F\";\n level3 = \"#9F9F9F\";\n level4 = \"#9F9F9F\";\n";
 + }
 +
 + colorizescript.innerHTML = "function colorize() {\n" + colorstring + " div = document.getElementsByTagName('div');\n for (c=0; c<(div.length); c++) {\n if ((div[c].parentNode.className == \"funcbarthread\")) { myhtml = div[c].innerHTML;\n myhtmlarray = myhtml.split(\"<br>\");\n myhtml = \"\";\n for (z=0; z<(myhtmlarray.length); z++) {\n if (myhtmlarray[z].substring(0,19)==\"&gt; &gt; &gt; &gt;\") {\n myhtmlarray[z] = \"<span style='color: \" + level4 + \";'>\" + myhtmlarray[z] + \"</span>\";\n } else if (myhtmlarray[z].substring(0,14)==\"&gt; &gt; &gt;\") {\n myhtmlarray[z] = \"<span style='color: \" + level3 + \";'>\" + myhtmlarray[z] + \"</span>\";\n } else if (myhtmlarray[z].substring(0,9)==\"&gt; &gt;\") {\n myhtmlarray[z] = \"<span style='color: \" + level2 + \";'>\" + myhtmlarray[z] + \"</span>\";\n } else if (myhtmlarray[z].substring(0,4)==\"&gt;\") {\n myhtmlarray[z] = \"<span style='color: \" + level1 + \";'>\" + myhtmlarray[z] + \"</span>\";\n }\n myhtml = myhtml + myhtmlarray[z] + \"<br>\";\n }\n div[c].innerHTML = myhtml;\n }\n }\n}\n";
 + body.appendChild(colorizescript);
 +
 + setTimeout('colorize()', colorTimeout);
 +</code>
 
Torna su
script_greasemonkey.txt · Ultima modifica: 2009/07/22 15:45 (modifica esterna)
 
 
Looqat Dev Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0