From e727dbd95444f485c07d141588d6f5864f26a3c3 Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 2 Jan 2024 17:24:41 +0300 Subject: [PATCH] Implement #83 --- src/features/expandos/css/indent.css | 0 src/features/posts/indentCommentHide.ts | 36 +++++++++++++++++++++++++ src/features/posts/index.ts | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/features/expandos/css/indent.css create mode 100644 src/features/posts/indentCommentHide.ts diff --git a/src/features/expandos/css/indent.css b/src/features/expandos/css/indent.css new file mode 100644 index 0000000..e69de29 diff --git a/src/features/posts/indentCommentHide.ts b/src/features/posts/indentCommentHide.ts new file mode 100644 index 0000000..0ac67ed --- /dev/null +++ b/src/features/posts/indentCommentHide.ts @@ -0,0 +1,36 @@ +import { OLFeature } from "../base" + +// +function isMarginClick(element: HTMLElement, e: MouseEvent) { + var style = window.getComputedStyle(element, null); + var pTop = parseInt( style.getPropertyValue('margin-top') ); + var pRight = parseFloat( style.getPropertyValue('margin-right') ); + var pLeft = parseFloat( style.getPropertyValue('margin-left') ); + var pBottom = parseFloat( style.getPropertyValue('margin-bottom') ); + var width = element.offsetWidth; + var height = element.offsetHeight; + var x = e.offsetX; + var y = e.offsetY; + + return !(( x > pLeft && x < width - pRight) && + ( y > pTop && y < height - pBottom)) + } + +export default class IndentCommentHide extends OLFeature { + moduleId: string = "IndentCommentHide"; + moduleName: string = "Hide comments on tap on indent"; + async onPost(post: HTMLDivElement): Promise { + if (post.classList.contains("comment")) { + post.addEventListener("click", (e) => { + if (!(e.target as HTMLElement).classList.contains("sitetable")) { + return; + } + if (isMarginClick(post, e)) { + console.log("padding clicked!", post, e) + e.stopPropagation(); + (post.querySelector(".expand") as HTMLAnchorElement).click() + } + }) + } + } +} \ No newline at end of file diff --git a/src/features/posts/index.ts b/src/features/posts/index.ts index 96d28fb..7b0cb39 100644 --- a/src/features/posts/index.ts +++ b/src/features/posts/index.ts @@ -7,6 +7,7 @@ import setupNativeShare from "./nativeSharing"; import setupToggles from "./postToggles"; import { OLFeature } from "../base"; import NativeShare from "./nativeSharing"; +import IndentCommentHide from "./indentCommentHide"; function setupPost(post: HTMLDivElement) { const postContainer = setupPostContainer(post); @@ -40,4 +41,4 @@ class PostsEnhance extends OLFeature { setupPost(post) } } -export default [PostsEnhance, NativeShare] \ No newline at end of file +export default [PostsEnhance, NativeShare, IndentCommentHide] \ No newline at end of file