-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,796 additions
and
4,677 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { EventTypes, SettingIds } from '../../../common/constants'; | ||
import dom from '../../../content/observers/dom'; | ||
import settings from '../../lib/settings'; | ||
import styles from './styles.module.css'; | ||
|
||
const CHAT_ROOM = 'ul'; // TODO: find better selector | ||
|
||
let mutationObserver: MutationObserver | null = null; | ||
|
||
class AlwaysPresent { | ||
constructor() { | ||
settings.on(`${SettingIds.ALWAYS_PRESENT}.${EventTypes.SETTING_UPDATE}`, () => { | ||
const nodes = document.querySelectorAll(CHAT_ROOM); | ||
for (const node of nodes) { | ||
const id = node.getAttribute('id'); | ||
if (!id?.startsWith('cv-')) { | ||
continue; | ||
} | ||
this.attachObserver(node); | ||
} | ||
}); | ||
dom.on(CHAT_ROOM, (node: HTMLElement) => { | ||
const id = node.getAttribute('id'); | ||
if (!id?.startsWith('cv-')) { | ||
return; | ||
} | ||
this.attachObserver(node); | ||
}); | ||
} | ||
|
||
attachObserver(node: HTMLElement) { | ||
const enabled = settings.getSetting(SettingIds.ALWAYS_PRESENT); | ||
node.classList.toggle(styles.alwaysVisible, true); | ||
|
||
if (mutationObserver != null) { | ||
mutationObserver.disconnect(); | ||
mutationObserver = null; | ||
} | ||
|
||
if (!enabled) { | ||
return; | ||
} | ||
|
||
mutationObserver = new MutationObserver((mutations) => { | ||
for (const mutation of mutations) { | ||
if (mutation.attributeName !== 'aria-hidden') { | ||
continue; | ||
} | ||
const target = mutation.target as HTMLElement; | ||
const previousSibling = target.previousElementSibling as HTMLElement; | ||
if (previousSibling == null) { | ||
continue; | ||
} | ||
const shouldHide = target.getAttribute('aria-hidden') === 'true'; | ||
previousSibling.classList.toggle(styles.hideOverlay, shouldHide); | ||
} | ||
}); | ||
|
||
mutationObserver.observe(node, { attributeFilter: ['aria-hidden'], attributes: true }); | ||
} | ||
} | ||
|
||
export default new AlwaysPresent(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.alwaysVisible { | ||
visibility: unset !important; | ||
} | ||
.hideOverlay { | ||
display: none !important; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,47 @@ | ||
import './SaveButton'; | ||
import { EventTypes, SettingIds } from '../../../common/constants'; | ||
import settings from '../../lib/settings'; | ||
import dom from '../../../content/observers/dom'; | ||
import styles from './styles.module.css'; | ||
|
||
const MEDIA_CONTENT_SELECTOR = 'div[aria-label="media content"]'; | ||
|
||
function preventContextMenu(event: MouseEvent) { | ||
event.stopImmediatePropagation(); | ||
} | ||
|
||
class SaveImage { | ||
constructor() { | ||
this.load(); | ||
settings.on(`${SettingIds.SAVE_IMAGE}.${EventTypes.SETTING_UPDATE}`, this.load); | ||
dom.on(MEDIA_CONTENT_SELECTOR, (node: HTMLElement) => { | ||
this.patchMediaContent(node); | ||
}); | ||
} | ||
|
||
load() { | ||
const enabled = settings.getSetting(SettingIds.SAVE_IMAGE); | ||
|
||
if (enabled) { | ||
window.addEventListener('contextmenu', preventContextMenu, true); | ||
const mediaContent = document.querySelectorAll(MEDIA_CONTENT_SELECTOR); | ||
for (const node of mediaContent) { | ||
this.patchMediaContent(node as HTMLElement); | ||
} | ||
} | ||
|
||
if (!enabled) { | ||
window.removeEventListener('contextmenu', preventContextMenu, true); | ||
const mediaContent = document.querySelectorAll(MEDIA_CONTENT_SELECTOR); | ||
for (const node of mediaContent) { | ||
this.patchMediaContent(node as HTMLElement); | ||
} | ||
} | ||
} | ||
|
||
patchMediaContent(node: HTMLElement) { | ||
const enabled = settings.getSetting(SettingIds.SAVE_IMAGE); | ||
node.classList.toggle(styles.patchedMediaContent, enabled); | ||
} | ||
} | ||
|
||
export default new SaveImage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.patchedMediaContent { | ||
pointer-events: unset !important; | ||
filter: unset !important; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/content/modules/settings-menu/components/AlwaysPresent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Checkbox, Text } from '@nextui-org/react'; | ||
import React from 'react'; | ||
import { SettingIds } from '../../../../common/constants'; | ||
import useSettingState from '../../../common/hooks/useSettingState'; | ||
import styles from './Checkbox.module.css'; | ||
|
||
export default function AlwaysPresent() { | ||
const [value, setValue] = useSettingState(SettingIds.ALWAYS_PRESENT); | ||
|
||
return ( | ||
<Checkbox isSelected={value} onChange={(boolean) => setValue(boolean)}> | ||
<div className={styles.checkboxLabel}> | ||
<Text size={14} css={{ margin: 0 }}> | ||
Always Present | ||
</Text> | ||
<Text size={14} color="#999" css={{ margin: 0 }}> | ||
Prevent the chat from being hidden when you click away. | ||
</Text> | ||
</div> | ||
</Checkbox> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters