EZ Recorder

// ==UserScript==
// @name    EZ Recorder [ExampleSite]
// @description    簡易記錄已讀主題
// @author    NKid
// @version    2012-06-22
// @run-at document-end
// @include        http://ExampleSite.net*
// ==/UserScript==
GM_addStyle('.GM_recorded  {background-color:#00A9D8  !important;}');
GM_registerMenuCommand('EZ Recorder [ExampleSite] - Clear Records ',clearRecord);
var siteName="ExampleSite";
var titleSelector="h2.entry-title a";

function clearRecord() {
    if (confirm('Do you want to clear the record?'))
    {
        window.localStorage.removeItem(siteName);
        GM_notification('Clear The Record Of This Site.',null);
    }
}
function titleClick(event) {
    //記錄主題id並上色
    event.preventDefault();
    event.target.className="GM_recorded";
    localStorage.setItem(siteName,event.target.href);
    GM_notification('Recorded.',null);
}
//trigger設定事件
function setTitleClickEvent() {
        var titles=document.querySelectorAll(titleSelector);
        for(var i=0;i<titles.length;i++)
            titles[i].addEventListener('click',titleClick,false);
}

function markThisPage() {
        if (localStorage.getItem(siteName) != null)
        {
            var record=localStorage.getItem(siteName);
            var titles=document.querySelectorAll(titleSelector);
            for(var i=0;i<titles.length;i++)
                if (record ==titles[i].href) titles[i].className="GM_recorded";
        }
}
function showRecord() {
    prompt("The record of this site.",localStorage.getItem(siteName));
}
setTitleClickEvent();
markThisPage();