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

fix: 修复剪藏时标签带有双换行问题 & 优化插件滚动效果 #230

Merged
merged 1 commit into from
Dec 25, 2023
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
6 changes: 3 additions & 3 deletions src/background/context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const menuList: MenuItem[] = [
{
id: 'save-to-yuque-notes',
get title() {
return __i18n('保存到语雀小记');
return __i18n('剪藏到语雀');
},
contexts: ['selection'],
},
Expand All @@ -25,7 +25,7 @@ const menuList: MenuItem[] = [
{
id: 'save-to-yuque-image',
get title() {
return __i18n('保存到语雀小记');
return __i18n('剪藏到语雀');
},
contexts: ['image'],
},
Expand All @@ -43,7 +43,7 @@ export function listenContextMenuEvents() {
const { selectionText } = info;
chromeExtension.scripting.executeScript({
target: { tabId: currentTab?.id as number },
args: [{ html: `${selectionText}<br/>` }],
args: [{ html: `${selectionText}` }],
func: args => {
window._yuque_ext_app.addContentToClipAssistant(args.html, true);
},
Expand Down
63 changes: 29 additions & 34 deletions src/components/SuperSideBar/impl/ClipAssistant/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ import { backgroundBridge } from '@/core/bridge/background';
import { IStartOcrResult, ocrManager } from '@/core/ocr-manager';
import { getBookmarkHTMLs, transformUrlToFile } from '@/isomorphic/util';
import SelectSavePosition from '@/components/SelectSavePosition';
import {
buildParamsForDoc,
buildParamsForNote,
} from '@/components/lake-editor/helper';
import { buildParamsForDoc, buildParamsForNote } from '@/components/lake-editor/helper';
import LinkHelper from '@/isomorphic/link-helper';
import { STORAGE_KEYS } from '@/config';
import {
DefaultSavePosition,
ISavePosition,
} from '@/core/bridge/background/request/mine';
import { DefaultSavePosition, ISavePosition } from '@/core/bridge/background/request/mine';
import { ITag } from '@/core/bridge/background/request/tag';
import useClipShortCut from '@/hooks/useClipShortCut';
import {
Expand Down Expand Up @@ -48,12 +42,9 @@ function ClipContent() {
const [selectTags, setSelectTags] = useState<ITag[]>([]);
const [title, setTitle] = useState('');

const onTitleChange = useCallback(
(e: React.ChangeEvent<HTMLTextAreaElement>) => {
setTitle(e.target.value);
},
[],
);
const onTitleChange = useCallback((e: React.ChangeEvent<HTMLTextAreaElement>) => {
setTitle(e.target.value);
}, []);

const onLoad = useCallback(() => {
// iframe 加载完成后触发一个 message
Expand All @@ -74,10 +65,7 @@ function ClipContent() {
return;
}

const showSuccessMessage = (
text: string,
link: { text: string; href: string },
) => {
const showSuccessMessage = (text: string, link: { text: string; href: string }) => {
if (Env.isRunningHostPage) {
backgroundBridge.tab.showMessage({
text,
Expand Down Expand Up @@ -105,8 +93,8 @@ function ClipContent() {
...(await buildParamsForNote(editor)),
tag_meta_ids: selectTags.map(item => item.id),
};
await backgroundBridge.request.note.create(noteParams);
const url = LinkHelper.goMyNote();
const result: any = await backgroundBridge.request.note.create(noteParams);
const url = LinkHelper.goMyNote(result.data.id);
showSuccessMessage(__i18n('保存成功!'), {
href: url,
text: __i18n('去小记查看'),
Expand Down Expand Up @@ -163,27 +151,30 @@ function ClipContent() {

const onClipPage = async () => {
const html = await backgroundBridge.clip.clipPage();
await addLinkWhenEmpty();
const isAddLink = await addLinkWhenEmpty();
if (!isAddLink) {
editorRef.current?.insertBreakLine();
}
editorRef.current?.appendContent(html);
editorRef.current?.insertBreakLine();
};

const addLinkWhenEmpty = async () => {
if (!editorRef.current?.isEmpty()) {
return;
return false;
}
const config: IClipConfig = await backgroundBridge.configManager.get(
'clip',
);
if (!config.addLink) return;
const config: IClipConfig = await backgroundBridge.configManager.get('clip');
if (!config.addLink) return false;
await onCollectLink();
return true;
};

const onSelectArea = async () => {
const html = await backgroundBridge.clip.selectArea();
await addLinkWhenEmpty();
const isAddLink = await addLinkWhenEmpty();
if (!isAddLink) {
editorRef.current?.insertBreakLine();
}
editorRef.current?.appendContent(html);
editorRef.current?.insertBreakLine();
};

const onScreenOcr = async () => {
Expand All @@ -210,10 +201,11 @@ function ClipContent() {
};
});
const text = textArray?.map(item => item.text)?.join('') || '';
await addLinkWhenEmpty();

const isAddLink = await addLinkWhenEmpty();
if (!isAddLink) {
editorRef.current?.insertBreakLine();
}
editorRef.current?.appendContent(text);
editorRef.current?.insertBreakLine();
}
} catch (error) {
console.log('ocr error:', error);
Expand Down Expand Up @@ -256,13 +248,16 @@ function ClipContent() {
(div as HTMLDivElement)?.click();
};

const onMessage = (e: any) => {
const onMessage = async (e: any) => {
if (e.data.key !== ClipAssistantMessageKey) {
return;
}
switch (e.data.action) {
case ClipAssistantMessageActions.addContent: {
addLinkWhenEmpty();
const isAddLink = await addLinkWhenEmpty();
if (!isAddLink) {
editorRef.current?.insertBreakLine();
}
editorRef.current?.appendContent(e.data?.data);
break;
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/lake-editor/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ export default forwardRef<IEditorRef, EditorProps>((props, ref) => {
},
placeholder: __i18n('输入内容...'),
defaultFontsize: 14,
typography: {
typography: 'classic',
paragraphSpacing: 'relax',
},
});
newEditor.on('visitLink', (url: string) => {
window.open(url, '__blank');
Expand Down
3 changes: 3 additions & 0 deletions src/components/lake-editor/template-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export const templateHtml = `
.ne-layout-mode-fixed .ne-editor-wrap-content, .ne-layout-mode-adapt .ne-editor-wrap-content {
min-width: 317px;
}
.ne-editor-wrap {
overscroll-behavior: contain;
}
</style>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion src/core/bridge/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type ICallBridgeImpl = (bridgeName: string, params?: IBridgeParams, callb
export function callBackgroundBridge(bridgeName: string, data?: MapT<any>, callback?: OneArgFunctionT<any>) {
callback =
callback ||
function () {
function() {
// ignore
};
chrome.runtime.sendMessage(
Expand Down
62 changes: 31 additions & 31 deletions src/core/parseDom/parsePageConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const parsePageConfig = [
{
url: 'https?:\\\\/\\\\/www\\\\.toutiao\\\\.com\\\\/w\\\\/([a-zA-Z]\\\\/)?[a-zA-Z]\\\\d{10,}',
url: 'https?:\\/\\/www\\.toutiao\\.com\\/w\\/([a-zA-Z]\\/)?[a-zA-Z]\\d{10,}',
include: ['.wtt-content'],
exclude: [
'.xgplayer',
Expand All @@ -13,12 +13,12 @@ export const parsePageConfig = [
],
},
{
url: 'https?:\\\\/\\\\/www\\\\.toutiao\\\\.com\\\\/article',
url: 'https?:\\/\\/www\\.toutiao\\.com\\/article',
include: ['.article-content'],
exclude: ['.xgplayer'],
},
{
url: '^https?:\\\\/\\\\/www\\\\.toutiao\\\\.com\\\\/([a-zA-Z]\\\\/)?[a-zA-Z]\\\\d{10,}',
url: '^https?:\\/\\/www\\.toutiao\\.com\\/([a-zA-Z]\\/)?[a-zA-Z]\\d{10,}',
include: ['.article-content', '.weitoutiao-content'],
exclude: [
'#comment-area',
Expand All @@ -32,12 +32,12 @@ export const parsePageConfig = [
],
},
{
url: '^https?:\\\\/\\\\/zhuanlan\\\\.zhihu\\\\.com\\\\/p\\\\/',
url: '^https?:\\/\\/zhuanlan\\.zhihu\\.com\\/p\\/',
include: ['article.Post-Main'],
exclude: ['.Post-Author', '.Post-topicsAndReviewer', '.RichContent-actions', 'img.LinkCard-image', '.Post-Header'],
},
{
url: '^https?:\\\\/\\\\/www\\\\.zhihu\\\\.com\\\\/question\\\\/\\\\d+',
url: '^https?:\\/\\/www\\.zhihu\\.com\\/question\\/\\d+',
include: ['.QuestionHeader-title', '.ContentItem.AnswerItem', '.List-item'],
exclude: [
'.ContentItem-time',
Expand All @@ -53,7 +53,7 @@ export const parsePageConfig = [
],
},
{
url: '^https?:\\\\/\\\\/mp\\\\.weixin\\\\.qq\\\\.com\\\\/s',
url: '^https?:\\/\\/mp\\.weixin\\.qq\\.com\\/s',
include: ['.rich_media_wrp', '.js_inner', '#js_common_share_desc'],
exclude: [
'.weapp_text_link',
Expand All @@ -71,7 +71,7 @@ export const parsePageConfig = [
],
},
{
url: '^https?:\\\\/\\\\/blog\\\\.csdn\\\\.net',
url: '^https?:\\/\\/blog\\.csdn\\.net',
include: ['.blog-content-box', '.hljs-comment'],
exclude: [
'.dp-highlighter.bg_cpp .bar',
Expand All @@ -83,20 +83,20 @@ export const parsePageConfig = [
],
},
{
url: '^https?:\\\\/\\\\/blog\\\\.csdn\\\\.net',
url: '^https?:\\/\\/blog\\.csdn\\.net',
include: ['.blog-content-box', '.hljs-comment'],
exclude: ['.dp-highlighter.bg_cpp .bar'],
},
{ url: '^https?:\\\\/\\\\/new\\\\.qq\\\\.com', include: ['.content-article'], exclude: ['.videoPlayerWrap'] },
{ url: '^https?:\\\\/\\\\/applet-data\\\\.web\\\\.bytedance\\\\.net', include: ['.app-main'], exclude: [] },
{ url: '^https?:\\\\/\\\\/blog\\\\.whatsapp\\\\.com', include: ['._9t2d'], exclude: [] },
{ url: '^https?:\\/\\/new\\.qq\\.com', include: ['.content-article'], exclude: ['.videoPlayerWrap'] },
{ url: '^https?:\\/\\/applet-data\\.web\\.bytedance\\.net', include: ['.app-main'], exclude: [] },
{ url: '^https?:\\/\\/blog\\.whatsapp\\.com', include: ['._9t2d'], exclude: [] },
{
url: '^https?:\\\\/\\\\/gist\\\\.github\\\\.com',
url: '^https?:\\/\\/gist\\.github\\.com',
include: ['.js-gist-file-update-container'],
exclude: ['.px-0'],
},
{
url: '^https?:\\\\/\\\\/www\\\\.lennysnewsletter\\\\.com\\\\/p',
url: '^https?:\\/\\/www\\.lennysnewsletter\\.com\\/p',
include: ['.single-post-container', '.header-with-anchor-widget', 'h1', 'h2', 'h3', 'h4'],
exclude: [
'.meta-subheader',
Expand All @@ -115,27 +115,27 @@ export const parsePageConfig = [
],
},
{
url: '^https?:\\\\/\\\\/www\\\\.larksuite\\\\.com\\\\/hc\\\\/',
url: '^https?:\\/\\/www\\.larksuite\\.com\\/hc\\/',
include: ['#js-hc-breadcrumb ~ div'],
exclude: ['.image-wrapper-sizer'],
},
{
url: '^https?:\\\\/\\\\/www\\\\.feishu\\\\.cn\\\\/hc\\\\/',
url: '^https?:\\/\\/www\\.feishu\\.cn\\/hc\\/',
include: ['#js-hc-breadcrumb ~ div'],
exclude: ['.image-wrapper-sizer'],
},
{
url: '^https?:\\\\/\\\\/baijiahao\\\\.baidu\\\\.com\\\\/s',
url: '^https?:\\/\\/baijiahao\\.baidu\\.com\\/s',
include: ['#app > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1)'],
exclude: ['div > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)', '#commentModule'],
},
{
url: '^https?:\\\\/\\\\/mbd\\\\.baidu\\\\.com\\\\/newspage\\\\/data\\\\/landingsuper?',
url: '^https?:\\/\\/mbd\\.baidu\\.com\\/newspage\\/data\\/landingsuper?',
include: ['#app > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1)'],
exclude: ['div > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)', '#commentModule'],
},
{
url: '^https?:\\\\/\\\\/www\\\\.cnbc\\\\.com\\\\/\\\\d+\\\\/',
url: '^https?:\\/\\/www\\.cnbc\\.com\\/\\d+\\/',
include: ['.PageBuilder-pageWrapper'],
exclude: [
'.ArticleHeader-headerContentContainer',
Expand All @@ -154,7 +154,7 @@ export const parsePageConfig = [
],
},
{
url: '^https?:\\\\/\\\\/nypost\\\\.com\\\\/\\\\d+\\\\/',
url: '^https?:\\/\\/nypost\\.com\\/\\d+\\/',
include: ['.single--article'],
exclude: [
'.sharedaddy',
Expand All @@ -170,7 +170,7 @@ export const parsePageConfig = [
],
},
{
url: '^https?:\\\\/\\\\/time\\\\.geekbang\\\\.org\\\\/column\\\\/article\\\\/',
url: '^https?:\\/\\/time\\.geekbang\\.org\\/column\\/article\\/',
include: ['.Index_contentWidth_3_1Sf'],
exclude: [
'.recommend-read',
Expand All @@ -186,7 +186,7 @@ export const parsePageConfig = [
],
},
{
url: '^https?:\\\\/\\\\/dariusforoux\\\\.com',
url: '^https?:\\/\\/dariusforoux\\.com',
include: ['#content'],
exclude: [
'form',
Expand All @@ -199,7 +199,7 @@ export const parsePageConfig = [
],
},
{
url: '^https?:\\\\/\\\\/cloud\\\\.google\\\\.com\\\\/blog\\\\/',
url: '^https?:\\/\\/cloud\\.google\\.com\\/blog\\/',
include: ['#jump-content', 'c-wiz'],
exclude: [
'article-sticky-share-block',
Expand All @@ -215,25 +215,25 @@ export const parsePageConfig = [
'.glue-modal',
],
},
{ url: '^https?:\\\\/\\\\/medium\\\\.com\\\\/$', include: ['article'], exclude: [] },
{ url: '^https?:\\/\\/medium\\.com\\/$', include: ['article'], exclude: [] },
{
url: '^https?:\\\\/\\\\/medium\\\\.com\\\\/',
url: '^https?:\\/\\/medium\\.com\\/',
include: ['section', 'main'],
exclude: ['header', 'footer', 'button'],
},
{ url: '^https?:\\\\/\\\\/([a-zA-Z0-9]+\\\\.)medium\\\\.com\\\\/([^about])', include: ['section'], exclude: [] },
{ url: '^https?:\\\\/\\\\/([a-zA-Z0-9]+\\\\.)medium\\\\.com\\\\/about', include: ['main'], exclude: [] },
{ url: '^https?:\\\\/\\\\/([a-zA-Z0-9]+\\\\.)medium\\\\.com\\\\/$', include: ['main'], exclude: [] },
{ url: '^https?:\\/\\/([a-zA-Z0-9]+\\.)medium\\.com\\/([^about])', include: ['section'], exclude: [] },
{ url: '^https?:\\/\\/([a-zA-Z0-9]+\\.)medium\\.com\\/about', include: ['main'], exclude: [] },
{ url: '^https?:\\/\\/([a-zA-Z0-9]+\\.)medium\\.com\\/$', include: ['main'], exclude: [] },
{
url: '^https?:\\\\/\\\\/www\\\\.wogoo\\\\.com\\\\/',
url: '^https?:\\/\\/www\\.wogoo\\.com\\/',
include: ['.leftSide'],
exclude: ['.articleComment', '.zan'],
},
{ url: '^https?:\\\\/\\\\/www\\\\.iocoder\\\\.cn\\\\/', include: ['#main'], exclude: ['.article-nav', 'footer'] },
{ url: '^https?:\\/\\/www\\.iocoder\\.cn\\/', include: ['#main'], exclude: ['.article-nav', 'footer'] },
{
url: '^https?:\\\\/\\\\/help\\\\.solidworks\\\\.com\\\\/',
url: '^https?:\\/\\/help\\.solidworks\\.com\\/',
include: ['#DSMainContent'],
exclude: ['#DSLeftPane', '#auto_links'],
},
{ url: '^https?:\\\\/\\\\/effecthouse\\\\.tiktok\\\\.com\\\\/', include: ['section', 'article'], exclude: [] },
{ url: '^https?:\\/\\/effecthouse\\.tiktok\\.com\\/', include: ['section', 'article'], exclude: [] },
];
2 changes: 1 addition & 1 deletion src/isomorphic/link-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Env from './env';

const LinkHelper = {
goDoc: (doc: { id: number }) => `${YUQUE_DOMAIN}/go/doc/${doc.id}`,
goMyNote: () => `${YUQUE_DOMAIN}/dashboard/notes`,
goMyNote: (id: number | string) => `${YUQUE_DOMAIN}/dashboard/notes?selectNoteId=${id}`,
goMyPage: (account: { login: string }) => `${YUQUE_DOMAIN}/${account.login}`,
feedback: () => {
return `https://www.yuque.com/feedbacks/new?body=系统信息:浏览器插件/${Env.isBate ? 'Beta版' : '正式版'}/${
Expand Down
Loading
Loading