diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-11-23 22:08:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 22:08:30 -0500 |
commit | d454b52a18127f782fafdf71534ea2c41f20ef44 (patch) | |
tree | baa980dbd94d624d44bac2df3d691fb759d8300d /ext/js/accessibility/google-docs.js | |
parent | ecc994a8bbd52a426434a549f8e3e68eba6e786e (diff) |
Google Docs accessibility refactor (#2023)
* Skip urlRegex if it's used as a filter
* Add getRequiredContentScriptRegistrationPermissions function
* Add a reentrant check to google-docs.js
* Remove script node
* Move forceGoogleDocsHtmlRendering check into google-docs.js
* Replace document-start.js usage with google-docs.js
* Remove documentStart handling
* Add missing parameter descriptions
Diffstat (limited to 'ext/js/accessibility/google-docs.js')
-rw-r--r-- | ext/js/accessibility/google-docs.js | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/ext/js/accessibility/google-docs.js b/ext/js/accessibility/google-docs.js index f9ba0f7f..e45743ab 100644 --- a/ext/js/accessibility/google-docs.js +++ b/ext/js/accessibility/google-docs.js @@ -15,7 +15,36 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -(() => { +(async () => { + // Reentrant check + if (self.googleDocsAccessibilitySetup) { return; } + self.googleDocsAccessibilitySetup = true; + + const invokeApi = (action, params) => { + return new Promise((resolve, reject) => { + chrome.runtime.sendMessage({action, params}, (response) => { + void chrome.runtime.lastError; + if (typeof response !== 'object' || response === null) { + reject(new Error('Unexpected response')); + } else if (typeof response.error !== 'undefined') { + reject(new Error('Invalid response')); + } else { + resolve(response.result); + } + }); + }); + }; + + const optionsContext = {depth: 0, url: location.href}; + let options; + try { + options = await invokeApi('optionsGet', {optionsContext}); + } catch (e) { + return; + } + + if (!options.accessibility.forceGoogleDocsHtmlRendering) { return; } + let parent = document.head; if (parent === null) { parent = document.documentElement; @@ -24,4 +53,5 @@ const script = document.createElement('script'); script.textContent = 'window._docs_force_html_by_ext = true;'; parent.appendChild(script); + parent.removeChild(script); })(); |