92 lines
2.9 KiB
JavaScript
92 lines
2.9 KiB
JavaScript
var bg = chrome.extension.getBackgroundPage();
|
|
|
|
/* var testButton = document.getElementById('test_btn');
|
|
var getItemsButton = document.getElementById('getItems_btn');
|
|
var tabInfoButton = document.getElementById('tabInfo_btn');
|
|
|
|
testButton.addEventListener('click', function () {
|
|
console.log('debug tab:');
|
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
|
chrome.tabs.sendMessage(tabs[0].id, { from: 'popup', to: 'content_scripts', action: 'run_title' }, function (response) {
|
|
console.log(response);
|
|
});
|
|
});
|
|
});
|
|
|
|
getItemsButton.addEventListener('click', function () {
|
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
|
chrome.tabs.sendMessage(tabs[0].id, { from: 'popup', to: 'content_scripts', action: 'get_items' }, function (response) {
|
|
console.log(response);
|
|
});
|
|
});
|
|
});
|
|
|
|
tabInfoButton.addEventListener('click', function () {
|
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
|
chrome.tabs.sendMessage(tabs[0].id, { from: 'popup', to: 'content_scripts', action: 'tab_info' }, function (response) {
|
|
console.log(response);
|
|
});
|
|
});
|
|
});
|
|
*/
|
|
|
|
var runButton = document.getElementById('checkboxThreeInput');
|
|
|
|
runButton.addEventListener('click', function () {
|
|
console.log('debug tab:');
|
|
var cmd = "bg_stop_cmd";
|
|
if (runButton.checked) {
|
|
cmd = "bg_run_cmd"
|
|
}
|
|
|
|
chrome.runtime.sendMessage({ from: 'popup', to: 'content_scripts', action: cmd }, function (response) {
|
|
console.log(response);
|
|
});
|
|
/* chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
|
chrome.tabs.sendMessage(tabs[0].id, { from: 'popup', to: 'content_scripts', action: cmd }, function (response) {
|
|
console.log(response);
|
|
});
|
|
}); */
|
|
});
|
|
|
|
//var tabInfoButton = document.getElementById('runProgress');
|
|
|
|
/* chrome.extension.onMessage.addListener(
|
|
function (request, sender, sendResponse) {
|
|
console.log('收到消息', request);
|
|
sendResponse("回答处理结果");
|
|
}
|
|
); */
|
|
|
|
/* var prog = 0;
|
|
|
|
window.onload = function () {
|
|
var tolProgress = document.getElementById('runProgress');
|
|
var prgTimer = setInterval(function () {
|
|
tolProgress.style.width = prog + "%";
|
|
console.log("Progress: %d", prog);
|
|
if(prog++ >= 100) {
|
|
clearInterval(prgTimer);
|
|
}
|
|
}, 100);
|
|
} */
|
|
|
|
//var prog = 0;
|
|
|
|
window.onload = function () {
|
|
runButton.checked = bg.g_isRunCmd;
|
|
/* var tolProgress = document.getElementById('runProgress');
|
|
var prgTimer = setInterval(function () {
|
|
tolProgress.style.width = prog + "%";
|
|
console.log("Progress: %d", prog);
|
|
|
|
if(bg.g_totalItems > 0) {
|
|
prog = Math.floor(bg.g_readItems * 100 / bg.g_totalItems);
|
|
}
|
|
|
|
if(prog >= 100) {
|
|
clearInterval(prgTimer);
|
|
}
|
|
}, 1000); */
|
|
}
|