我將amazon link localizer轉換爲Chrome擴展。 我目前正在處理的錯誤是:未捕獲的ReferenceError和意外的令牌錯誤
Uncaught ReferenceError: checkAmazonLinks is not defined
被張貼這JSON的網址是: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);
}
這裏是我的清單.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請求回調,但後來我得到一個錯誤說
Uncaught SyntaxError: Unexpected token :
有一個在我的.js函數調用checkAmazonLinks()
,這是findLocation()
加載後,我試圖重新排列順序,但這並沒有幫助。在findLocation()
之前,在.js中定義checkAmazonLinks()
的想法是通過具有相同函數名稱的回調來檢索JSON。我如何克服這個錯誤?
findLocation函數在哪裏運行(背景頁面,內容腳本,彈出窗口)? – gkalpak
它在內容腳本中,amazon-localiser.js –