Created
May 29, 2009 05:55
-
-
Save gleuch/119804 to your computer and use it in GitHub Desktop.
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
// Sniff out visited links by a user with jQuery | |
// by Greg Leuch <http://www.gleuch.com> | |
// based on an initial idea from Jonathan Snook <http://snook.ca> | |
// idea: <http://twitter.com/snookca/status/1121377463> | |
// Note: Only works if user has browser history enabled (save history for x >0 days) | |
// Edit: looks like my code mimics same idea that Aza Raskin's SocialHistory.js does, sans iframe and visit color matching. <http://www.azarask.in/blog/post/socialhistoryjs/> | |
(function($) { | |
$.sniffVisited = function() { | |
if (!$.sniffVisited.init) { | |
$.sniffVisited.domain = window.location.href.replace(/^([a-z]*)(:\/\/)([a-z0-9\-\_\.\:\@]*)(.*)$/i, '$1$2$3'); | |
if ($('style#style_'+ $.sniffVisited.id).size() < 1) $('body').append('<style id="style_'+ $.sniffVisited.id +'" type="text/css">#links_'+ $.sniffVisited.id +' {display: none;} body a:visited {counter-increment: '+ $.sniffVisited.match +';}</style>'); | |
if ($('div#links_'+ $.sniffVisited.id).size() < 1) $('body').append('<div id="links_'+ $.sniffVisited.id +'"></div>'); | |
jQuery($.sniffVisited.against).each($.sniffVisited.test); | |
} | |
$('a').filter($.sniffVisited.filter).each($.sniffVisited.add); | |
// Sniff internal links... | |
if ($.sniffVisited.history.local.length > 0) alert("Internal pages:\n\n"+ jQuery.unique($.sniffVisited.history.local).join("\n")); | |
// Sniff external links... | |
if ($.sniffVisited.history.external.length > 0) alert("External pages:\n\n"+ jQuery.unique($.sniffVisited.history.external).join("\n")); | |
} | |
$.extend($.sniffVisited, { | |
init : false, | |
domain : false, | |
id : 'jquery_sniffVisited', | |
match : 'visited', | |
against : ['facebook.com', 'twitter.com', 'youtube.com', 'vimeo.com', 'tumblr.com'], | |
history : {local : [], external : []}, | |
test : function(i) {$('#links_'+ $.sniffVisited.id).append('<a href="http://www.'+ this +'/" /><a href="http://'+ this +'/" /><a href="https://www.'+ this +'/" /><a href="https://'+ this +'/" />');}, | |
add : function() {(this.href.indexOf($.sniffVisited.domain) >= 0 ? $.sniffVisited.history.local : $.sniffVisited.history.external).push(this.href);}, | |
filter : function() {return /visited/i.test($(this).css('counter-increment'));} | |
}); | |
})(jQuery); | |
// Call sniffer | |
$(document).ready(function() {$.sniffVisited();}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment