summaryrefslogtreecommitdiff
path: root/ext/js/background/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-08-07 12:40:51 -0400
committerGitHub <noreply@github.com>2021-08-07 12:40:51 -0400
commit5d4141a429dad23d78238f67ef61baabd251e67c (patch)
tree7e9875b3fb576d714204bb42e9c9ce862ec3c0a0 /ext/js/background/backend.js
parentad31b70b67be6a8a3d53769dacc748aa850330bc (diff)
Google Docs accessibility (#1875)
* Add accessibility option for forcing Google Docs HTML-based rendering * Update settings * Send a documentStart message at document start * Add accessibility script for Google Docs * Set up accessibility * Update tests
Diffstat (limited to 'ext/js/background/backend.js')
-rw-r--r--ext/js/background/backend.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index 623f3612..b4b9bc27 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -124,7 +124,8 @@ class Backend {
['isTabSearchPopup', {async: true, contentScript: true, handler: this._onApiIsTabSearchPopup.bind(this)}],
['triggerDatabaseUpdated', {async: false, contentScript: true, handler: this._onApiTriggerDatabaseUpdated.bind(this)}],
['testMecab', {async: true, contentScript: true, handler: this._onApiTestMecab.bind(this)}],
- ['textHasJapaneseCharacters', {async: false, contentScript: true, handler: this._onApiTextHasJapaneseCharacters.bind(this)}]
+ ['textHasJapaneseCharacters', {async: false, contentScript: true, handler: this._onApiTextHasJapaneseCharacters.bind(this)}],
+ ['documentStart', {async: false, contentScript: true, handler: this._onDocumentStart.bind(this)}]
]);
this._messageHandlersWithProgress = new Map([
]);
@@ -745,6 +746,12 @@ class Backend {
return this._japaneseUtil.isStringPartiallyJapanese(text);
}
+ _onDocumentStart(params, sender) {
+ const {tab, frameId, url} = sender;
+ if (typeof url !== 'string' || typeof tab !== 'object' || tab === null) { return; }
+ this._updateTabAccessibility(url, tab, frameId);
+ }
+
// Command handlers
async _onCommandOpenSearchPage(params) {
@@ -2207,4 +2214,31 @@ class Backend {
// NOP
}
}
+
+ _updateTabAccessibility(url, tab, frameId) {
+ let file = null;
+
+ switch (new URL(url).hostname) {
+ case 'docs.google.com':
+ {
+ const optionsContext = {depth: 0, url};
+ const options = this._getProfileOptions(optionsContext);
+ if (!options.accessibility.forceGoogleDocsHtmlRendering) { return; }
+ file = 'js/accessibility/google-docs.js';
+ }
+ break;
+ }
+
+ if (file === null) { return; }
+
+ const details = {
+ allFrames: false,
+ frameId,
+ file,
+ matchAboutBlank: true,
+ runAt: 'document_start'
+ };
+ const callback = () => this._checkLastError(chrome.runtime.lastError);
+ chrome.tabs.executeScript(tab.id, details, callback);
+ }
}