Skip to content

Commit

Permalink
Merge branch 'master_pdfpattern' #45
Browse files Browse the repository at this point in the history
  • Loading branch information
wtetsu committed Aug 15, 2020
2 parents b8938e4 + a8537da commit 6a2bc87
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
11 changes: 4 additions & 7 deletions src/main/core/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const processFirstLaunch = async () => {

const { settings, position } = await config.loadAll();

if (onPdfDocument(location.href, settings.pdfUrlPattern)) {
if (onPdfDocument(location.href, settings.pdfUrl)) {
launchPdfViewer(settings);
return;
}
Expand Down Expand Up @@ -68,13 +68,10 @@ const launchPdfViewer = (settings) => {
};

const onPdfDocument = (url, pdfUrlPattern) => {
const e = document.body?.children?.[0];
if (e?.tagName === "EMBED" && e?.type === "application/pdf") {
return true;
}

if (!pdfUrlPattern) {
return false;
const e = document.body?.children?.[0];
const embedPdf = e?.tagName === "EMBED" && e?.type === "application/pdf";
return embedPdf;
}

try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/settings/defaultsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
initialPosition: "right",
scroll: "scroll",
skipPdfConfirmation: false,
pdfUrlPattern: "\\.(?:pdf|PDF)\\??[\\w-=&~]*$",
pdfUrl: "",
backgroundColor: "#ffffff",
headFontColor: "#000088",
descFontColor: "#101010",
Expand Down
7 changes: 4 additions & 3 deletions src/options/component/AdvancedSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type AdvancedSettingsProps = {
export const AdvancedSettings: React.FC<AdvancedSettingsProps> = (props) => {
const lookupWithCapitalized = props.settings?.lookupWithCapitalized ?? false;
const parseWordsLimit = props.settings?.parseWordsLimit ?? 8;
const pdfUrlPattern = props.settings?.pdfUrlPattern ?? "";
const pdfUrl = props.settings?.pdfUrl ?? "";
const contentWrapperTemplate = props.settings?.contentWrapperTemplate ?? "";
const dialogTemplate = props.settings?.dialogTemplate ?? "";
const contentTemplate = props.settings?.contentTemplate ?? "";
Expand Down Expand Up @@ -65,9 +65,10 @@ export const AdvancedSettings: React.FC<AdvancedSettingsProps> = (props) => {
&nbsp;
<input
type="text"
value={pdfUrlPattern}
onChange={(e) => update({ pdfUrlPattern: e.target.value })}
value={pdfUrl}
onChange={(e) => update({ pdfUrl: e.target.value })}
style={{ width: 600 }}
placeholder="\.pdf$"
/>
<h3>
{res.get("htmlTemplate")}
Expand Down
2 changes: 1 addition & 1 deletion src/options/resource/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ export default {
aboutJsonEditor:
"This is JSON data which expresses the whole Mouse Dictionary's settings. Please use it for backup, sharing and so forth.",
skipPdfConfirmation: "Skip PDF download confirmation",
pdfUrlPattern: "PDF URL pattern",
pdfUrlPattern: "Override PDF document judgment (regular expressions for URL)",
};
2 changes: 1 addition & 1 deletion src/options/resource/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ export default {
aboutJsonEditor:
"Mouse Dictionary設定全体のJSONデータです。バックアップや共有にご利用ください ※辞書データは含みません",
skipPdfConfirmation: "PDFファイルのダウンロード確認を省略する",
pdfUrlPattern: "PDFドキュメントとみなすURLパターン",
pdfUrlPattern: "PDFドキュメント判定の上書き(URLに対する正規表現)",
};
2 changes: 1 addition & 1 deletion src/options/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type MouseDictionaryAdvancedSettings = {
contentWrapperTemplate: string;
dialogTemplate: string;
contentTemplate: string;
pdfUrlPattern: string;
pdfUrl: string;
};

export type InitialPosition = "left" | "right" | "keep";
Expand Down

0 comments on commit 6a2bc87

Please sign in to comment.