Zey*_*nel 6 javascript google-app-engine google-chrome-extension
这是我之前的问题的后续跟进.
我正在使用Chrome扩展程序http://ting-1.appspot.com/将书签页面保存到Google App Engine后端.看看Chrome网上商店,我看到扩展程序有一个"添加到Chrome"按钮.由于我的扩展程序需要与后端进行通信(因此用户必须拥有gmail帐户才能使用此扩展程序)如何在扩展程序中指明使用用户名(将扩展程序添加到Chrome的人员的gmail地址)来编写用他的用户ID添加谷歌应用引擎的书签?我的理解上有差距,我似乎没有在文档中找到与此问题相关的任何内容.我background.html在下面.谢谢.
background.html
<html>
<script>
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.getSelected(null, function(tab) {
// Send a request to the content script.
chrome.tabs.sendRequest(tab.id, {action: "getDOM"}, function(response) {
var firstParagraph = response.dom;
console.log("background -- before *console.log(response.dom)*")
console.log("this is *console.log(response.dom)*: " + response.dom)
console.log("background -- after *console.log(response.dom)*")
//}); moved to end to get the variable firstParagraph
var formData = new FormData();
formData.append("url", tab.url);
formData.append("title", tab.title);
formData.append("pitch", firstParagraph);
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://ting-1.appspot.com/submithandlertest", true);
xhr.onreadystatechange = function (aEvt) {
if (xhr.readyState == 4) {
if (xhr.status == 200){
console.log("request 200-OK");
chrome.browserAction.setBadgeText ( { text: "done" } );
setTimeout(function () {
chrome.browserAction.setBadgeText( { text: "" } );
}, 2000);
}else{
console.log("connection error");
chrome.browserAction.setBadgeText ( { text: "ERR" } );
}
}
};
xhr.send(formData);
}); //chrome.tabs.sendRequest
});
});
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5389 次 |
| 最近记录: |