diff options
Diffstat (limited to 'ext/js')
| -rw-r--r-- | ext/js/accessibility/google-docs.js | 27 | ||||
| -rw-r--r-- | ext/js/background/backend.js | 36 | ||||
| -rw-r--r-- | ext/js/data/options-util.js | 14 | ||||
| -rw-r--r-- | ext/js/document-start.js | 18 | 
4 files changed, 93 insertions, 2 deletions
| diff --git a/ext/js/accessibility/google-docs.js b/ext/js/accessibility/google-docs.js new file mode 100644 index 00000000..f9ba0f7f --- /dev/null +++ b/ext/js/accessibility/google-docs.js @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2021  Yomichan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program.  If not, see <https://www.gnu.org/licenses/>. + */ + +(() => { +    let parent = document.head; +    if (parent === null) { +        parent = document.documentElement; +        if (parent === null) { return; } +    } +    const script = document.createElement('script'); +    script.textContent = 'window._docs_force_html_by_ext = true;'; +    parent.appendChild(script); +})(); 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); +    }  } diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index 42d8a93a..30ffadb1 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -462,7 +462,8 @@ class OptionsUtil {              {async: true,  update: this._updateVersion10.bind(this)},              {async: false, update: this._updateVersion11.bind(this)},              {async: true,  update: this._updateVersion12.bind(this)}, -            {async: true,  update: this._updateVersion13.bind(this)} +            {async: true,  update: this._updateVersion13.bind(this)}, +            {async: false, update: this._updateVersion14.bind(this)}          ];          if (typeof targetVersion === 'number' && targetVersion < result.length) {              result.splice(targetVersion); @@ -864,4 +865,15 @@ class OptionsUtil {          }          return options;      } + +    _updateVersion14(options) { +        // Version 14 changes: +        //  Added accessibility options. +        for (const profile of options.profiles) { +            profile.options.accessibility = { +                forceGoogleDocsHtmlRendering: false +            }; +        } +        return options; +    }  } diff --git a/ext/js/document-start.js b/ext/js/document-start.js new file mode 100644 index 00000000..de1c2403 --- /dev/null +++ b/ext/js/document-start.js @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2021  Yomichan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program.  If not, see <https://www.gnu.org/licenses/>. + */ + +chrome.runtime.sendMessage({action: 'documentStart'}, () => void chrome.runtime.lastError); |