This repository has been archived by the owner on Feb 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #307, make read intent use content script handlers
Also fix #260, 'read' no longer toggles, but only starts reading. Also fix #152, you can stop reading (with 'stop reading') a page that was started manually
- Loading branch information
Showing
2 changed files
with
79 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
/* globals communicate */ | ||
|
||
function startNarration() { | ||
const dropdown = document.querySelector(".narrate-dropdown"); | ||
if (dropdown) { | ||
dropdown.classList.add("open"); | ||
} | ||
const element = document.querySelector(".narrate-start-stop"); | ||
const element = document.querySelector(".narrate-start-stop[title='Start']"); | ||
if (!element) { | ||
return false; | ||
} | ||
if (element) { | ||
element.click(); | ||
} else { | ||
setTimeout(startNarration, 500); | ||
} | ||
return true; | ||
} | ||
|
||
function addListener() { | ||
browser.runtime.onMessage.addListener(message => { | ||
if (message.type === "stopReading") { | ||
const element = document.querySelector(".narrate-start-stop"); | ||
if (element) { | ||
// element.click(); | ||
console.log("clicking element", element); | ||
element.dispatchEvent(new MouseEvent("click")); | ||
} | ||
} else { | ||
console.log("Received unexpected message in startNarration:", message); | ||
} | ||
}); | ||
} | ||
|
||
startNarration(); | ||
addListener(); | ||
communicate.register("narrate", startNarration); | ||
communicate.register("stopReading", () => { | ||
const element = document.querySelector(".narrate-start-stop[title='Stop']"); | ||
if (!element) { | ||
return false; | ||
} | ||
console.log("clicking element", element); | ||
element.dispatchEvent(new MouseEvent("click")); | ||
return true; | ||
}); |