0

Amazon リンク ローカライザーを Chrome 拡張機能に変換しています。私が現在扱っているエラーは次のとおりです。

Uncaught ReferenceError: checkAmazonLinks が定義されていません

この JSON を投稿している URL は次のとおりです: https://freegeoip.net/json/?callback=checkAmazonLinks JS ファイルで次のように呼び出しています。

function findLocation() {
if (typeof google != "undefined" && google.loader.ClientLocation != null) {
    var strCountry = google.loader.ClientLocation.address.country_code;
    checkAmazonLinks(strCountry)
    console.log(strCountry)
} else {
    objScript = document.createElement("script");
    objScript.src = "https://freegeoip.net/json/?callback=checkAmazonLinks";
    document.getElementsByTagName("head")[0].appendChild(objScript);
}

これが私のmanifest.jsです:

{
"name"              : "amazon linker",
"version"           : "0.1",
"manifest_version"  : 2,
"description"       : "A simple extension that turns all Amazon links on a page into localized affiliate links",
"permissions"     : [ "http://*/*","https://*/*"],
"browser_action": {
    "default_title": "Amazon Linker"
},
"content_security_policy": "script-src 'self' https://google.com; https://freegeoip.net;  object-src 'self'",

"content_scripts": [{
        "matches": ["<all_urls>"],
        "js": ["amazon-localiser.js"]
    }
],
 "web_accessible_resources": ["amazon-localiser.js","amazon-localiser.php"]
}

freegeoip で json リクエストからコールバックを削除しようとしましたが、次のエラーが表示されます

キャッチされていない SyntaxError: 予期しないトークン:

を呼び出す関数が .js にありcheckAmazonLinks()、これは の後にロードされfindLocation()ます。順序を並べ替えてみましたが、役に立ちませんでした。同じ関数名でコールバックを介して JSON を取得するcheckAmazonLinks()前に、.js で定義するという考え方でした。findLocation()このエラーを回避するにはどうすればよいですか?

4

1 に答える 1