确定我已经将代码更新为尽可能小但仍然得到错误...虽然现在问题不是很正确......现在应该是“为什么waitFor跳出沙箱?” (但我被告知不要为帖子更改问题,如果这是不好的表格,请对不起)。如果您安装此扩展程序并按照以下说明操作,则会看到waitFor get转移到内容脚本沙箱的外面
要看到这个错误.....
转到....
https://www.facebook.com/groups/382415791793391/
..等待页面完全加载。
然后单击“Testy Testy”选项卡以使页面刷新
看看控制台,你会看到“你不应该看到这个”
我的控制台输出看起来像这样....
chekcpage
waitFor
(19)waitFor
pop
attach contentNodeRemoved
chekcpage
waitFor
removing
added
attach contentNodeRemoved
chekcpage
waitFor
(156+)You shouldnt be able to see this
myscript.js
script = function(old) {
window.variableInUnsafeWindow = "You shouldnt be able to see this";
}
function exec(fn) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = '(' + fn + ')();';
document.documentElement.appendChild(script); // run the script
document.documentElement.removeChild(script); // clean up
}
exec(script);
window.onpopstate = function(event) {
console.debug('pop');
checkPage();
};
function waitFor(query, delay) {
if (typeof(variableInUnsafeWindow) == "undefined") {
console.debug('waitFor');
found = document.documentElement.querySelector(query);
if (!found) {
window.setTimeout("(" + waitFor + ")('" + query + "'," + delay + ");", delay);
}
} else {
console.debug(variableInUnsafeWindow);
window.setTimeout("(" + waitFor + ")('" + query + "'," + delay + ");", delay);
}
}
function contentNodeRemoved() {
console.debug('removing');
document.querySelector('div#contentCol').removeEventListener('DOMNodeRemoved', contentNodeRemoved, false);
document.querySelector('div#contentCol').addEventListener('DOMNodeInserted', contentNodeAdded, false);
}
function contentNodeAdded() {
console.debug('added');
document.querySelector('div#contentCol').removeEventListener('DOMNodeInserted', contentNodeAdded, false);
checkPage();
}
function checkPage() {
if (document.querySelector('div#contentCol')) {
console.debug('attach contentNodeRemoved');
var node = document.querySelector('div#contentCol');
node.addEventListener('DOMNodeRemoved', contentNodeRemoved, false);
}
console.debug('chekcpage');
waitFor('ul#group_mall_382415791793391', 300);
}
checkPage();
manifest.json
{
"name": "Facebook - Group member ban icon",
"description": "Puts an X after a users name on the groups page for banning. Unfortunately the X show on groups your not an Admin of still.",
"content_scripts": [{
"matches": ["*://*.facebook.com/*"],
"js": ["myscript.js"],
"run_at": "document_start"
}],
"permissions": ["tabs"],
"icons": {
"16": "icon.png",
"48": "icon48.png",
"128": "icon128.png"
},
"version": "1.0"
}