Skip to content

Commit

Permalink
Implement #83
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoNezd committed Jan 2, 2024
1 parent 236f634 commit e727dbd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Empty file.
36 changes: 36 additions & 0 deletions src/features/posts/indentCommentHide.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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()
}
})
}
}
}
3 changes: 2 additions & 1 deletion src/features/posts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -40,4 +41,4 @@ class PostsEnhance extends OLFeature {
setupPost(post)
}
}
export default [PostsEnhance, NativeShare]
export default [PostsEnhance, NativeShare, IndentCommentHide]

0 comments on commit e727dbd

Please sign in to comment.