MediaWiki:EmailObfuscate.js: Unterschied zwischen den Versionen

Aus Freifunk MWU Wiki
Zur Navigation springen Zur Suche springen
K
K (To hell with it! Fix links)
 
(8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 
/* Ich verschleiere Email-Adressen zum Spamschutz */
 
/* Ich verschleiere Email-Adressen zum Spamschutz */
  
var user = document.getElementById('emailuser');
+
var sets = document.getElementsByClassName('emailobfuscate');
var host = document.getElementById('emailhost');
 
var suffix = document.getElementById('emailsuffix');  
 
  
var email = document.getElementById('emailobfuscated');
+
if(typeof(sets) != 'undefined' && sets !== null)
 +
{
 +
    var i = 0, set;
 +
    while (set = sets[i++])
 +
    {
 +
        var email = document.getElementById('nospam'+i);
  
email.innerHTML = '<a href="mailto:' + user + '@' + host + '.' + suffix + '">' + user + '@' + host + '.' + suffix + '</a>';
+
        if(typeof(email) != 'undefined' && email !== null)
 +
        {
 +
            var user = document.getElementById('emailuser'+i);
 +
            var host = document.getElementById('emailhost'+i);
 +
            var suffix = document.getElementById('emailsuffix'+i);
 +
            var text = document.getElementById('emailtext'+i);
 +
            var subject = document.getElementById('emailsubject'+i);
 +
            var body = document.getElementById('emailbody'+i);
 +
 
 +
            if(typeof(user) != 'undefined' && user !== null && typeof(host) != 'undefined' && host !== null && typeof(suffix) != 'undefined' && suffix !== null)
 +
            {
 +
                var addr = user.innerHTML.replace(/^\s+|\s+$/g,'') + '@' + host.innerHTML.replace(/^\s+|\s+$/g,'') + '.' + suffix.innerHTML.replace(/^\s+|\s+$/g,'');
 +
 
 +
                var link = addr;
 +
                if(typeof(text) != 'undefined' && text !== null)
 +
                {
 +
                    link = text.innerHTML.replace(/^\s+|\s+$/g,'');
 +
                }
 +
 
 +
                if((typeof(subject) != 'undefined' && subject !== null) || (typeof(body) != 'undefined' && body !== null))
 +
                {
 +
                    if((subject !== null) && (body !== null))
 +
                    {
 +
                        addr += '?&amp;subject=' + encodeURIComponent(subject.innerHTML.replace(/^\s+|\s+$/g,'')) + '&amp;body=' + encodeURIComponent(body.innerHTML.replace(/^\s+|\s+$/g,''));
 +
                    }
 +
                    else if(subject !== null)
 +
                    {
 +
                        addr += '?&amp;subject=' + encodeURIComponent(subject.innerHTML.replace(/^\s+|\s+$/g,''));
 +
                    }
 +
                    else if(body !== null)
 +
                    {
 +
                        addr += '?&amp;body=' + encodeURIComponent(body.innerHTML.replace(/^\s+|\s+$/g,''));
 +
                    }
 +
                }
 +
                email.innerHTML = '<a href="mailto:' + addr + '">' + link + '</a>';
 +
            }
 +
        }
 +
    }
 +
}

Aktuelle Version vom 2. September 2014, 11:26 Uhr

/* Ich verschleiere Email-Adressen zum Spamschutz */

var sets = document.getElementsByClassName('emailobfuscate');

if(typeof(sets) != 'undefined' && sets !== null)
{
    var i = 0, set;
    while (set = sets[i++])
    {
        var email = document.getElementById('nospam'+i);

        if(typeof(email) != 'undefined' && email !== null)
        {
            var user = document.getElementById('emailuser'+i);
            var host = document.getElementById('emailhost'+i);
            var suffix = document.getElementById('emailsuffix'+i);
            var text = document.getElementById('emailtext'+i);
            var subject = document.getElementById('emailsubject'+i);
            var body = document.getElementById('emailbody'+i);

            if(typeof(user) != 'undefined' && user !== null && typeof(host) != 'undefined' && host !== null && typeof(suffix) != 'undefined' && suffix !== null)
            {
                var addr = user.innerHTML.replace(/^\s+|\s+$/g,'') + '@' + host.innerHTML.replace(/^\s+|\s+$/g,'') + '.' + suffix.innerHTML.replace(/^\s+|\s+$/g,'');

                var link = addr;
                if(typeof(text) != 'undefined' && text !== null)
                {
                    link = text.innerHTML.replace(/^\s+|\s+$/g,'');
                }

                if((typeof(subject) != 'undefined' && subject !== null) || (typeof(body) != 'undefined' && body !== null))
                {
                    if((subject !== null) && (body !== null))
                    {
                        addr += '?&amp;subject=' + encodeURIComponent(subject.innerHTML.replace(/^\s+|\s+$/g,'')) + '&amp;body=' + encodeURIComponent(body.innerHTML.replace(/^\s+|\s+$/g,''));
                    }
                    else if(subject !== null)
                    {
                        addr += '?&amp;subject=' + encodeURIComponent(subject.innerHTML.replace(/^\s+|\s+$/g,''));
                    }
                    else if(body !== null)
                    {
                        addr += '?&amp;body=' + encodeURIComponent(body.innerHTML.replace(/^\s+|\s+$/g,''));
                    }
                }
                email.innerHTML = '<a href="mailto:' + addr + '">' + link + '</a>';
            }
        }
    }
}