Krom için çok basit bir uzantı oluşturmaya çalışıyorum ama bir değişkeni popup html'den geçirmem gerekiyor.Chrome uzantısı: popup html'den değişkenleri geçirme
Bildirim::
{
"background": {
"scripts": [ "background.js" ]
},
"browser_action": {
"default_icon": "img/test.png",
"default_popup": "popup.html",
"default_title": "Auto Clicker"
},
"description": "Auto click",
"manifest_version": 2,
"name": "Auto Clicker",
"permissions": [ "activeTab" ],
"version": "0.0.1"
}
background.js
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
switch (request.directive) {
case "popup-click-1":
// execute the content script
chrome.tabs.executeScript(null, { // defaults to the current tab
file: "myscript.js", // script to inject into page and run in sandbox
allFrames: true // This injects script into iframes in the page and doesn't work before 4.0.266.0.
});
sendResponse({}); // sending back empty response to sender
break;
}
}
);
Bu
i şimdiye kadar var kodudur MyScript.jsfunction foo(){
document.getElementById('submit-button').click();
}
setInterval(function(){
foo()}, 20000)
foo();
popup.js
function clickHandler(e) {
chrome.extension.sendMessage({directive: "popup-click-1"}, function(response) {
this.close(); // close the popup when the background finishes processing request
});
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('submit').addEventListener('click', clickHandler);
})
popup.html
<html>
<head>
<title>test</title>
<script src="popup.js"></script>
</head>
<body>
test
<form>
<input id="1" type = "text">
</br>
</form>
<button id='submit'> etst </button>
</body>
</html>
Şimdiye kadar ben (foo çalıştırın) tıkladığınızda gönder ama ton, her 20sec çalışır. Elde etmek istediğim, popup html'ye bir sayı eklemek ve daha sonra setInterval işlevinin zamanını ayarlamak için bu sayıyı myscript.js adresinde kullanmaktır.
Yani burada bir senaryo geçerli:
Ben sayfasını açın i uzatma düğmesine basın. Bir form ile bir popup var. 30000’ü koyduktan sonra özeti vurdum. Bu şekilde, foo() her 30 saniyede çalışır.
1.. 2. Bu durumda arka plan senaryosunun gerekliliğini görmüyorum (aslında şemanızın işe yaradığından şüphe duyuyorum) – wOxxOm
@wOxxOm 1) Kullanıcının popup.html formuna girdiği değişkeni almak ve sayıyı değiştirmek istiyorum. Bu sayı ile 20000, myscript.js 2) Kod mükemmel çalışıyor, çok defa denedim. Popup.html'deki gönder düğmesine bastığınızda, # submit-düğmesi her 20 saniyede bir tıklanır. –