mirror of
https://github.com/elisspace/AskAssist.git
synced 2026-08-29 15:33:47 +00:00
functioning commit, timer does not reset intervals
This commit is contained in:
@@ -1,53 +1,95 @@
|
||||
let options = {
|
||||
"alert-frequency": 10,
|
||||
"alert-sound": 1,
|
||||
"refresh-frequency": 2
|
||||
"alert-frequency":5,
|
||||
"sound-select":"rick roll",
|
||||
"watch-time": 4,
|
||||
"possible-alerts": [
|
||||
{name:"rick roll", file:'alert2'},
|
||||
{name:"soft beep", file:'alert1'}
|
||||
]
|
||||
};
|
||||
function saveOptions(){
|
||||
document.querySelectorAll('[isOption="true"]').forEach(function(el){
|
||||
options[el.id]=el.innerHTML;
|
||||
})
|
||||
let soundSelect = "";
|
||||
document.querySelectorAll('#alert-sounds>*').forEach(function(el){
|
||||
if(el.style.display!="none"){
|
||||
soundSelect = (soundSelect) ? "error:multiple chosen" : el.innerHTML;
|
||||
}
|
||||
})
|
||||
options["sound-select"]=soundSelect;
|
||||
console.log(options);
|
||||
}
|
||||
|
||||
function appendTool(html){
|
||||
// fetch the plugin components from the background script...
|
||||
chrome.runtime.sendMessage({message:{flag:"get", options:[{name:'toolbar', path:"./components/toolbar.html"}, {name:'options', path:"./components/options.html"}]}}, function(res){
|
||||
chrome.runtime.sendMessage(
|
||||
{message:
|
||||
{flag:"get", options:[
|
||||
{name:'toolbar', path:"./components/toolbar.html"}
|
||||
]}
|
||||
},
|
||||
function(res){
|
||||
//... and append them
|
||||
document.querySelector('.p-workspace__primary_view_contents').innerHTML=res.toolbar+document.querySelector('.p-workspace__primary_view_contents').innerHTML;
|
||||
let toolbar = document.createElement('div');
|
||||
toolbar.innerHTML=res.toolbar;
|
||||
let workspace = document.querySelector('.p-workspace__primary_view_contents');
|
||||
workspace.prepend(toolbar);
|
||||
//... and their event listeners
|
||||
document.querySelector('#start-timer').addEventListener('click', function(){
|
||||
start.style.display = 'none';
|
||||
stop.style.display = 'inline-block';
|
||||
let waiting = document.querySelector('#waiting');
|
||||
let watching = document.querySelector('#watching');
|
||||
let waitBrach = document.querySelector('#waiting-branch');
|
||||
let watchBrach = document.querySelector('#watching-branch');
|
||||
waiting.addEventListener('click', function(){
|
||||
console.log('running refresh')
|
||||
waitBrach.style.display = "none";
|
||||
watchBrach.style.display = "inline";
|
||||
timer = setInterval(function(){
|
||||
var refresh_btn = document.querySelectorAll('[data-qa-action-id="refresh-queue"]')[0];
|
||||
if(refresh_btn){refresh_btn.click()};
|
||||
var refresh_btn = document.querySelector('[data-qa-action-id="refresh-queue"]');
|
||||
refresh_btn.click();
|
||||
if(newQuestion()){
|
||||
chrome.runtime.sendMessage({message:{flag:"alert", option:options["alert-sound"]}});
|
||||
let message = {message:{flag:"alert", options:options}};
|
||||
console.log('New Question Detected - sending alert to background', message);
|
||||
chrome.runtime.sendMessage(message);
|
||||
};
|
||||
console.log(options["refresh-frequency"]*1000)
|
||||
}, options["refresh-frequency"]*1000);
|
||||
}, options["watch-time"]*1000);
|
||||
return timer;
|
||||
});
|
||||
document.querySelector('#stop-timer').addEventListener('click', function(){
|
||||
stop.style.display = 'none';
|
||||
start.style.display = 'inline';
|
||||
watching.addEventListener('click', function(){
|
||||
waitBrach.style.display = "inline";
|
||||
watchBrach.style.display = "none";
|
||||
clearInterval(timer);
|
||||
});
|
||||
document.querySelector('#settings-button').addEventListener('click', function(){
|
||||
let container = document.querySelector('#options-container');
|
||||
if(container.classList.contains('slideOut')){
|
||||
container.classList.remove('slideOut');
|
||||
} else {
|
||||
container.classList.add('slideOut');
|
||||
}
|
||||
});
|
||||
document.querySelectorAll('.ask-option').forEach(function(el){
|
||||
el.addEventListener('change', function(e){
|
||||
options[e.target.id]=e.target.value;
|
||||
console.log(options);
|
||||
document.querySelectorAll('#alert-sounds>*').forEach(function(el,i){
|
||||
el.addEventListener('click', function(e){
|
||||
let next = (e.target.id == "one")? "two" : "one";
|
||||
document.querySelectorAll('#alert-sounds>*').forEach(function(el,i){
|
||||
el.style.display = 'none';
|
||||
})
|
||||
document.querySelector('#'+next).style.display = 'inline';
|
||||
options["alert-sound"]=document.querySelector('#'+next).innerHTML;
|
||||
})
|
||||
})
|
||||
var start = document.querySelector('#start-timer');
|
||||
var stop = document.querySelector('#stop-timer');
|
||||
})
|
||||
}
|
||||
document.querySelectorAll("[contenteditable='true']").forEach(function(el){
|
||||
// approximate on('change') which does not appear to work
|
||||
function handleChange(e){
|
||||
saveOptions();
|
||||
}
|
||||
el.addEventListener("blur", handleChange);
|
||||
el.addEventListener("input", handleChange);
|
||||
// prevent return and overspacing on contenteditable features
|
||||
el.addEventListener("keypress", function(e){
|
||||
if (e.target.innerHTML.length>2){
|
||||
e.preventDefault();
|
||||
};
|
||||
if (isNaN(String.fromCharCode(e.which))) e.preventDefault();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function newQuestion(){
|
||||
console.log('searching for new question...')
|
||||
let search = document.body.innerHTML.search('<b data-stringify-type="bold">AVAILABLE QUESTIONS</b>');
|
||||
if(search!==-1){
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user