Javascript 注入的代码适用于大多数网页,但不适用于youtube。。。?

Javascript 注入的代码适用于大多数网页,但不适用于youtube。。。?,javascript,google-chrome-extension,Javascript,Google Chrome Extension,我编写了一个简单的扩展,在当前网页上注入实时时钟。它适用于大多数网页,google.com,hulu.com,stackoverflow.com…,但不适用于youtube.com,我不知道为什么 以下是manifest.json: { "name": "Insert Timestamp", "version": "1.0", "manifest_version": 2, "description": "Insert Timestamp", "icons": { "16": "icon16.p

我编写了一个简单的扩展,在当前网页上注入实时时钟。它适用于大多数网页,google.com,hulu.com,stackoverflow.com…,但不适用于youtube.com,我不知道为什么

以下是manifest.json:

{
"name": "Insert Timestamp",
"version": "1.0",
"manifest_version": 2, 
"description": "Insert Timestamp",
"icons": { "16": "icon16.png",
           "48": "icon48.png",
          "128": "icon128.png" },
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",

"permissions": ["tabs", "http://*/*", "https://*/*", "unlimitedStorage"],

"content_scripts" : [{
    "matches" : [ "http://*/*", "https://*/*"],
    "css" : ["show.css"],
    "js" : ["cbd.js", "ccc.js"]
}]
}
cbd.js调用ccc.js中的函数“onload”,以获得实时并在div中显示时间

而show.css也非常简单:

#showme {
    position: fixed;
    z-index: 999999999;
    top: 0;
    left:0;
}
我对网页内容不太熟悉,只是猜测:也许youtube在我的时钟上放了什么东西

-----------------这里添加了java脚本代码------------------ (1) cbd.js

(2) ccc.js

var div=document.createElement(“showme”);
div.id=“showme”;
文件.正文.附件(div);
document.getElementById('showme').style.color='red';
document.getElementById('showme').style.fontSize='32pt';
函数startTime()
{ 
var today=新日期();
var h=today.getHours();
var m=today.getMinutes()
var s=today.getSeconds();
var w=today.getmillizes()%1000;
h=检查时间(h);
m=检查时间(m);
s=检查时间(s);
w=支票(w);
document.getElementById('showme').innerHTML=h+“:“+m+”:“+s+”:“+w;
t=设置超时('startTime()',1);
} 
功能检查时间(i)
{ 

如果(i9)&(i)您检查了页面的控制台是否有任何错误?可能是您在DOM中注入/操作的某个元素
#showme
,当YouTube通过AJAX+
history.pushState()更新页面时,它会被删除/重新加载
。顺便说一句,添加您正在使用的JavaScript代码,并告诉我们预期的行为。嗨,Xan,是的,我做了,错误在google.com等网页上运行之前已经修复。嗨,Marco,是的,“#showme”是我想要注入的元素。上面添加了java代码。我期望在这里可以看到:,我希望在我用chrome打开的任何网页上都能看到红色的实时时钟。为什么需要
onload
包装器?请看,尤其是注意事项。
window.onload = function() { startTime(); }
var div = document.createElement("showme");
div.id = "showme";
document.body.appendChild(div);
  document.getElementById('showme').style.color = 'red';
  document.getElementById('showme').style.fontSize = '32pt';

function startTime() 
{ 
    var today=new Date(); 
    var h=today.getHours(); 
    var m=today.getMinutes() 
    var s=today.getSeconds(); 
    var w=today.getMilliseconds()%1000;

    h=checkTime(h); 
    m=checkTime(m); 
    s=checkTime(s); 
    w=checkMS(w);

    document.getElementById('showme').innerHTML=h+":"+m+":"+s+":"+w;

    t=setTimeout('startTime()',1); 
} 

function checkTime(i) 
{ 
    if (i<10) 
    {i="0" + i;} 
        return i; 
} 

function checkMS(i) 
{ 
    if ((i>9)&&(i<100) )
        {i="0" + i;} 
    else if(i<10)
        {i="00" + i;} 
    else
        {}
    return i; 
}