﻿// ==UserScript==
// @name                Tuenti
// @namespace           http://alejandrofh.es/greasemonkey
// @description         Actualiza cada cierto tiempo la página de inicio de Tuenti
// @include             http://www.tuenti.com/#m=Home&func=index
// @include             http://www.tuenti.com/#m=home&func=view_home
// ==/UserScript==

//------------------------------------------------------------------------------
// Funciones de JavaScript que queremos añadirle a la pagina
script = document.createElement('script');

// Funcion "actualizar"
actualizar = document.createTextNode('var timer;'+
                                    'var parpadea;'+
                                    'function actualizar () {'+
                                        'var direccion = document.location;'+
                                        'if (direccion=="http://www.tuenti.com/#m=Home&func=index"||direccion=="http://www.tuenti.com/#m=home&func=view_home") {'+
                                            'Request.IFRAME.send("?m=Home&func=index&ajax=1&store=1&ajax_target=canvas"); }'+
                                    '}');
script.appendChild(actualizar);

// Funcion "titulo"
titulo = document.createTextNode('function titulo () {'+
                                'if (document.location=="http://www.tuenti.com/#m=Home&func=index"||document.location=="http://www.tuenti.com/#m=home&func=view_home") {'+
                                    'var div = document.getElementById("main_info");'+
                                    'if (div.getElementsByTagName("ul").length){'+
                                            'if (document.title=="Inicio") {'+
                                                'document.title=".";'+
                                            '}'+
                                            'else {'+
                                                ' document.title="Inicio";'+
                                            '}'+
                                    '}'+
                                    'else {'+
                                        'if (document.title!="Inicio"){ document.title=="Inicio"; }'+
                                    '}'+
                                '}'+
                                '}');
script.appendChild(titulo);

// Las añadimos al "head" del documento "html"
head = document.getElementsByTagName('head');
head[0].appendChild(script);
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Comienzo del Script

GM_log('Entrando Actualiza-Tuenti');

// Una vez creado todo, ejecutamos el actualizar  y titulo ciclicamente
script2 = document.createElement('script');
ejecutar = document.createTextNode('timer = setInterval("actualizar()",60000); parpadea=setInterval("titulo()", 1000)');
script2.appendChild(ejecutar);
body = document.getElementsByTagName('body');
body[0].appendChild(script2);

// Final del Script
//------------------------------------------------------------------------------
