When a visitor surfs into the YouPorn homepage, a script running on the website checks to see what other porn sites that person has been to.
It's based on your browser changing the color of links you've already clicked on. A script on the site exploits a Web privacy leak to quickly check and see whether your browser reveals that the links to a host of other porn sites have been assigned the color "purple," meaning you've clicked them before.
How YouPorn Checks What Other Porn Sites You've Visited
This article is shrill and takes a while getting to the point, but the gist is that: A) every site that includes a 'Like' button on it shares a Facebook-issued cookie, so FB is able to associate together your visits to all of those sites, even if you aren't logged in and don't click the button; and B) if you ever do log in to FB, they issue you a new cookie and (the article assert without evidence) retroactively associate the old pseudonymous cookie with the new one, linking all that old history data with your now-logged-in account.