Skip to content

Commit

Permalink
template
Browse files Browse the repository at this point in the history
  • Loading branch information
hoothin committed Oct 16, 2023
1 parent fc2009f commit a0175bb
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = "1.6.30.8";
export const version = "1.6.30.9";
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ window.setLang = (_lang) => {
hideOnSearchEngine: '在搜索引擎页面隐藏',
hideOnSearchEngineTips: '启用后,在搜索引擎页面搜索条将不再自动显示',
suggestType: '搜索联想词的引擎',
templateTitle: '模板文本,用 $template{模板名} 调用',
templateName: '模板名',
templateValue: '模板内容',
paramTitle: '搜索参数',
param: '参数',
details: '详述',
Expand Down Expand Up @@ -549,6 +552,9 @@ window.setLang = (_lang) => {
hideOnSearchEngine: '在搜尋引擎頁面隱藏',
hideOnSearchEngineTips: '啓用後,在搜尋引擎頁面搜尋條將不再自動顯示',
suggestType: '搜索聯想詞的引擎',
templateTitle: '模板文本,用 $template{模板名} 調用',
templateName: '模板名',
templateValue: '模板内容',
paramTitle: '搜尋參數',
param: '參數',
details: '詳述',
Expand Down Expand Up @@ -838,6 +844,9 @@ window.setLang = (_lang) => {
hideOnSearchEngine: 'Hide on search engine page',
hideOnSearchEngineTips: 'After enabling, Search Bar on the search engine page will no longer be displayed automatically',
suggestType: 'Source of related words',
templateTitle: 'Template text, call by $template{template name}',
templateName: 'Template Name',
templateValue: 'Template Value',
paramTitle: 'Search params',
param: 'Param',
details: 'Details',
Expand Down
2 changes: 1 addition & 1 deletion src/page/Engines.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ export default function Engines() {
createData('showTips:', window.i18n('param_showTips')),
createData('find:', window.i18n('param_find')),
createData('find.addto():', window.i18n('param_findadd')),
createData('javascript:', window.i18n('javascript'))
createData('javascript', window.i18n('javascript'))
];
let selectTxt = -1, selectImg = -1, selectLink = -1, selectPage = -1, selectAll = -1;
for (let i = 0; i < window.searchData.sitesConfig.length; i++) {
Expand Down
73 changes: 72 additions & 1 deletion src/page/Export.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ import { createClient } from "webdav";
import Snackbar from '@mui/material/Snackbar';
import MuiAlert from '@mui/material/Alert';
import ContentPasteGoIcon from '@mui/icons-material/ContentPasteGo';
import Accordion from '@mui/material/Accordion';
import AccordionSummary from '@mui/material/AccordionSummary';
import AccordionDetails from '@mui/material/AccordionDetails';
import Typography from '@mui/material/Typography';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline';


async function checkWebdav(host, username, password, pathname) {
Expand Down Expand Up @@ -430,9 +436,14 @@ let longHoldState = 0;
export default function Export() {
const [presetCss, setPresetCss] = React.useState('');
const [openSync, setOpenSync] = React.useState(false);
const [cssText, setCssText] = React.useState(window.searchData.prefConfig.cssText||'');
const [cssText, setCssText] = React.useState(window.searchData.prefConfig.cssText || '');
const [templateData, setTemplateData] = React.useState(window.searchData.prefConfig.templateData || {});
const [fontAwesomeCss, setFontAwesomeCss] = React.useState(window.searchData.prefConfig.fontAwesomeCss);

const [refresh, setRefresh] = React.useState(false);
React.useEffect(() => {
refresh && setTimeout(() => setRefresh(false), 0)
}, [refresh]);
const [alertBody, setAlert] = React.useState({openAlert: false, alertContent: '', alertType: 'error'});
const handleAlertOpen = (content, type) => {
switch (type) {
Expand Down Expand Up @@ -468,6 +479,7 @@ export default function Export() {
var downloadEle = document.createElement('a');
downloadEle.download = "searchJumper.json";
downloadEle.target = "_blank";
var inputingTimer;
function saveConfig() {
try {
if (editor) {
Expand Down Expand Up @@ -669,6 +681,65 @@ export default function Export() {
validator={createAjvValidator(schema)}
/>
</Box>
<Accordion defaultExpanded={true} sx={{ maxHeight: '30vh', overflow: 'auto' }}>
<AccordionSummary
sx={{background: '#f9f9f9', position: 'sticky', top: 0, minHeight: '45px!important', maxHeight: '45px!important'}}
expandIcon={<ExpandMoreIcon />}
id="template-header"
>
<Typography sx={{display: 'block', width: '100%', textAlign: 'center', fontSize: '1.3em', fontWeight: 'bold'}}>{window.i18n("templateTitle")}</Typography>
<IconButton sx={{fontSize: '30px', position: "absolute", color: "rgba(0, 0, 0, 0.54)"}} key='addTemplate'
onClick={e => {
e.preventDefault();
e.stopPropagation();
let templateName = prompt(window.i18n("templateName"));
if (!templateName) return;
let templateValue = prompt(window.i18n("templateValue"));
if (!templateValue) return;
templateData[templateName] = templateValue;
setTemplateData(templateData);
setRefresh(true);
window.searchData.prefConfig.templateData = templateData;
saveConfigToScript();
}}
>
<AddCircleOutlineIcon />
</IconButton>
</AccordionSummary>
<AccordionDetails>
{Object.keys(templateData).map((key, index) =>
<Box sx={{ flexGrow: 1, display: 'flex'}} key={index}>
<TextField
id={"template" + index}
label={key}
fullWidth
sx={{mb : 1}}
value={templateData[key]}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
var newData = {...templateData, [key]: event.target.value};
setTemplateData(newData);
clearTimeout(inputingTimer);
inputingTimer = setTimeout(() => {
window.searchData.prefConfig.templateData = newData;
saveConfigToScript();
}, 500);
}}
/>
<Button variant="outlined" color="error" sx={{ textWrap: "nowrap", margin: "0 0 8px 8px"}} startIcon={<DeleteIcon />}
onClick={()=>{
delete templateData[key];
setTemplateData(templateData);
setRefresh(true);
window.searchData.prefConfig.templateData = templateData;
saveConfigToScript();
}}
>
{window.i18n('delete')}
</Button>
</Box>
)}
</AccordionDetails>
</Accordion>
<FormControl fullWidth sx={{ mt: 1 }}>
<InputLabel>{window.i18n('presetCss')}</InputLabel>
<Select
Expand Down

0 comments on commit a0175bb

Please sign in to comment.