﻿// ==UserScript==
// @name                浏览记录(lp/lp_info.aspx使用)
// @description         news和楼盘的浏览记录
// @created date        2009/11/26   10:24
// @created author      Tiger(tigershi0507@gmail.com)
// @version             1.0.1
// @version owner       Copyright (C) 2009-2010 keerr.com All rights reserved.
// ==/UserScript==
/*************************************************
verified time 	:	2009/11/30   8:30
verified author	:	Tiger
verified purpose:	"LatestReadLP" -> cookieName
**************************************************/
/*************************************************
verified time 	:	2009/11/30   10:46
verified author	:	Tiger
verified purpose:	加入了cookie的options参数，否则是错误的
**************************************************/
/*************************************************
verified time 	:	2009/12/24   11:12
verified author	:	Tiger
verified purpose:	完成了之前一直报错的一个url的问题
**************************************************/
/********************************************************************
verified time 	:	2010/4/14   9:29
verified author	:	Tiger
verified purpose:	修改了一个cookie冗余数据的问题
*********************************************************************/

/// <summary>
/// 浏览记录
/// </summary>
/// <param name="cookieName">分类</param>
/// <param name="titleSel"></param>
/// <param name="listSel"></param>
$.recordLatestReadItem = function(cookieName, titleSel, listSel) {
    var CookieOptions = {   // cookie的统一参数集
        path: '/',
        domain: '',
        expires: 2,
        secure: false
    };
    var title = $.trim($(titleSel).text()),  // 记录显示的标题
        href = document.location.pathname,  // 记录相对应的url
        $_list = $(listSel);    // 呈现dom位置
    var latestRecordJson = $.evalJSON($.cookie(cookieName)),
        thisPageRecordJson = "{\"_title\":\"" + title + "\",\"_r_url\":\"" + href + "\"},";
    if (latestRecordJson === null) {
        $.cookie(cookieName, "[{\"_title\":\"" + title + "\",\"_r_url\":\"" + href + "\"}]", CookieOptions);
        $_list.append("<li>&bull;<a href=\"" + href + "\"> " + title + "</a></li>");
        return true;
    } else {
        var j = 1;
        $_list.html("");
        $_list.append("<li>&bull;<a href=\"" + href + "\"> " + title + "</a></li>");
        for (var i = 0; i < latestRecordJson.length; i++) {
            if (latestRecordJson[i] !== undefined) {

                if (title === latestRecordJson[i]._title && href === latestRecordJson[i]._r_url) {
                    continue;
                }
                else {
                    $_list.append("<li>&bull;<a href=\"" + latestRecordJson[i]._r_url + "\"> " + latestRecordJson[i]._title + "</a></li>");
                }
                thisPageRecordJson = thisPageRecordJson + "{\"_title\":\"" + latestRecordJson[i]._title + "\",\"_r_url\":\"" + latestRecordJson[i]._r_url + "\"}";
                j++;
                if (j < 9) {
                    thisPageRecordJson = thisPageRecordJson + ",";
                }
                else {
                    break;
                }
            }
        }
        thisPageRecordJson = "[" + thisPageRecordJson + "]";
        $.cookie(cookieName, thisPageRecordJson, CookieOptions);
        return true;
    }
}


