İçeriği bağlarım.arka plan ile js.js 2 farklı görev yapmak için: yerel HTML'yi enjekte edin ve başka bir web sayfasından veri alın.
Şu anda, createContainer()
sonra başlar fetchweb()
bitti ve neden olduğundan emin değilim (ihtiyacım var createContainer()
önce koşmak için). Her iki işlevi de Söze dönüştürmeye çalıştım ama yine de aynı sonuç
İçerik.js
function createContainer1() {
// call html file container
chrome.runtime.sendMessage({ cmd: "read_cont1" }, function (html) {
$("#container1").html(html);
});
// more code
}
function fetchWeb() {
chrome.runtime.sendMessage(
{ cmd: "send_url", url: window.location.href},
function (response) {
console.log(JSON.stringify(response));
}
);
}
createContainer1()
fetchWeb()
arka plân.js
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.cmd == "read_cont1") {
$.ajax({
url: chrome.extension.getURL("container1.html"),
dataType: "html",
success: sendResponse,
});
return true;
} else if (request.cmd == "send_url") {
sendResponse({ review_url: fetchData(request.url) });
return true;
}
});