Skip to content

Commit

Permalink
feat: 将点击过的链接标记为已读
Browse files Browse the repository at this point in the history
  • Loading branch information
abtswath committed Apr 12, 2024
1 parent 70a9a04 commit 58cd620
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "v2ex topic viewer",
"description": "支持 V2EX 在主题列表页分屏浏览主题内容",
"version": "0.0.5",
"version": "0.0.6",
"action": {
"default_popup": "popup.html",
"default_icon": {
Expand Down
4 changes: 0 additions & 4 deletions src/content/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export class TopicViewer extends HTMLElement {

private loadingElement: HTMLElement;

private loading = false;

constructor() {
super();
const shadowRoot = this.attachShadow({ mode: 'open' });
Expand Down Expand Up @@ -69,15 +67,13 @@ export class TopicViewer extends HTMLElement {
}

protected showLoading() {
this.loading = true;
if (!this.loadingExists()) {
this.container.appendChild(this.loadingElement);
}
removeClass(this.loadingElement, 'topic-viewer-hide');
}

protected hideLoading() {
this.loading = false;
addClass(this.loadingElement, 'topic-viewer-hide');
}

Expand Down
11 changes: 9 additions & 2 deletions src/content/content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "@webcomponents/webcomponentsjs";
import { FRAME_NAME, TopicViewer } from './components';
import { TopicViewer } from './components';

export const getParent = (el: HTMLElement, selector: string): HTMLElement | null => {
if (!el.parentElement) {
Expand Down Expand Up @@ -40,8 +40,8 @@ let rightContainer: HTMLElement | null = null;
const insertAfterTopicItem = (topicViewer: HTMLElement, topicItem: HTMLElement) => {
rightContainer?.remove();
topicViewer.setAttribute('data-height', `calc(100vh - ${topicItem.offsetHeight}px)`);
topicItem.scrollIntoView();
topicItem.parentElement?.insertBefore(topicViewer, topicItem.nextElementSibling);
topicItem.scrollIntoView();
}
const insertPageRight = (topicViewer: HTMLElement, topicItem: HTMLElement) => {
if (rightContainer === null) {
Expand All @@ -52,6 +52,12 @@ const insertPageRight = (topicViewer: HTMLElement, topicItem: HTMLElement) => {
topicItem.scrollIntoView();
}

const markLinkVisited = (url: string) => {
const current_url = window.location.href;
history.pushState(history.state, '', url);
history.pushState(history.state, '', current_url);
}

const viewTopic = (evt: MouseEvent) => {
if (evt.ctrlKey) {
return;
Expand All @@ -71,6 +77,7 @@ const viewTopic = (evt: MouseEvent) => {
topicItem.scrollIntoView();
return;
}
markLinkVisited(anchor.href);
document.querySelector('topic-viewer')?.remove();
const topicViewer = document.createElement('topic-viewer');
topicViewer.setAttribute('data-uri', anchor.href);
Expand Down

0 comments on commit 58cd620

Please sign in to comment.