Хорошо, я знаю, что этот вопрос уже задавался в Stack, однако, когда я говорю, что прошел через все это - у меня есть. Более 75% ответов здесь даны в jquery, которые я не хочу использовать! Я очень растерялся и мне нужна помощь, спасибо!
Я пытался создать расширение, которое нажимает кнопку на сайте, когда кнопка доступна автоматически. Кнопка всплывает каждые 10 минут или около того. Проблема в том, что я не могу сохранить значение своего флажка. Я прошел около 30-40 итераций своего кода, поэтому он немного запутанный и повсеместно, поэтому, пожалуйста, извините за гиббери sh. Вот мой код:
Манифест. json:
{
"name": "Auto Chest Graber",
"version": "1.0.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"browser_action": {
"default_title": "Auto Chest Graber",
"default_popup": "popup.html"
},
"permissions": ["tabs","<all_urls>","storage","cookies"]
}
всплывающее окно. html:
<!doctype html>
<html>
<style>
</style>
<body>
<div>
<input id="onOffSwitch" type="checkbox" class="checkbox">Activate Auto Grabber</input>
<script src="content.js" charset="utf-8"></script>
</div>
</body>
</html>
содержимое. js:
function saveChanges() {
// Get a value saved in a form.
var checkBoxValue = document.getElementById('onOffSwitch').value;
// Check that there's some code there.
if (!checkBoxValue) {
message('Error: No value specified');
return;
}
if (checkBoxValue = null) {
checkBoxValue = false;
}
// Save it using the Chrome extension storage API.
chrome.storage.sync.set({'value': checkBoxValue}, function() {
// Notify that we saved.
message('Settings saved');
});
}
if (document.getElementById('onOffSwitch').value = true) {
chrome.tabs.executeScript({
file: 'grabLoot.js'
})
}
grabLoot. js:
document.getElementsByClassName("tw-button tw-button--success tw-interactive")[0].click();
Я много раз перечитывал учебник Google по chrome .storage на https://developer.chrome.com/apps/storage, но этого не произошло пока очень помогло.