Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/support jump to same page #70

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4.2",
"version": "0.4.3",
"minAppVersion": "1.0.0",
"description": "Surf the Net in Obsidian.",
"author": "Boninall",
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.4.2",
"version": "0.4.3",
"description": "Surf the Net in Obsidian.",
"main": "main.js",
"scripts": {
Expand Down
22 changes: 20 additions & 2 deletions src/surfingPluginSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface SurfingSettings {
markdownPath: string;
highlightFormat: string;
openInSameTab: boolean;
highlightInSameTab: boolean;
openInObsidianWeb: boolean;
}

Expand All @@ -44,6 +45,7 @@ export const DEFAULT_SETTINGS: SurfingSettings = {
markdownPath: "/",
customHighlightFormat: false,
highlightFormat: '[{CONTENT}]({URL})',
highlightInSameTab: false,
openInSameTab: false,
openInObsidianWeb: false,
}
Expand Down Expand Up @@ -507,7 +509,7 @@ export class SurfingSettingTab extends PluginSettingTab {
}

settingName = t('Copy Link to Highlight Format');
const settingDesc = t("Set copy link to text fragment format. [{CONTENT}]({URL}) By default. You can also set {TIME:YYYY-MM-DD HH:mm:ss} to get the current date.");
let settingDesc = t("Set copy link to text fragment format. [{CONTENT}]({URL}) By default. You can also set {TIME:YYYY-MM-DD HH:mm:ss} to get the current date.");
setting = new Setting(wbContainerEl)
.setName(settingName)
.setDesc(settingDesc)
Expand All @@ -528,6 +530,22 @@ export class SurfingSettingTab extends PluginSettingTab {
);

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

settingName = t('Jump to Opened Page');
settingDesc = t("When click on the URL from same domain name in the note, jump to the same surfing view rather than opening a new Surfing view.");
setting = new Setting(wbContainerEl)
.setName(settingName)
.setDesc(settingDesc)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.highlightInSameTab)
.onChange(async (value) => {
this.plugin.settings.highlightInSameTab = value;
this.applySettingsUpdate();
});
});

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

