diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/apis/hypothesis/HypothesisUtils.ts | 10 | ||||
| -rw-r--r-- | src/client/views/MainView.tsx | 15 |
2 files changed, 17 insertions, 8 deletions
diff --git a/src/client/apis/hypothesis/HypothesisUtils.ts b/src/client/apis/hypothesis/HypothesisUtils.ts index 16f132e97..8d941cac6 100644 --- a/src/client/apis/hypothesis/HypothesisUtils.ts +++ b/src/client/apis/hypothesis/HypothesisUtils.ts @@ -50,16 +50,16 @@ export namespace Hypothesis { var success = false; const onSuccess = action(() => { - console.log("EDITSUCCESS"); + console.log("EDIT SUCCESS"); + success = true; clearTimeout(interval); DocumentLinksButton.invisibleWebDoc = undefined; document.removeEventListener("editSuccess", onSuccess); - success = true; }); - console.log("SEND addLink"); + console.log("send addLink"); const newHyperlink = `[${title}\n](${url})`; - const interval = setInterval(() => // keep trying to scroll every 250ms until annotations have loaded and editing is successful + const interval = setInterval(() => // keep trying to edit until annotations have loaded and editing is successful !success && document.dispatchEvent(new CustomEvent<{ newHyperlink: string, id: string }>("addLink", { detail: { newHyperlink: newHyperlink, id: annotationId }, bubbles: true @@ -70,7 +70,7 @@ export namespace Hypothesis { clearInterval(interval); DocumentLinksButton.invisibleWebDoc = undefined; } - }), 15000); // give up if no success after 15s + }), 12000); // give up if no success after 12s document.addEventListener("editSuccess", onSuccess); }; diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index ef44e0a4e..11ffcc734 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -824,12 +824,21 @@ export class MainView extends React.Component { </div>; </span>, ele); - const interval = setInterval(() => { + var success = false; + const onSuccess = () => { + console.log("EDIT SUCCESS"); + success = true; + clearTimeout(interval); + document.removeEventListener("editSuccess", onSuccess); + }; + + const interval = setInterval(() => { // keep trying to click until annotations have loaded and editing is successful console.log("clicked"); - simulateMouseClick(ele, 50, 50, 50, 50); + !success && simulateMouseClick(ele, 50, 50, 50, 50); }, 500); - setTimeout(() => clearInterval(interval), 10000); + setTimeout(() => !success && clearInterval(interval), 10000); // give up if no success after 10s + document.addEventListener("editSuccess", onSuccess); }); } } |
