Permalink
Browse files

Fixed #98

HIT Catcher buttons now have a fallback and will attempt to send buttons up to 5 times before stopping.
  • Loading branch information...
Kadauchi committed May 31, 2018
1 parent 5c3d739 commit 1128939d9828ceb90a07f1b49793e20a4b336c1e
Showing with 61 additions and 38 deletions.
  1. +19 −5 background/web-request.js
  2. +42 −33 mturk/hit-catcher-buttons-missed.js
@@ -24,6 +24,24 @@ chrome.webRequest.onCompleted.addListener(
async details => {
const request = requestsDB[details.requestId];
let misses = 0;
function missedHIT() {
misses += 1;
chrome.tabs.sendMessage(
request.tabId,
{
hitMissed: request.hit_set_id
},
res => {
if (!res && misses < 5) {
setTimeout(missedHIT, 1000);
}
}
);
}
if (request) {
const catcher = chrome.extension
.getViews()
@@ -36,11 +54,7 @@ chrome.webRequest.onCompleted.addListener(
`https://worker.mturk.com/projects/${request.hit_set_id}/tasks`
) === -1
) {
setTimeout(() => {
chrome.tabs.sendMessage(request.tabId, {
hitMissed: request.hit_set_id
});
}, 1000);
setTimeout(missedHIT, 1000);
}
}
},
@@ -1,39 +1,48 @@
chrome.runtime.onMessage.addListener(async (request) => {
const hitSetId = request.hitMissed;
if (hitSetId) {
const once = document.createElement(`button`);
once.className = `btn btn-primary`;
once.textContent = `Once`;
once.style.marginLeft = `5px`;
once.addEventListener(`click`, () => {
chrome.runtime.sendMessage({
hitCatcher: {
id: hitSetId,
name: ``,
once: true,
sound: true
}
});
async function hitCatcherButtonsMissedHIT(hitSetId, sendResponse) {
const once = document.createElement(`button`);
once.className = `btn btn-primary`;
once.textContent = `Once`;
once.style.marginLeft = `5px`;
once.addEventListener(`click`, () => {
chrome.runtime.sendMessage({
hitCatcher: {
id: hitSetId,
name: ``,
once: true,
sound: true
}
});
});
const panda = document.createElement(`button`);
panda.className = `btn btn-primary`;
panda.textContent = `Panda`;
panda.style.marginLeft = `5px`;
panda.addEventListener(`click`, () => {
chrome.runtime.sendMessage({
hitCatcher: {
id: hitSetId,
name: ``,
once: false,
sound: false
}
});
const panda = document.createElement(`button`);
panda.className = `btn btn-primary`;
panda.textContent = `Panda`;
panda.style.marginLeft = `5px`;
panda.addEventListener(`click`, () => {
chrome.runtime.sendMessage({
hitCatcher: {
id: hitSetId,
name: ``,
once: false,
sound: false
}
});
});
const rEl = await ReactDOM(`reactComponents/alert/Alert`);
rEl.getElementsByTagName(`h3`)[0].appendChild(once);
rEl.getElementsByTagName(`h3`)[0].appendChild(panda);
sendResponse(true);
}
const rEl = await ReactDOM(`reactComponents/alert/Alert`);
rEl.getElementsByTagName(`h3`)[0].appendChild(once);
rEl.getElementsByTagName(`h3`)[0].appendChild(panda);
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
const { hitMissed } = request;
if (hitMissed) {
hitCatcherButtonsMissedHIT(hitMissed, sendResponse);
return true;
}
return false;
});

0 comments on commit 1128939

Please sign in to comment.