review changes
This commit is contained in:
@@ -4,8 +4,7 @@ import { observer } from "mobx-react"
|
|||||||
import { isChrome, getSettings, setStorage } from "utils/browser"
|
import { isChrome, getSettings, setStorage } from "utils/browser"
|
||||||
import ApiClient from "api/Client"
|
import ApiClient from "api/Client"
|
||||||
import remoteServices from "../remoteServices"
|
import remoteServices from "../remoteServices"
|
||||||
import { map, sortedUniqBy, filter } from "lodash"
|
import { pipe, prop, map, sortedUniqBy, filter } from "lodash/fp"
|
||||||
import { getHostOverridesFromSettings } from "../utils/settings"
|
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
class Options extends Component {
|
class Options extends Component {
|
||||||
@@ -18,25 +17,19 @@ class Options extends Component {
|
|||||||
@observable showHostOverrideOptions = false
|
@observable showHostOverrideOptions = false
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.servicesHostOverrideList = sortedUniqBy(
|
this.servicesHostOverrideList = pipe(
|
||||||
map(
|
filter(prop("allowHostOverride")),
|
||||||
filter(remoteServices, (remoteService) => {
|
map((remoteService) => ({
|
||||||
return remoteService.allowHostOverride
|
name: remoteService.name,
|
||||||
}),
|
host: remoteService.host,
|
||||||
(remoteService) => {
|
})),
|
||||||
return {
|
sortedUniqBy("name"),
|
||||||
name: remoteService.name,
|
)(remoteServices)
|
||||||
host: remoteService.host,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"name",
|
|
||||||
)
|
|
||||||
|
|
||||||
getSettings(false).then((storeData) => {
|
getSettings(false).then((storeData) => {
|
||||||
this.subdomain = storeData.subdomain || ""
|
this.subdomain = storeData.subdomain || ""
|
||||||
this.apiKey = storeData.apiKey || ""
|
this.apiKey = storeData.apiKey || ""
|
||||||
this.hostOverrides = getHostOverridesFromSettings(storeData) || {}
|
this.hostOverrides = storeData.hostOverrides || {}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +42,7 @@ class Options extends Component {
|
|||||||
this.hostOverrides[event.target.name] = this.removePathFromUrl(event.target.value.trim())
|
this.hostOverrides[event.target.name] = this.removePathFromUrl(event.target.value.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleHostOverrideOptions = (event) => {
|
toggleHostOverrideOptions = () => {
|
||||||
this.showHostOverrideOptions = !this.showHostOverrideOptions
|
this.showHostOverrideOptions = !this.showHostOverrideOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +54,7 @@ class Options extends Component {
|
|||||||
subdomain: this.subdomain,
|
subdomain: this.subdomain,
|
||||||
apiKey: this.apiKey,
|
apiKey: this.apiKey,
|
||||||
settingTimeTrackingHHMM: false,
|
settingTimeTrackingHHMM: false,
|
||||||
...this.hostOverrides,
|
hostOverrides: this.hostOverrides,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const { version } = chrome.runtime.getManifest()
|
const { version } = chrome.runtime.getManifest()
|
||||||
const apiClient = new ApiClient({
|
const apiClient = new ApiClient({
|
||||||
@@ -142,8 +135,8 @@ class Options extends Component {
|
|||||||
<label>Host URL: {remoteService.name}</label>
|
<label>Host URL: {remoteService.name}</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name={`hostOverrides:${remoteService.name}`}
|
name={remoteService.name}
|
||||||
value={this.hostOverrides[`hostOverrides:${remoteService.name}`]}
|
value={this.hostOverrides[remoteService.name] || ""}
|
||||||
placeholder={remoteService.host}
|
placeholder={remoteService.host}
|
||||||
onKeyDown={this.handleInputKeyDown}
|
onKeyDown={this.handleInputKeyDown}
|
||||||
onChange={this.onChangeHostOverrides}
|
onChange={this.onChangeHostOverrides}
|
||||||
|
|||||||
@@ -8,14 +8,12 @@ import remoteServices from "./remoteServices"
|
|||||||
import { ContentMessenger } from "utils/messaging"
|
import { ContentMessenger } from "utils/messaging"
|
||||||
import "../css/content.scss"
|
import "../css/content.scss"
|
||||||
import { getSettings } from "./utils/browser"
|
import { getSettings } from "./utils/browser"
|
||||||
import { getHostOverridesFromSettings } from "./utils/settings"
|
|
||||||
|
|
||||||
const popupRef = createRef()
|
const popupRef = createRef()
|
||||||
|
|
||||||
let findService
|
let findService
|
||||||
getSettings().then((settings) => {
|
getSettings().then((settings) => {
|
||||||
const hostOverrides = getHostOverridesFromSettings(settings, true)
|
findService = createServiceFinder(remoteServices, settings.hostOverrides)(document)
|
||||||
findService = createServiceFinder(remoteServices, hostOverrides)(document)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
chrome.runtime.onConnect.addListener(function (port) {
|
chrome.runtime.onConnect.addListener(function (port) {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { head } from "lodash/fp"
|
import { head } from "lodash/fp"
|
||||||
import remoteServices from "../remoteServices"
|
|
||||||
|
|
||||||
export const isChrome = () => typeof browser === "undefined" && chrome
|
export const isChrome = () => typeof browser === "undefined" && chrome
|
||||||
export const isFirefox = () => typeof browser !== "undefined" && chrome
|
export const isFirefox = () => typeof browser !== "undefined" && chrome
|
||||||
@@ -7,8 +6,7 @@ export const isFirefox = () => typeof browser !== "undefined" && chrome
|
|||||||
const DEFAULT_SUBDOMAIN = "unset"
|
const DEFAULT_SUBDOMAIN = "unset"
|
||||||
|
|
||||||
export const getSettings = (withDefaultSubdomain = true) => {
|
export const getSettings = (withDefaultSubdomain = true) => {
|
||||||
const keys = ["subdomain", "apiKey", "settingTimeTrackingHHMM",
|
const keys = ["subdomain", "apiKey", "settingTimeTrackingHHMM", "hostOverrides"]
|
||||||
...Object.values(remoteServices).map(remoteService => `hostOverrides:${remoteService.name}`)]
|
|
||||||
const { version } = chrome.runtime.getManifest()
|
const { version } = chrome.runtime.getManifest()
|
||||||
if (isChrome()) {
|
if (isChrome()) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
|||||||
@@ -11,13 +11,11 @@ import { get, forEach, reject, isNil } from "lodash/fp"
|
|||||||
import { createMatcher } from "utils/urlMatcher"
|
import { createMatcher } from "utils/urlMatcher"
|
||||||
import remoteServices from "remoteServices"
|
import remoteServices from "remoteServices"
|
||||||
import { queryTabs, isBrowserTab, getSettings, setStorage } from "utils/browser"
|
import { queryTabs, isBrowserTab, getSettings, setStorage } from "utils/browser"
|
||||||
import { getHostOverridesFromSettings } from "./settings"
|
|
||||||
|
|
||||||
let matcher
|
let matcher
|
||||||
|
|
||||||
const initMatcher = (settings) => {
|
const initMatcher = (settings) => {
|
||||||
const hostOverrides = getHostOverridesFromSettings(settings, true)
|
matcher = createMatcher(remoteServices, settings.hostOverrides)
|
||||||
matcher = createMatcher(remoteServices, hostOverrides)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getSettings().then((settings) => {
|
getSettings().then((settings) => {
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
import { filter, fromPairs, map, toPairs } from "lodash"
|
|
||||||
|
|
||||||
export const getHostOverridesFromSettings = (settings, removePrefix) => {
|
|
||||||
return fromPairs(
|
|
||||||
map(
|
|
||||||
filter(toPairs(settings), (item) => {
|
|
||||||
return item[0].indexOf("hostOverrides") !== -1
|
|
||||||
}),
|
|
||||||
(item) => {
|
|
||||||
if (removePrefix) {
|
|
||||||
item[0] = item[0].replace("hostOverrides:", "")
|
|
||||||
}
|
|
||||||
return item
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -44,7 +44,7 @@ const prepareHostForRegExp = (host) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return host.replace(":", "\\:")//.replace(/\//g, "\\/")
|
return host.replace(":", "\\:")
|
||||||
}
|
}
|
||||||
|
|
||||||
const replaceHostInPattern = (host, pattern) => {
|
const replaceHostInPattern = (host, pattern) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user