Skip to content

Commit

Permalink
feat: support disable html extension in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Quorafind committed Jan 28, 2024
1 parent 0b6732e commit 6f85b76
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 943 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "surfing",
"name": "Surfing",
"version": "0.9.4",
"version": "0.9.5",
"minAppVersion": "1.4.0",
"description": "Surf the Net in Obsidian.",
"author": "Boninall & Windily-cloud",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "surfing",
"version": "0.9.4",
"version": "0.9.5",
"description": "Use surfing to surf the net in Obsidian.",
"main": "main.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions src/surfingIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class SurfingPlugin extends Plugin {
if (this.settings.bookmarkManager.openBookMark) this.registerView(WEB_BROWSER_BOOKMARK_MANAGER_ID, (leaf) => new SurfingBookmarkManagerView(leaf, this));

try {
this.registerExtensions(HTML_FILE_EXTENSIONS, WEB_BROWSER_FILE_VIEW_ID);
if (this.settings.enableHtmlPreview) this.registerExtensions(HTML_FILE_EXTENSIONS, WEB_BROWSER_FILE_VIEW_ID);
} catch (error) {
new Notice(`File extensions ${HTML_FILE_EXTENSIONS} had been registered by other plugin!`);
}
Expand Down Expand Up @@ -1042,20 +1042,20 @@ export default class SurfingPlugin extends Plugin {

private registerEmbededHTML() {
// @ts-expect-error
app.embedRegistry.registerExtension("html", (e, t, n) => {
this.app.embedRegistry.registerExtension("html", (e, t, n) => {
return new EmbededWebView(e, t);
});
// @ts-expect-error
app.embedRegistry.registerExtension("htm", (e, t, n) => {
this.app.embedRegistry.registerExtension("htm", (e, t, n) => {
return new EmbededWebView(e, t);
});
}

unRegisterEmbededHTML() {
// @ts-expect-error
app.embedRegistry.unregisterExtension("html");
this.app.embedRegistry.unregisterExtension("html");
// @ts-expect-error
app.embedRegistry.unregisterExtension("htm");
this.app.embedRegistry.unregisterExtension("htm");
}

async loadSettings() {
Expand Down
28 changes: 24 additions & 4 deletions src/surfingPluginSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export interface SurfingSettings {
defaultColumnList: string[];
defaultFilterType: string;
},
treeData: NodeModel<CustomData>[]
treeData: NodeModel<CustomData>[];
enableHtmlPreview: boolean;
}

export interface SearchEngine {
Expand Down Expand Up @@ -117,6 +118,7 @@ export const DEFAULT_SETTINGS: SurfingSettings = {
defaultFilterType: 'tree',
},
treeData: [],
enableHtmlPreview: true,
};
// Add search engines here for the future used.
export const SEARCH_ENGINES: SearchEngine[] = [
Expand Down Expand Up @@ -386,7 +388,7 @@ export class SurfingSettingTab extends PluginSettingTab {
private generateGeneralSettings(tabName: string, wbContainerEl: HTMLElement) {
this.addOpenInSameTab(tabName, wbContainerEl);
this.addHoverPopover(tabName, wbContainerEl);

this.addEnableHTMLPreview(tabName, wbContainerEl);
this.addRefreshButton(tabName, wbContainerEl);
this.addHighlightFormat(tabName, wbContainerEl);
this.addMarkdownPath(tabName, wbContainerEl);
Expand Down Expand Up @@ -718,8 +720,8 @@ export class SurfingSettingTab extends PluginSettingTab {
}

private addHoverPopover(tabName: string, wbContainerEl: HTMLElement) {
const settingName = 'Hover Popover';
const settingDesc = 'Show a popover when hover on the link.';
const settingName = t('Hover Popover');
const settingDesc = t('Show a popover when hover on the link.');
const setting = new Setting(wbContainerEl)
.setName(settingName)
.setDesc(settingDesc)
Expand All @@ -735,6 +737,24 @@ export class SurfingSettingTab extends PluginSettingTab {
this.addSettingToMasterSettingsList(tabName, setting.settingEl, settingName, settingDesc);
}

private addEnableHTMLPreview(tabName: string, wbContainerEl: HTMLElement) {
const settingName = t('Enable HTML Preview');
const settingDesc = t('Enable HTML Preview in Surfing');
const setting = new Setting(wbContainerEl)
.setName(settingName)
.setDesc(settingDesc)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.enableHtmlPreview)
.onChange(async (value) => {
this.plugin.settings.enableHtmlPreview = value;
this.applySettingsUpdate();
});
});

this.addSettingToMasterSettingsList(tabName, setting.settingEl, settingName, settingDesc);
}

private addReplaceIframeInCanvas(tabName: string, wbContainerEl: HTMLElement) {
const settingName = t('[Experimental] Replace Iframe In Canvas') + t('(Reload to take effect)');
const setting = new Setting(wbContainerEl)
Expand Down
4 changes: 4 additions & 0 deletions src/translations/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ export default {
"Send to ReadWise": "Send to ReadWise",
"Add a action in page haader to Send to ReadWise.": "Add a action in page haader to Send to ReadWise.",
'Disable / to search when on these sites': 'Disable / to search when on these sites',
'Hover Popover': 'Hover Popover',
'Show a popover when hover on the link.': 'Show a popover when hover on the link.',
'Enable HTML Preview': 'Enable HTML Preview',
'Enable HTML Preview in Surfing': 'Enable HTML Preview in Surfing',
};
2 changes: 2 additions & 0 deletions src/translations/locale/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ export default {
"Send to ReadWise": "发送到 ReadWise",
"Add a action in page haader to Send to ReadWise.": "在页面标题栏中添加一个动作来发送到 ReadWise。",
'Disable / to search when on these sites': '当在这些网站中禁止按 / 来搜索的功能',
'Show a popover when hover on the link.': '当鼠标悬停在链接上时显示一个弹出窗口。',
'Hover Popover': '悬停弹出窗口',
};
Loading

0 comments on commit 6f85b76

Please sign in to comment.