Last active
January 7, 2022 14:06
-
-
Save derpyherp/87d3ca6533856f96bccd3ed986abc14b to your computer and use it in GitHub Desktop.
Show a custom message to social media visitors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<script src="/referer.js"></script> | |
</head> | |
<body> | |
<div id="greeting"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (document.referrer) { | |
var source_domain = (document.referrer.split('/')[2]); | |
var social_media = [ | |
["t.co", "Twitter"], | |
["reddit.com", "reddit"], | |
["facebook.com", "Facebook"], | |
["instagram.com", "Instagram"], | |
["youtube.com", "YouTube"], | |
["pinterest.com", "Pinterest"] | |
]; | |
for (let index = 0; index < social_media.length; ++index) { | |
const element = social_media[index]; | |
//need to use endsWith or t.co will match reddit.com etc | |
if (source_domain.endsWith(element[0])) { | |
pretty_name = element[1]; | |
break; | |
} | |
} | |
} | |
function show_msg() { | |
if (pretty_name) { | |
document.getElementById("greeting").innerHTML = "Welcome, " + pretty_name + " visitor!"; | |
} | |
} | |
window.onload = show_msg; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment