


javascript SocialHistory Check whether the visitor has visited a certain site_javascript skills
window.onload = function() { var sl = new SocialHistory(); alert(sl.doesVisit("www.jb51.net")); } If the user has ever used www.jb51.net, then this function will return true, otherwise it will return false. In fact, the principle is not complicated. It uses the attributes of the link's a:visited pseudo-class. First generate an iframe on the page, and set a and a:visited to different styles in this iframe. Then insert the link to the website into the iframe. The browser will set the a:visited style for the visited links based on the user's access history. Finally, the final style of the link is obtained. If it is a:visited, it can be considered that the user has visited the website. For specific implementation methods, please refer to the source code. This script is mainly used to display social bookmark icons, which can properly display the website used by the user. But I am worried that this approach is suspected of stealing user privacy? Although this method can only determine whether the user has visited a specific website, it cannot obtain all access history without limit. /* |
* Social Limit - Only the social you care about. |
* |
* Enables your site to know which social bookmarking badges to display to your |
* visitors. It tells you all social sites the user has gone to, or you can |
* query for a specific one. |
* |
* For example: |
* |
* var sl = SocialHistory(); |
* alert( sl.doesVisit("Digg") ); // Returns true/false, -1 if unknown. |
* var listOfVisitedSites = sl.visitedSites(); |
* var checkedSites = sl.checkedSites(); |
* |
* If you want to add more sites to check, you can pass that in as a dictionary |
* to History: |
* |
* var more = { "Humanized": "http://humanized.com", |
* "Azarask.in": ["http://azarask.in", "http://azarask.in/blog"] |
* }; |
* var sl = SocialHistory(more); |
* alert( sl.doesVisit("Humanized") ); |
* |
* For a list of built-in sites, see the sites variable below. |
* |
* Copyright (c) 2008 Aza Raskin (http://azarask.in/blog) |
* |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
* of this software and associated documentation files (the "Software"), to deal |
* in the Software without restriction, including without limitation the rights |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
* copies of the Software, and to permit persons to whom the Software is |
* furnished to do so, subject to the following conditions: |
* |
* The above copyright notice and this permission notice shall be included in |
* all copies or substantial portions of the Software. |
* |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
* THE SOFTWARE. |
* |
*/ |
var SocialHistory = function( moreSites ){ |
var sites = { |
"Digg": ["http://digg.com", "http://digg.com/login"], |
"Reddit": ["http://reddit.com", "http://reddit.com/new/", "http://reddit.com/controversial/", "http://reddit.com/top/", "http://reddit.com/r/reddit.com/", "http://reddit.com/r/programming/"], |
"StumbleUpon": ["http://stumbleupon.com"], |
"Yahoo Buzz": ["http://buzz.yahoo.com"], |
"Facebook": ["http://facebook.com/home.php", "http://facebook.com", "https://login.facebook.com/login.php"], |
"Del.icio.us": ["https://secure.del.icio.us/login", "http://del.icio.us/"], |
"MySpace": ["http://www.myspace.com/"], |
"Technorati": ["http://www.technorati.com"], |
"Newsvine": ["https://www.newsvine.com", "https://www.newsvine.com/_tools/user/login"], |
"Songza": ["http://songza.com"], |
"Slashdot": ["http://slashdot.org/"], |
"Ma.gnolia": ["http://ma.gnolia.com/"], |
"Blinklist": ["http://www.blinklist.com"], |
"Furl": ["http://furl.net", "http://furl.net/members/login"], |
"Mister Wong": ["http://www.mister-wong.com"], |
"Current": ["http://current.com", "http://current.com/login.html"], |
"Menaeme": ["http://meneame.net", "http://meneame.net/login.php"], |
"Oknotizie": ["http://oknotizie.alice.it", "http://oknotizie.alice.it/login.html.php"], |
"Diigo": ["http://www.diigo.com/", "https://secure.diigo.com/sign-in"], |
"Funp": ["http://funp.com", "http://funp.com/account/loginpage.php"], |
"Blogmarks": ["http://blogmarks.net"], |
"Yahoo Bookmarks": ["http://bookmarks.yahoo.com"], |
"Xanga": ["http://xanga.com"], |
"Blogger": ["http://blogger.com"], |
"Last.fm": ["http://www.last.fm/", "https://www.last.fm/login/"], |
"N4G": ["http://www.n4g.com"], |
"Faves": ["http://faves.com", "http://faves.com/home", "https://secure.faves.com/signIn"], |
"Simpy": ["http://www.simpy.com", "http://www.simpy.com/login"], |
"Yigg": ["http://www.yigg.de"], |
"Kirtsy": ["http://www.kirtsy.com", "http://www.kirtsy.com/login.php"], |
"Fark": ["http://www.fark.com", "http://cgi.fark.com/cgi/fark/users.pl?self=1"], |
"Mixx": ["https://www.mixx.com/login/dual", "http://www.mixx.com"], |
"Google Bookmarks": ["http://www.google.com/bookmarks", "http://www.google.com/ig/add?moduleurl=bookmarks.xml&hl=en"], |
"Subbmitt": ["http://subbmitt.com/"] |
}; |
for( var site in moreSites ) { |
// If we don't have the site, create the URL list. |
if( typeof( sites[site] ) == "undefined" ) sites[site] = []; |
// If the value is string, just push that onto the URL list. |
if( typeof( moreSites[site] ) == "string" ) |
sites[site].push( moreSites[site] ); |
else |
sites[site] = sites[site].concat( moreSites[site] ); |
} |
var visited = {}; |
function getStyle(el, scopeDoc,styleProp) { |
if (el.currentStyle) |
var y = el.currentStyle[styleProp]; |
else if (window.getComputedStyle) |
var y = scopeDoc.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp); |
return y; |
} |
function remove( el ) { |
el.parentNode.removeChild( el ); |
} |
// Code inspired by: |
// bindzus.wordpress.com/2007/12/24/adding-dynamic-contents-to-iframes |
function createIframe() { |
var iframe = document.createElement("iframe"); |
iframe.style.position = "absolute"; |
iframe.style.visibility = "hidden"; |
document.body.appendChild(iframe); |
// Firefox, Opera |
if(iframe.contentDocument) iframe.doc = iframe.contentDocument; |
// Internet Explorer |
else if(iframe.contentWindow) iframe.doc = iframe.contentWindow.document; |
// Magic: Force creation of the body (which is null by default in IE). |
// Also force the styles of visited/not-visted links. |
iframe.doc.open(); |
iframe.doc.write('); |
iframe.doc.write("a{color: #000000; display:none;}"); |
iframe.doc.write("a:visited {color: #FF0000; display:inline;}"); |
iframe.doc.write(''); |
iframe.doc.close(); |
// Return the iframe: iframe.doc contains the iframe. |
return iframe; |
} |
var iframe = createIframe(); |
function embedLinkInIframe( href, text ) { |
var a = iframe.doc.createElement("a"); |
a.href = href; |
a.innerHTML = site; |
iframe.doc.body.appendChild( a ); |
} |
for( var site in sites ) { |
var urls = sites[site]; |
for( var i=0; iurls.length; i ) { |
// You have to create elements in the scope of the iframe for IE. |
embedLinkInIframe( urls[i], site ); |
// Automatically try variations of the URLS with and without the "www" |
if( urls[i].match(/www./) ){ |
var sansWWW = urls[i].replace(/www./, ""); |
embedLinkInIframe( sansWWW, site ); |
} else { |
// 2 = 1 for length of string 1 for slice offset |
var httpLen = urls[i].indexOf("//") 2; |
var withWWW = urls[i].substring(0, httpLen ) "www." urls[i].substring( httpLen ); |
embedLinkInIframe( withWWW, site ); |
} |
} |
} |
var links = iframe.doc.body.childNodes; |
for( var i=0; ilinks.length; i ) { |
// Handle both Firefox/Safari, and IE (respectively) |
var displayValue = getStyle(links[i], iframe.doc, "display"); |
var didVisit = displayValue != "none"; |
if( didVisit ){ |
visited[ links[i].innerHTML ] = true; |
} |
} |
remove( iframe ); |
return new (function(){ |
var usedSites = []; |
for( var site in visited ){ |
usedSites.push( site ); |
} |
// Return an array of visited sites. |
this.visitedSites = function() { |
return usedSites; |
} |
// Return true/false. If we didn't check the site, return -1. |
this.doesVisit = function( site ) { |
if( typeof( sites[site] ) == "undefined" ) |
return -1; |
return typeof( visited[site] ) != "undefined"; |
} |
var checkedSites = []; |
for( var site in sites ){ |
checkedSites.push( site ); |
} |
// Return a list of the sites checked. |
this.checkedSites = function(){ |
return checkedSites; |
} |
})(); |
} |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

JavaScript is a programming language widely used in web development, while WebSocket is a network protocol used for real-time communication. Combining the powerful functions of the two, we can create an efficient real-time image processing system. This article will introduce how to implement this system using JavaScript and WebSocket, and provide specific code examples. First, we need to clarify the requirements and goals of the real-time image processing system. Suppose we have a camera device that can collect real-time image data
