Source for "www.kicker.de livescores AutoUpdater und eMail-Ticker (ajax)"

By billythegates
Has 6 other scripts.


// Copyright (C) 2008 Manuel F. <mf@find-the-flow.com>
//
// 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 2, 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.

// ==UserScript== 
// @name           www.kicker.de livescores AutoUpdater und eMail-Ticker (ajax)
// @namespace      *
// @version        0.8.7
// @description    Für alle die keine Lust haben ständig auf "aktualisieren" zu drücken...
// @include        *.kicker.de*/live-news/livescores/*
// @releasenotes   http://ticker.e-dias.de/releasenotes.txt
// ==/UserScript==

var VERSION="0.8.7";
var UPDATE_TIME_IN_SECONDS=5;
var DEFAULT_SETTING="on";	//  "on" heißt autoupdater ist standardmäßig eingeschaltet, alles andere bedeutet AUS!
var SHOW_ERG_TYPES=new Array(["Tor","true"],["Gelbe Karte","false"],["Gelb-Rote Karte","true"],["Rote Karte","true"],["Spielerwechsel","false"]);

/* global vars */
var autoUpdater,reloadImg,requestObj,update,serverTime,userEmail;
var serverURL="http://ticker.e-dias.de/";
var tickerObject=document.getElementById("ltcontent");
var msgBase="http://www.kicker.de/";
var msgCSS="css/generic/liveticker_v4-2-9.css";

(function() {
	var scripts = [
		serverURL+'DOMTools.js',
		serverURL+'AutoUpdater.js',
		'http://www.usability-online.com/assets/script/html-xpath.js'
	];
	/* append external scripts to head */
	for (i in scripts) {
	    var script = document.createElement('script');
	    script.src = scripts[i];
	    document.getElementsByTagName('head')[0].appendChild(script);
	}
	var styles = [
		serverURL+'tickerstyles.css'
	];
	/* append external styles to head */
	for (i in styles) {
	    var style = document.createElement('link');
	    style.setAttribute("rel","stylesheet");
	    style.href = styles[i];
	    document.getElementsByTagName('head')[0].appendChild(style);
	}
})(); // end anonymous function wrapper

function initTicker(){
	reloadImg=elem('reloadimg');
	/* create and append Settings */
	serverTime=autoUpdater.startTime;
	window.setInterval(startAutoUpdate, autoUpdater.updateInterval*1000);
}

function setStand(updateElemArr){
	try{
		requestTime();
	}catch (e){};
	if(serverTime){
		for(var i=0;i<updateElemArr.length;i++){
			if(updateElemArr[i].parentNode)
				updateElemArr[i].parentNode.getElementsByTagName("small")[0].innerHTML="         (Stand "+serverTime+")";
		}
	}
}

startAutoUpdate=function(){
	if(elem("updateState").value=="true"){
		autoUpdater.getLiveTickerUpdate();
		if(elem("ltkonf")){
			setStand([elem("ltkonf").getElementsByTagName("div")[0],elem("lttxtt").getElementsByTagName("div")[0]]);
		}else{
			setStand([elem("lttxtt").getElementsByTagName("div")[0]]);
		}
		if(autoUpdater.recentUpdate){
			if(autoUpdater.alertMessage[0]){
				var message=autoUpdater.alertMessage[0];
				var title=autoUpdater.alertMessage[1];
				var send=false;
				var check=false;
				var topaktuell=elem("lttopa").innerHTML?true:false;
				check=topaktuell?title.contains(autoUpdater.showErgTypes[0][0]):message.contains("ergtyp_1.");
				send=(check&&autoUpdater.showErgTypes[0][1]=="true")?true:send;
				title=check?autoUpdater.showErgTypes[0][0]+"! "+title:title;
				if(!check){	// es kann nur einen Typ geben ;)
					check=topaktuell?title.contains(autoUpdater.showErgTypes[1][0]):message.contains("ergtyp_2.");
					send=(check&&autoUpdater.showErgTypes[1][1]=="true")?true:send;
					title=check?autoUpdater.showErgTypes[1][0]+". "+title:title;
				}
				if(!check){ // Gelb-Rot schließt Rot aus!
					check=topaktuell?title.contains(autoUpdater.showErgTypes[2][0]):message.contains("ergtyp_3.");
					send=(check&&autoUpdater.showErgTypes[2][1]=="true")?true:send;
					title=check?autoUpdater.showErgTypes[2][0]+"! "+title:title;
				}
				if(!check){
					check=topaktuell?title.contains(autoUpdater.showErgTypes[3][0]):message.contains("ergtyp_4.");
					send=(check&&autoUpdater.showErgTypes[3][1]=="true")?true:send;
					title=check?autoUpdater.showErgTypes[3][0]+"! "+title:title;
				}
				if(!check){
					check=topaktuell?title.contains(autoUpdater.showErgTypes[4][0]):message.contains("ergtyp_5.");
					send=(check&&autoUpdater.showErgTypes[4][1]=="true")?true:send;
					title=check?autoUpdater.showErgTypes[4][0]+". "+title:title;
				}
				//alert("send="+send);
				if(send){
					try{
						sendMail(message,escape(title));
					}catch(e){}
				}
			}
			autoUpdater.recentUpdate=false;
		}
	}
}

/**********************************************************************/
/******************************* dom-tools ******************************/

/** get element by ID! */
elem=function(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (window[id]) {
		return window[id];
	}
	return null;
}

String.prototype.contains = function(t) { return this.indexOf(t) >= 0 ? true : false }

/**********************************************************************/
/***************************** ajax-functions ****************************/

/************************** request Server time *************************/
function requestTime() {
	GM_xmlhttpRequest({
		method: 'GET',
		url: serverURL+'getTime.php',
		headers: {
			'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
			'Accept': 'application/atom+xml,application/xml,text/xml',
		},
		onload: function(responseDetails) {
			serverTime=responseDetails.responseText;
		}
	});
}
/****************************** send eMail ******************************/
function sendMail(msg,title) {
	GM_xmlhttpRequest({
		method: 'POST',
		url: serverURL+'sendmail.php',
		headers: {
			'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
			'Content-Type':'application/x-www-form-urlencoded',
			'Accept': 'application/atom+xml,application/xml,text/xml'
		},
		data:'email='+elem('userEmailField').value+'&title='+title+'&css='+msgCSS+'&text='+msg+'&base='+msgBase,
		onload: function(responseDetails) {
			autoUpdater.alertMessage[0]="";
			autoUpdater.alertMessage[1]="";
			//alert(responseDetails.responseText);
		}
	});
}

window.addEventListener('load', function(event) {
	if(elem("livet")){
		// Grab a reference to the AutoUpdater object which was loaded by the AutoUpdater library earlier.
		AutoUpdater = unsafeWindow['AutoUpdater'];
		var loc=window.location.toString();
		var firstChar=loc.lastIndexOf("object/")+7;
		var tickerID=loc.substr(firstChar,6);
		var tickerType=loc.indexOf("livematch")==-1?2:1;
		autoUpdater=new AutoUpdater(tickerID,tickerType,UPDATE_TIME_IN_SECONDS,DEFAULT_SETTING,SHOW_ERG_TYPES);
		unsafeWindow.autoUpdater=autoUpdater;
		elem("autoUpdaterElement").setAttribute("version",VERSION);
		initTicker();
	}
}, 'false');
window.addEventListener('unload', function(event) {
	if(elem("livet")){
		unsafeWindow.autoUpdater=null;
	}
}, 'false');