Update browser compatibility and Edge detection (#629)
This commit is contained in:
parent
cdf191336a
commit
7b5dd5c310
@ -82,6 +82,12 @@
|
|||||||
"no-unsanitized/property": "error"
|
"no-unsanitized/property": "error"
|
||||||
},
|
},
|
||||||
"overrides": [
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["ext/mixed/js/core.js"],
|
||||||
|
"env": {
|
||||||
|
"webextensions": false
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"files": ["ext/**/*.js"],
|
"files": ["ext/**/*.js"],
|
||||||
"excludedFiles": ["ext/mixed/js/core.js"],
|
"excludedFiles": ["ext/mixed/js/core.js"],
|
||||||
@ -101,8 +107,7 @@
|
|||||||
"deferPromise": "readonly",
|
"deferPromise": "readonly",
|
||||||
"clone": "readonly",
|
"clone": "readonly",
|
||||||
"EventDispatcher": "readonly",
|
"EventDispatcher": "readonly",
|
||||||
"EventListenerCollection": "readonly",
|
"EventListenerCollection": "readonly"
|
||||||
"EXTENSION_IS_BROWSER_EDGE": "readonly"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -116,7 +121,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"files": ["ext/mixed/js/core.js"],
|
"files": ["ext/mixed/js/yomichan.js"],
|
||||||
"globals": {
|
"globals": {
|
||||||
"chrome": "writable"
|
"chrome": "writable"
|
||||||
}
|
}
|
||||||
|
@ -208,6 +208,7 @@ input[type=checkbox].storage-button-checkbox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
html:root[data-browser=edge] [data-show-for-browser~=edge],
|
html:root[data-browser=edge] [data-show-for-browser~=edge],
|
||||||
|
html:root[data-browser=edge-legacy] [data-show-for-browser~=edge-legacy],
|
||||||
html:root[data-browser=chrome] [data-show-for-browser~=chrome],
|
html:root[data-browser=chrome] [data-show-for-browser~=chrome],
|
||||||
html:root[data-browser=firefox] [data-show-for-browser~=firefox],
|
html:root[data-browser=firefox] [data-show-for-browser~=firefox],
|
||||||
html:root[data-browser=firefox-mobile] [data-show-for-browser~=firefox-mobile],
|
html:root[data-browser=firefox-mobile] [data-show-for-browser~=firefox-mobile],
|
||||||
@ -221,6 +222,7 @@ html:root[data-operating-system=openbsd] [data-show-for-operating-system~=openbs
|
|||||||
}
|
}
|
||||||
|
|
||||||
html:root[data-browser=edge] [data-hide-for-browser~=edge],
|
html:root[data-browser=edge] [data-hide-for-browser~=edge],
|
||||||
|
html:root[data-browser=edge-legacy] [data-hide-for-browser~=edge-legacy],
|
||||||
html:root[data-browser=chrome] [data-hide-for-browser~=chrome],
|
html:root[data-browser=chrome] [data-hide-for-browser~=chrome],
|
||||||
html:root[data-browser=firefox] [data-hide-for-browser~=firefox],
|
html:root[data-browser=firefox] [data-hide-for-browser~=firefox],
|
||||||
html:root[data-browser=firefox-mobile] [data-hide-for-browser~=firefox-mobile],
|
html:root[data-browser=firefox-mobile] [data-hide-for-browser~=firefox-mobile],
|
||||||
|
@ -15,38 +15,6 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Extension information
|
|
||||||
*/
|
|
||||||
|
|
||||||
function _extensionHasChrome() {
|
|
||||||
try {
|
|
||||||
return typeof chrome === 'object' && chrome !== null;
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _extensionHasBrowser() {
|
|
||||||
try {
|
|
||||||
return typeof browser === 'object' && browser !== null;
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const EXTENSION_IS_BROWSER_EDGE = (
|
|
||||||
_extensionHasBrowser() &&
|
|
||||||
(!_extensionHasChrome() || (typeof chrome.runtime === 'undefined' && typeof browser.runtime !== 'undefined'))
|
|
||||||
);
|
|
||||||
|
|
||||||
if (EXTENSION_IS_BROWSER_EDGE) {
|
|
||||||
// Edge does not have chrome defined.
|
|
||||||
chrome = browser;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Error handling
|
* Error handling
|
||||||
*/
|
*/
|
||||||
|
@ -67,8 +67,15 @@ class Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _getBrowser() {
|
async _getBrowser() {
|
||||||
if (EXTENSION_IS_BROWSER_EDGE) {
|
try {
|
||||||
return 'edge';
|
if (chrome.runtime.getURL('/').startsWith('ms-browser-extension://')) {
|
||||||
|
return 'edge-legacy';
|
||||||
|
}
|
||||||
|
if (/\bEdge?\//.test(navigator.userAgent)) {
|
||||||
|
return 'edge';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// NOP
|
||||||
}
|
}
|
||||||
if (typeof browser !== 'undefined') {
|
if (typeof browser !== 'undefined') {
|
||||||
try {
|
try {
|
||||||
|
@ -15,6 +15,25 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Set up chrome alias if it's not available (Edge Legacy)
|
||||||
|
if ((() => {
|
||||||
|
let hasChrome = false;
|
||||||
|
let hasBrowser = false;
|
||||||
|
try {
|
||||||
|
hasChrome = (typeof chrome === 'object' && chrome !== null && typeof chrome.runtime !== 'undefined');
|
||||||
|
} catch (e) {
|
||||||
|
// NOP
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
hasBrowser = (typeof browser === 'object' && browser !== null && typeof browser.runtime !== 'undefined');
|
||||||
|
} catch (e) {
|
||||||
|
// NOP
|
||||||
|
}
|
||||||
|
return (hasBrowser && !hasChrome);
|
||||||
|
})()) {
|
||||||
|
chrome = browser;
|
||||||
|
}
|
||||||
|
|
||||||
const yomichan = (() => {
|
const yomichan = (() => {
|
||||||
class Yomichan extends EventDispatcher {
|
class Yomichan extends EventDispatcher {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
Loading…
Reference in New Issue
Block a user