Chrome扩展程序仅运行一次

时间:2014-07-08 12:55:18

标签: javascript google-chrome google-chrome-extension load phishing

我刚刚开始创建Chrome扩展程序,我想编写一个删除网站Dota-Trade.com上包含网上诱骗链接的邮件。

我得到了一切工作,但是如果按 F5 ,脚本只会删除消息。如果我浏览网站并点击“消息”,则没有任何反应。我怎么能改变这个?

的manifest.json

{
  "name": "Dota-Trade.com Fake Link Blocker",
  "version": "2",
  "manifest_version": 2,
  "description": "Deletes content which contain urls except official ones. By Trojan.",
  "content_scripts": [
    {
        "matches": [
        "http://dota-trade.com/messages"],
        "js": ["main.js"],
        "run_at": "document_end",
        "all_frames": true
    }
  ]
}

我的main.js

function remove(){
  var div = document.getElementById("threads");
  var messages = div.getElementsByClassName("message te clear");

  for (var i=0; i < messages.length; i++) {
    rp = messages[i].getElementsByClassName("rp");

    messagetextobj = rp[0].getElementsByClassName("text");
    var messagetext = messagetextobj[0].textContent;

    if (messagetext.indexOf(".com/profiles") > -1 && messagetext.indexOf("steamcommunity.com") == -1) {
      div.removeChild(messages[i]);
    };
  }

  setTimeout(function(){remove();},500);
}

remove();

0 个答案:

没有答案