private addOpenInSameTab(tabName: string, wbContainerEl: HTMLElement) {
Expand All @@ -548,7 +566,7 @@ export class SurfingSettingTab extends PluginSettingTab {
}

private addOpenInObsidianWeb(tabName: string, wbContainerEl: HTMLElement) {
const settingName = t('Open URL In Obsidian Web From Other Software');
const settingName = t('Open URL In Obsidian Web From Other Software (Reload to take effect)');
const setting = new Setting(wbContainerEl)
.setName(settingName)
.addToggle((toggle) => {
Expand Down
16 changes: 12 additions & 4 deletions src/surfingView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import SurfingPlugin from "./surfingIndex";
import { t } from "./translations/helper";
import searchBox from "./component/searchBox";
import { SEARCH_ENGINES } from "./surfingPluginSetting";
import { around } from "monkey-around";
import { tokenType } from "./types/obsidian";
import { checkIfWebBrowserAvailable } from "./utils/urltest";

export const WEB_BROWSER_VIEW_ID = "surfing-view";

Expand All @@ -37,7 +34,9 @@ export class SurfingView extends ItemView {
}

static spawnWebBrowserView(newLeaf: boolean, state: WebBrowserViewState) {
const isOpenInSameTab = app.plugins.getPlugin("surfing").settings.openInSameTab;
const pluginSettings = app.plugins.getPlugin("surfing").settings;
const isOpenInSameTab = pluginSettings.openInSameTab;
const highlightInSameTab = pluginSettings.highlightInSameTab;
if (!isOpenInSameTab) {
if (state.url.contains("bilibili")) {
for (let i = 0; i < app.workspace.getLeavesOfType(WEB_BROWSER_VIEW_ID).length; i++) {
Expand All @@ -48,6 +47,15 @@ export class SurfingView extends ItemView {
return;
}
}
} else if (state.url.contains("#:~:text=") && highlightInSameTab) {
for (let i = 0; i < app.workspace.getLeavesOfType(WEB_BROWSER_VIEW_ID).length; i++) {
if (app.workspace.getLeavesOfType(WEB_BROWSER_VIEW_ID)[i].getViewState().state.url.split('#:~:text=')[0] === state.url.split('#:~:text=')[0]) {
// @ts-ignore
app.workspace.getLeavesOfType(WEB_BROWSER_VIEW_ID)[i].view.navigate(state.url, false, true);
(app.workspace.getLeavesOfType(WEB_BROWSER_VIEW_ID)[i]).rebuildView();
return;
}
}
}
app.workspace.getLeaf(newLeaf).setViewState({ type: WEB_BROWSER_VIEW_ID, active: true, state });
return;
Expand Down
4 changes: 3 additions & 1 deletion src/translations/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
'Copy Plain Text': 'Copy Plain Text',
'Copy Link to Highlight': 'Copy Link to Highlight',
'Copy Video Timestamp': 'Copy Video Time',
'Open URL In Obsidian Web From Other Software': 'Open URL In Obsidian Web From Other Software',
'Open URL In Obsidian Web From Other Software (Reload to take effect)': 'Open URL In Obsidian Web From Other Software (Reload to take effect)',
"Copy BookmarkLets Success": "Copy BookmarkLets Success",
'Refresh Current Page': 'Refresh Current Page',
'Show Search Bar In Empty Page': 'Show Search Bar In Empty Page',
Expand Down Expand Up @@ -53,4 +53,6 @@ export default {
'Surfing is using iframe to prevent crashed when loading some websites.': 'Surfing is using iframe to prevent crashed when loading some websites.',
'Open With External Browser': 'Open With External Browser',
'Open With Surfing': 'Open With Surfing',
"When click on the URL from same domain name in the note, jump to the same surfing view rather than opening a new Surfing view.": "When click on the URL from same domain name in the note, jump to the same surfing view rather than opening a new Surfing view.",
'Jump to Opened Page': 'Jump to Opened Page',
};
4 changes: 3 additions & 1 deletion src/translations/locale/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
'Copy Plain Text': '复制纯文本',
'Copy Link to Highlight': '复制指向突出显示的链接',
'Copy Video Timestamp': '复制视频时间戳',
'Open URL In Obsidian Web From Other Software': '从别的软件在 Obsidian Web 中打开网址',
'Open URL In Obsidian Web From Other Software (Reload to take effect)': '从别的软件在 Obsidian Web 中打开网址 (重启 Ob 以生效)',
"Copy BookmarkLets Success": '复制 BookmarkLets 成功',
'Refresh Current Page': '刷新当前页面',
'Show Search Bar In Empty Page': '在空白页面中显示搜索栏',
Expand Down Expand Up @@ -51,4 +51,6 @@ export default {
'Surfing is using iframe to prevent crashed when loading some websites.': 'Surfing 使用 iframe 来防止加载某些网站时崩溃。',
'Open With External Browser': '在外部浏览器中打开',
'Open With Surfing': '在 Surfing 中打开',
"When click on the URL from same domain name in the note, jump to the same surfing view rather than opening a new Surfing view.": "当在笔记中点击相同域名的 URL 时,跳转到相同的 Surfing 视图而不是打开新的 Surfing 视图。",
'Jump to Opened Page': '跳转到已打开的页面',
};
1 change: 0 additions & 1 deletion src/types/obsidian.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ declare module "obsidian" {
id: string

history: {
constructor: () => {}
backHistory: Array<any>,
forwardHistory: Array<any>
},
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"0.3.0": "1.0.0",
"0.4.0": "1.0.0",
"0.4.1": "1.0.0",
"0.4.2": "1.0.0"
"0.4.2": "1.0.0",
"0.4.3": "1.0.0"
}