Skip to content

Commit

Permalink
feat: indicate that work is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Dec 8, 2018
1 parent 58f9106 commit fdb4cca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/solve/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ import {
captchaIbmSpeechApiLangCodes
} from 'utils/data';

let solverRunning = false;
let solverWorking = false;

function setSolverState({working = true} = {}) {
solverWorking = working;
const button = document.querySelector('#buster-button');
if (button) {
if (working) {
button.classList.add('working');
} else {
button.classList.remove('working');
}
}
}

function setButton() {
const infoButton = document.body.querySelector(
Expand All @@ -25,6 +37,9 @@ function setButton() {
button.setAttribute('tabindex', '0');
button.setAttribute('title', getText('buttonText_solve'));
button.id = 'buster-button';
if (solverWorking) {
button.classList.add('working');
}

button.addEventListener('click', start);
button.addEventListener('keydown', e => {
Expand Down Expand Up @@ -230,17 +245,17 @@ function start(e) {
e.preventDefault();
e.stopImmediatePropagation();

if (solverRunning) {
if (solverWorking) {
return;
}
solverRunning = true;
setSolverState({working: true});

solve()
.then(() => {
solverRunning = false;
setSolverState({working: false});
})
.catch(err => {
solverRunning = false;
setSolverState({working: false});
console.log(err.toString());
browser.runtime.sendMessage({
id: 'notification',
Expand Down
5 changes: 5 additions & 0 deletions src/solve/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fdb4cca

Please sign in to comment.