2011-12-16 51 views

回答

4

最好不要爲此使用Greasemonkey。這會很麻煩,可能會在頁面加載後錯過設置好的Cookie,並且只能在您實際瀏覽Google時刪除Google Cookie。

另外,您必須設置腳本的// @include語句來捕獲Google的所有當前和未來域(google.com,accounts.google.com,mail.google.com,google-analytics.com等)。如果Google服務"Secure cookies"那些也不能觸及。

最好使用一個用於聰明地刪除cookies的工具。我建議Selective Cookie Delete
此外,谷歌和其他網站,追蹤你遠比餅乾更糟糕。每週至少運行一次CCleaner是個好主意。


但是,如果你還是想用的Greasemonkey要做到這一點,這裏是將刪除域許多餅乾腳本上運行代碼:

警告: JavaScript和的Greasemonkey不能即使看到頁面上的所有cookie,也不能「保護」(僅限服務器)cookie被刪除。)。

//--- Loop through cookies and delete them. 
var cookieList = document.cookie.split (/;\s*/); 

for (var J = cookieList.length - 1; J >= 0; --J) { 
    var cookieName = cookieList[J].replace (/\s*(\w+)=.+$/, "$1"); 

    eraseCookie (cookieName); 
} 

其中eraseCookie()是:
(請注意,這eraseCookie通過嘗試所有可能的路徑,並最有可能的子域得到更多的cookie)

function eraseCookie (cookieName) { 
    //--- ONE-TIME INITS: 
    //--- Set possible domains. Omits some rare edge cases.?. 
    var domain  = document.domain; 
    var domain2  = document.domain.replace (/^www\./, ""); 
    var domain3  = document.domain.replace (/^(\w+\.)+?(\w+\.\w+)$/, "$2");; 

    //--- Get possible paths for the current page: 
    var pathNodes = location.pathname.split ("/").map (function (pathWord) { 
     return '/' + pathWord; 
    }); 
    var cookPaths = [""].concat (pathNodes.map (function (pathNode) { 
     if (this.pathStr) { 
      this.pathStr += pathNode; 
     } 
     else { 
      this.pathStr = "; path="; 
      return (this.pathStr + pathNode); 
     } 
     return (this.pathStr); 
    })); 

    (eraseCookie = function (cookieName) { 
     //--- For each path, attempt to delete the cookie. 
     cookPaths.forEach (function (pathStr) { 
      //--- To delete a cookie, set its expiration date to a past value. 
      var diagStr  = cookieName + "=" + pathStr + "; expires=Thu, 01-Jan-1970 00:00:01 GMT;"; 
      document.cookie = diagStr; 

      document.cookie = cookieName + "=" + pathStr + "; domain=" + domain + "; expires=Thu, 01-Jan-1970 00:00:01 GMT;"; 
      document.cookie = cookieName + "=" + pathStr + "; domain=" + domain2 + "; expires=Thu, 01-Jan-1970 00:00:01 GMT;"; 
      document.cookie = cookieName + "=" + pathStr + "; domain=" + domain3 + "; expires=Thu, 01-Jan-1970 00:00:01 GMT;"; 
     }); 
    }) (cookieName); 
}