Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does GitHub append a js to my jekyll site

I noticed that GitHub appends a js that seems to remove links to email addresses when they have the string /cdn-cgi/l/email-protection with them. Any one else having this strange issue or is this even really from GitHub?

Here is the prettified version of this script:

(function() {
    try {
        var s, a, i, j, r, c, l = document.getElementsByTagName("a"),
            t = document.createElement("textarea");
        for (i = 0; l.length - i; i++) {
            try {
                a = l[i].getAttribute("href");
                if (a && a.indexOf("/cdn-cgi/l/email-protection") > -1 && (a.length > 28)) {
                    s = '';
                    j = 27 + 1 + a.indexOf("/cdn-cgi/l/email-protection");
                    if (a.length > j) {
                        r = parseInt(a.substr(j, 2), 16);
                        for (j += 2; a.length > j && a.substr(j, 1) != 'X'; j += 2) {
                            c = parseInt(a.substr(j, 2), 16) ^ r;
                            s += String.fromCharCode(c);
                        }
                        j += 1;
                        s += a.substr(j, a.length - j);
                    }

                    t.innerHTML = s.replace(/</g, "&lt;").replace(/>/g, "&gt;");
                    l[i].setAttribute("href", "mailto:" + t.value);
                }
            } catch (e) {}
        }
    } catch (e) {}
})();

When I have a link like <a href="mailto:/cdn-cgi/l/email-protection/[email protected]">Contact</a> it becomes <a href="mailto:">Contact</a>. Otherwise, it does not do anything. Still, this bothers me because I did not put that script there yet there it is and I didn't seem to get any warning about GH appending scripts.

like image 249
Czar Pino Avatar asked May 18 '15 02:05

Czar Pino


People also ask

Can you use JavaScript with Jekyll?

Optimising assets can significantly improve load times for visitors to your site. When you build a site on CloudCannon, any assets referenced in your HTML/CSS are automatically minified and served from a CDN. JavaScript files are minified using UglifyJS.


1 Answers

I just got a response from GitHub support and it turns out the mysterious script was being added by CloudFlare when Email Address Obfuscation feature is turned on.

Relevant settings are on https://www.cloudflare.com/a/content-protection/<<domain.name>> under ScrapeShield, if anyone has similar troubles.

like image 167
Czar Pino Avatar answered Oct 06 '22 23:10

Czar Pino