fix #223 - Android compatibility
This commit is contained in:
parent
febaefd8dc
commit
8f04e17d27
|
@ -30,14 +30,21 @@ chrome.runtime.onMessage.addListener(onRuntimeMessage);
|
||||||
listener('styleReplaceAll', data));
|
listener('styleReplaceAll', data));
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.contextMenus.onClicked.addListener((info, tab) =>
|
if (chrome.contextMenus) {
|
||||||
contextMenus[info.menuItemId].click(info, tab));
|
chrome.contextMenus.onClicked.addListener((info, tab) =>
|
||||||
|
contextMenus[info.menuItemId].click(info, tab));
|
||||||
|
}
|
||||||
|
|
||||||
if ('commands' in chrome) {
|
if (chrome.commands) {
|
||||||
// Not available in Firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=1240350
|
// Not available in Firefox - https://bugzilla.mozilla.org/show_bug.cgi?id=1240350
|
||||||
chrome.commands.onCommand.addListener(command => browserCommands[command]());
|
chrome.commands.onCommand.addListener(command => browserCommands[command]());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!chrome.browserAction ||
|
||||||
|
!['setIcon', 'setBadgeBackgroundColor', 'setBadgeText'].every(name => chrome.browserAction[name])) {
|
||||||
|
window.updateIcon = () => {};
|
||||||
|
}
|
||||||
|
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
// set the default icon displayed after a tab is created until webNavigation kicks in
|
// set the default icon displayed after a tab is created until webNavigation kicks in
|
||||||
prefs.subscribe(['iconset'], () => updateIcon({id: undefined}, {}));
|
prefs.subscribe(['iconset'], () => updateIcon({id: undefined}, {}));
|
||||||
|
@ -108,7 +115,7 @@ contextMenus = Object.assign({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
if (chrome.contextMenus) {
|
||||||
const createContextMenus = (ids = Object.keys(contextMenus)) => {
|
const createContextMenus = (ids = Object.keys(contextMenus)) => {
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
const item = Object.assign({id}, contextMenus[id]);
|
const item = Object.assign({id}, contextMenus[id]);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<html id="stylus">
|
<html id="stylus">
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
<style id="firefox-transitions-bug-suppressor">
|
<style id="firefox-transitions-bug-suppressor">
|
||||||
/* restrict to FF */
|
/* restrict to FF */
|
||||||
|
|
|
@ -505,7 +505,7 @@ document.addEventListener('wheel', event => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
queryTabs({currentWindow: true}).then(tabs => {
|
chrome.windows && queryTabs({currentWindow: true}).then(tabs => {
|
||||||
const windowId = tabs[0].windowId;
|
const windowId = tabs[0].windowId;
|
||||||
if (prefs.get('openEditInWindow')) {
|
if (prefs.get('openEditInWindow')) {
|
||||||
if (
|
if (
|
||||||
|
@ -532,6 +532,9 @@ queryTabs({currentWindow: true}).then(tabs => {
|
||||||
getOwnTab().then(tab => {
|
getOwnTab().then(tab => {
|
||||||
const ownTabId = tab.id;
|
const ownTabId = tab.id;
|
||||||
useHistoryBack = sessionStorageHash('manageStylesHistory').value[ownTabId] === location.href;
|
useHistoryBack = sessionStorageHash('manageStylesHistory').value[ownTabId] === location.href;
|
||||||
|
if (!chrome.windows) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// When an edit page gets attached or detached, remember its state
|
// When an edit page gets attached or detached, remember its state
|
||||||
// so we can do the same to the next one to open.
|
// so we can do the same to the next one to open.
|
||||||
chrome.tabs.onAttached.addListener((tabId, info) => {
|
chrome.tabs.onAttached.addListener((tabId, info) => {
|
||||||
|
@ -1500,7 +1503,7 @@ function initHooks() {
|
||||||
|
|
||||||
|
|
||||||
function toggleContextMenuDelete(event) {
|
function toggleContextMenuDelete(event) {
|
||||||
if (event.button === 2 && prefs.get('editor.contextDelete')) {
|
if (chrome.contextMenus && event.button === 2 && prefs.get('editor.contextDelete')) {
|
||||||
chrome.contextMenus.update('editor.contextDelete', {
|
chrome.contextMenus.update('editor.contextDelete', {
|
||||||
enabled: Boolean(
|
enabled: Boolean(
|
||||||
this.selectionStart !== this.selectionEnd ||
|
this.selectionStart !== this.selectionEnd ||
|
||||||
|
|
|
@ -47,7 +47,7 @@ onDOMready().then(() => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!chrome.app) {
|
if (!chrome.app && chrome.windows) {
|
||||||
// die if unable to access BG directly
|
// die if unable to access BG directly
|
||||||
chrome.windows.getCurrent(wnd => {
|
chrome.windows.getCurrent(wnd => {
|
||||||
if (!BG && wnd.incognito) {
|
if (!BG && wnd.incognito) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ const KEEP_CHANNEL_OPEN = true;
|
||||||
|
|
||||||
const CHROME = Boolean(chrome.app) && parseInt(navigator.userAgent.match(/Chrom\w+\/(?:\d+\.){2}(\d+)|$/)[1]);
|
const CHROME = Boolean(chrome.app) && parseInt(navigator.userAgent.match(/Chrom\w+\/(?:\d+\.){2}(\d+)|$/)[1]);
|
||||||
const OPERA = CHROME && parseFloat(navigator.userAgent.match(/\bOPR\/(\d+\.\d+)|$/)[1]);
|
const OPERA = CHROME && parseFloat(navigator.userAgent.match(/\bOPR\/(\d+\.\d+)|$/)[1]);
|
||||||
|
const ANDROID = !chrome.windows;
|
||||||
let FIREFOX = !CHROME && parseFloat(navigator.userAgent.match(/\bFirefox\/(\d+\.\d+)|$/)[1]);
|
let FIREFOX = !CHROME && parseFloat(navigator.userAgent.match(/\bFirefox\/(\d+\.\d+)|$/)[1]);
|
||||||
|
|
||||||
if (!CHROME && !chrome.browserAction.openPopup) {
|
if (!CHROME && !chrome.browserAction.openPopup) {
|
||||||
|
@ -204,7 +205,8 @@ function openURL({url, index, openerTabId, currentWindow = true}) {
|
||||||
} else {
|
} else {
|
||||||
// create a new tab
|
// create a new tab
|
||||||
const options = {url, index};
|
const options = {url, index};
|
||||||
if (tab && (!FIREFOX || FIREFOX >= 57) && !chromeInIncognito) {
|
// FF57+ supports openerTabId, but not in Android (indicated by the absence of chrome.windows)
|
||||||
|
if (tab && (!FIREFOX || FIREFOX >= 57 && chrome.windows) && !chromeInIncognito) {
|
||||||
options.openerTabId = tab.id;
|
options.openerTabId = tab.id;
|
||||||
}
|
}
|
||||||
chrome.tabs.create(options, resolve);
|
chrome.tabs.create(options, resolve);
|
||||||
|
@ -220,7 +222,7 @@ function activateTab(tab) {
|
||||||
new Promise(resolve => {
|
new Promise(resolve => {
|
||||||
chrome.tabs.update(tab.id, {active: true}, resolve);
|
chrome.tabs.update(tab.id, {active: true}, resolve);
|
||||||
}),
|
}),
|
||||||
new Promise(resolve => {
|
chrome.windows && new Promise(resolve => {
|
||||||
chrome.windows.update(tab.windowId, {focused: true}, resolve);
|
chrome.windows.update(tab.windowId, {focused: true}, resolve);
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
@ -438,7 +440,7 @@ function openEditor(id) {
|
||||||
if (id) {
|
if (id) {
|
||||||
url += `?id=${id}`;
|
url += `?id=${id}`;
|
||||||
}
|
}
|
||||||
if (prefs.get('openEditInWindow')) {
|
if (chrome.windows && prefs.get('openEditInWindow')) {
|
||||||
chrome.windows.create(Object.assign({url}, prefs.get('windowPosition')));
|
chrome.windows.create(Object.assign({url}, prefs.get('windowPosition')));
|
||||||
} else {
|
} else {
|
||||||
openURL({url});
|
openURL({url});
|
||||||
|
|
|
@ -23,7 +23,8 @@ var prefs = new function Prefs() {
|
||||||
'manage.onlyEnabled.invert': false, // display only disabled styles
|
'manage.onlyEnabled.invert': false, // display only disabled styles
|
||||||
'manage.onlyLocal.invert': false, // display only externally installed styles
|
'manage.onlyLocal.invert': false, // display only externally installed styles
|
||||||
'manage.onlyUsercss.invert': false, // display only non-usercss (standard) styles
|
'manage.onlyUsercss.invert': false, // display only non-usercss (standard) styles
|
||||||
'manage.newUI': true, // use the new compact layout
|
// the new compact layout doesn't look good on Android yet
|
||||||
|
'manage.newUI': !navigator.appVersion.includes('Android'),
|
||||||
'manage.newUI.favicons': false, // show favicons for the sites in applies-to
|
'manage.newUI.favicons': false, // show favicons for the sites in applies-to
|
||||||
'manage.newUI.faviconsGray': true, // gray out favicons
|
'manage.newUI.faviconsGray': true, // gray out favicons
|
||||||
'manage.newUI.targets': 3, // max number of applies-to targets visible: 0 = none
|
'manage.newUI.targets': 3, // max number of applies-to targets visible: 0 = none
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<html id="stylus">
|
<html id="stylus">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title i18n-text="manageTitle"></title>
|
<title i18n-text="manageTitle"></title>
|
||||||
<link rel="stylesheet" href="manage/manage.css">
|
<link rel="stylesheet" href="manage/manage.css">
|
||||||
<link rel="stylesheet" href="msgbox/msgbox.css">
|
<link rel="stylesheet" href="msgbox/msgbox.css">
|
||||||
|
|
|
@ -333,7 +333,7 @@ Object.assign(handleEvent, {
|
||||||
const openForegroundTab = (middle && shift) || (left && ctrl && shift);
|
const openForegroundTab = (middle && shift) || (left && ctrl && shift);
|
||||||
const url = event.target.closest('[href]').href;
|
const url = event.target.closest('[href]').href;
|
||||||
if (openWindow || openBackgroundTab || openForegroundTab) {
|
if (openWindow || openBackgroundTab || openForegroundTab) {
|
||||||
if (openWindow) {
|
if (chrome.windows && openWindow) {
|
||||||
chrome.windows.create(Object.assign(prefs.get('windowPosition'), {url}));
|
chrome.windows.create(Object.assign(prefs.get('windowPosition'), {url}));
|
||||||
} else {
|
} else {
|
||||||
openURL({url, active: openForegroundTab});
|
openURL({url, active: openForegroundTab});
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html id="stylus">
|
<html id="stylus">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title i18n-text-append="optionsHeading">Stylus </title>
|
<title i18n-text-append="optionsHeading">Stylus </title>
|
||||||
<link rel="stylesheet" href="options/options.css">
|
<link rel="stylesheet" href="options/options.css">
|
||||||
<link rel="stylesheet" href="options/onoffswitch.css">
|
<link rel="stylesheet" href="options/onoffswitch.css">
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<html id="stylus">
|
<html id="stylus">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="popup/popup.css">
|
<link rel="stylesheet" href="popup/popup.css">
|
||||||
|
|
||||||
<style id="firefox-transitions-bug-suppressor">
|
<style id="firefox-transitions-bug-suppressor">
|
||||||
|
|
|
@ -354,7 +354,7 @@ Object.assign(handleEvent, {
|
||||||
},
|
},
|
||||||
|
|
||||||
openLink(event) {
|
openLink(event) {
|
||||||
if (!prefs.get('openEditInWindow', false)) {
|
if (!chrome.windows || !prefs.get('openEditInWindow', false)) {
|
||||||
handleEvent.openURLandHide.call(this, event);
|
handleEvent.openURLandHide.call(this, event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user