can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r18955: LJSUP-8676: Create cookie ljuniq if ther...

Committer: dpetrov
LJSUP-8676: Create cookie ljuniq if there is no one.
U   trunk/htdocs/js/livejournal.js
Modified: trunk/htdocs/js/livejournal.js
===================================================================
--- trunk/htdocs/js/livejournal.js	2011-04-22 07:29:02 UTC (rev 18954)
+++ trunk/htdocs/js/livejournal.js	2011-04-22 08:31:05 UTC (rev 18955)
@@ -36,6 +36,9 @@
     // set up various handlers for every page
     LiveJournal.initInboxUpdate();
 
+	//check ljuniq cookie and create if needed
+	LiveJournal.checkLjUniq();
+
     // run other hooks
     LiveJournal.run_hook("page_load");
 };
@@ -205,6 +208,33 @@
 	return queryStr + queryArr.join( '&' );
 }
 
+/**
+ * Generate a string for ljuniq cookie
+ *
+ * @return {String}
+ */
+LiveJournal.generateLjUniq = function() {
+	var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
+		result = '',
+		i;
+
+	var len = 15
+	for( i = 0; i < len; ++i ) {
+		result += alpha.charAt( Math.floor( Math.random() * ( alpha.length - 1 ) ) );
+	}
+
+	result += ':' + Math.floor( (new Date()) / 1000 );
+	result += ':pgstats' + ( ( Math.random() < 0.05 ) ? '1' : '0' );
+
+	return result;
+}
+
+LiveJournal.checkLjUniq = function() {
+	if( !Cookie( 'ljuniq' ) ) {
+		Cookie( 'ljuniq', LiveJournal.generateLjUniq(), { domain: Site.siteroot.replace( /^https?:\/\/www\./, '' ) } );
+	}
+}
+
 LiveJournal.closeSiteMessage = function(node, e, id)
 {
 	jQuery.post(LiveJournal.getAjaxUrl('close_site_message'), {

Tags: can3p, js, livejournal
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments