未捕获的SyntaxError:意外的输入结束

时间:2014-02-03 18:43:12

标签: javascript jquery html google-chrome-extension

我在google Chrome扩展程序的javascript控制台中出现此错误,我正在制作,我不知道为什么,有人可以帮助我吗? 这是我的脚本:

popup.js

function urlReduce(href){
    href = href.replace(href.substring(href.indexOf(location.pathname), href.length), "");
    href = href.replace("http://", "").replace("www.", "");
    return href;
}

chrome.runtime.onMessage.addListener(function (message) {
    var hosts = ["novamov.com", "videoweed.es", "vidspot.net", "allmyvideos.net", "streamcloud.eu", "magnovideo.com", "played.to", "vk.com", "moevideos.net", "youtube.com", "videomega.tv", "movshare.net"];
    var url = urlReduce(message.url);
    var found = $.inArray(url, hosts) > -1;
    if (found) {
    alert("sending msg");
        chrome.runtime.sendMessage({method:'getInfo'}, function(response){
            var response_array = response.split(",");
            var title = response_array[0];
            var serie = response_array[1];
            var number = response_array[2];
            var url = response_array[3];            
        });


        $("#serie").html(serie);
        $("#url").html(url);
        $("#number").html(number);
        $("#title").html(title);
    }
}

这里是popup.html的负责人

<head>
<script src="jquery.min.js"></script>
<script src="popup.js"></script>
</head>

1 个答案:

答案 0 :(得分:1)

第二个函数有回调但没有正确关闭

function urlReduce(href) {
    href = href.replace(href.substring(href.indexOf(location.pathname), href.length), "");
    href = href.replace("http://", "").replace("www.", "");
    return href;
}

chrome.runtime.onMessage.addListener(function (message) {
    var hosts = ["novamov.com", "videoweed.es", "vidspot.net", "allmyvideos.net", "streamcloud.eu", "magnovideo.com", "played.to", "vk.com", "moevideos.net", "youtube.com", "videomega.tv", "movshare.net"];
    var url = urlReduce(message.url);
    var found = $.inArray(url, hosts) > -1;
    if (found) {
        alert("sending msg");
        chrome.runtime.sendMessage({
            method: 'getInfo'
        }, function (response) {
            var response_array = response.split(",");
            var title = response_array[0];
            var serie = response_array[1];
            var number = response_array[2];
            var url = response_array[3];
        });


        $("#serie").html(serie);
        $("#url").html(url);
        $("#number").html(number);
        $("#title").html(title);
    }
}); // close it properly

浏览器控制台应该告诉你错误的位置,至少我的错误。