Skip to content

Commit

Permalink
fixed #9 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kholmogorov27 committed Mar 13, 2023
1 parent da62801 commit 6a48a01
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 23 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
</head>
<body>
<div id="root"></div>
<script src="config.js"></script>
<script src="icons.js"></script>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions public/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const CONFIG = {
window.CONFIG = {
macros: [
{
category: 'Entertainment',
Expand Down Expand Up @@ -735,5 +735,3 @@ const CONFIG = {
}
}
}

export default CONFIG
4 changes: 1 addition & 3 deletions public/icons.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions settings/settings.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as types from './settingTypes'
import config from '../public/config'

const searchEngines = {}
for (const key in config.engines)
searchEngines[key] = config.engines[key].name
for (const key in window.CONFIG.engines)
searchEngines[key] = window.CONFIG.engines[key].name

const template = {
general: {
Expand Down
5 changes: 2 additions & 3 deletions src/components/Card/Card.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { isValidElement, useMemo, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import useTransitions from '../../hooks/useTransitions'
import ICONS from '../../../public/icons'
import { motion } from 'framer-motion'
import { TbBan } from 'react-icons/tb'
import getCssGradient from '../../functions/generationUtils/getCssGradient'
Expand Down Expand Up @@ -179,8 +178,8 @@ function getIcon(icon, color) {
return <div>{icon}</div>

// if icon name passed
else if (typeof icon === 'string' && Object.prototype.hasOwnProperty.call(ICONS, icon))
return <div dangerouslySetInnerHTML={{__html: ICONS?.[icon]}}/>
else if (typeof icon === 'string' && Object.prototype.hasOwnProperty.call(window.ICONS, icon))
return <div dangerouslySetInnerHTML={{__html: window.ICONS?.[icon]}}/>

// fallback icon
return <div><TbBan color={color}/></div>
Expand Down
3 changes: 1 addition & 2 deletions src/components/MacrosMenu/MacrosMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { Splide, SplideSlide } from '@splidejs/react-splide'
import { Grid } from '@splidejs/splide-extension-grid'
import Card from '../Card/Card'
import { allowedModes } from '../../rules'
import config from '../../../public/config'
import classes from './MacrosMenu.module.css'
import '@splidejs/react-splide/css'

const pinnedMacros = config.macros.filter(m => m.pinned)
const pinnedMacros = window.CONFIG.macros.filter(m => m.pinned)

function MacrosMenu({ visibility, fullVisibility }) {
// settings
Expand Down
8 changes: 3 additions & 5 deletions src/functions/getMacro.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import config from '../../public/config'

function getMacro(query, normalisedURL=null) {
// searching for a macro by url
if (normalisedURL) {
for (const macro of config.macros) {
for (const macro of window.CONFIG.macros) {
// comparing query url and current macro url
if (normalisedURL === macro.normalisedURL) {
return {options: macro, command: null}
}
}
} else {
// searching for a macro by triggers
for (const macro of config.macros) {
for (const macro of window.CONFIG.macros) {
// iterating through triggers
for (const trigger of macro.triggers) {
// query must be equal to a trigger or ends with a command
Expand Down Expand Up @@ -42,7 +40,7 @@ function getCommand(query) {
let foundCommand = null

// sorting commands to don't skip a command which starts the same as an another command
const sortedCommands = config.commands.sort((a, b) => a.trigger.length > b.trigger.length)
const sortedCommands = window.CONFIG.commands.sort((a, b) => a.trigger.length > b.trigger.length)

for (const command of sortedCommands)
// if it's a command
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/useParseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { useContext, useMemo, useRef } from 'react'
import useIsKeyPressed from './useIsKeyPressed'
import { SettingsContext , ColorSchemeContext} from '../contexts/Settings'
import ParsedQuery from '../classes/parsedQuery'
import config from '../../public/config'

function useParseQuery(value, type='query', origin, persist=false) {
/* settings */
const settings = useContext(SettingsContext)
const engine = config.engines[settings.general.searchEngine]
const engine = window.CONFIG.engines[settings.general.searchEngine]
const forceSearchEngineOnCtrl = settings.query.forceSearchEngineOnCtrl
// ---

Expand Down

0 comments on commit 6a48a01

Please sign in to comment.