0

好的,我已将代码更新为尽可能小,但仍然出现错误……尽管现在问题不太正确……现在应该是“为什么 waitFor 跳出沙箱?” (但我被告知不要更改帖子的问题,如果这是不好的形式,对不起)。如果您安装此扩展程序并按照以下说明进行操作,您将看到 waitFor 被转移到内容脚本沙箱之外。
要查看此错误.....
转到....
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();

清单.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"
}
4

0 回答 0