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

toggle membership gifting #98

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
18 changes: 18 additions & 0 deletions src/components/AlertDialog.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts">
import {
alertDialog
} from '../ts/storage';
import Dialog from './common/Dialog.svelte';
import Button from 'smelte/src/components/Button';
</script>
<Dialog active={Boolean($alertDialog)} noCloseButton class="z-50">
<svelte:fragment slot="title">{$alertDialog?.title}</svelte:fragment>
<div>
{$alertDialog?.message}
</div>
<div slot="actions">
<Button on:click={() => {
$alertDialog = null;
}} color="primary">OK</Button>
</div>
</Dialog>
21 changes: 21 additions & 0 deletions src/components/GiftedMembershipToggle.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script lang="ts">
import { port } from '../ts/storage';
import { toggleMembershipGifting } from '../ts/chat-actions';
import { mdiCogOutline } from '@mdi/js';
import {
isYtFrame
} from '../ts/chat-constants';
</script>

{#if isYtFrame}
<div
on:click={() => {
toggleMembershipGifting($port);
}}
style="transform: translateX(3.5px);"
class="rounded-full flex justify-center items-center cursor-pointer w-8 h-8">
<svg viewBox="0 0 24 24" style="height: 20px;">
<path d={mdiCogOutline} fill="white" />
</svg>
</div>
{/if}
11 changes: 11 additions & 0 deletions src/components/Hyperchat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import PaidMessage from './PaidMessage.svelte';
import MembershipItem from './MembershipItem.svelte';
import ReportBanDialog from './ReportBanDialog.svelte';
import AlertDialog from './AlertDialog.svelte';
import SuperchatViewDialog from './SuperchatViewDialog.svelte';
import StickyBar from './StickyBar.svelte';
import {
Expand Down Expand Up @@ -235,6 +236,15 @@
);
}
break;
case 'toggleMembershipGiftingResponse':
if (!response.success) {
$alertDialog = {
title: 'Error',
message: "Please try again from YouTube's membership settings interface.",
color: 'error'
};
}
break;
case 'registerClientResponse':
break;
default:
Expand Down Expand Up @@ -341,6 +351,7 @@

<ReportBanDialog />
<SuperchatViewDialog />
<AlertDialog />

<svelte:window on:resize={() => {
scrollToBottom();
Expand Down
16 changes: 10 additions & 6 deletions src/components/MembershipItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import MessageRun from './MessageRuns.svelte';
import { showProfileIcons } from '../ts/storage';
import { membershipBackground, milestoneChatBackground } from '../ts/chat-constants';
import GiftedMembershipToggle from './GiftedMembershipToggle.svelte';

export let message: Ytc.ParsedMessage;

Expand All @@ -21,7 +22,7 @@
{#if membership || membershipGift}
<div class={classes} style="background-color: #{membershipBackground};">
<div
class="p-2"
class="p-2 relative"
style="{isMilestoneChat ? `background-color: #${milestoneChatBackground};` : ''}"
>
{#if $showProfileIcons}
Expand All @@ -44,11 +45,14 @@
<MessageRun runs={membership.headerSubtext} />
{/if}
{#if membershipGift}
<img
class="h-10 w-10 float-right"
src={membershipGift.image.src}
alt={membershipGift.image.alt}
title={membershipGift.image.alt} />
<div class="float-right inline-flex flex-row items-center">
<img
class="h-10 w-10"
src={membershipGift.image.src}
alt={membershipGift.image.alt}
title={membershipGift.image.alt} />
<GiftedMembershipToggle />
</div>
{/if}
</div>
{#if isMilestoneChat}
Expand Down
15 changes: 1 addition & 14 deletions src/components/ReportBanDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
chatReportUserOptions
} from '../ts/chat-constants';
import {
reportDialog,
alertDialog
reportDialog
} from '../ts/storage';
import Dialog from './common/Dialog.svelte';
import type { Writable } from 'svelte/store';
Expand All @@ -30,15 +29,3 @@
}} color="error" disabled={!$optionStore}>Report</Button>
</div>
</Dialog>

<Dialog active={Boolean($alertDialog)} noCloseButton>
<svelte:fragment slot="title">{$alertDialog?.title}</svelte:fragment>
<div>
{$alertDialog?.message}
</div>
<div slot="actions">
<Button on:click={() => {
$alertDialog = null;
}} color="primary">OK</Button>
</div>
</Dialog>
17 changes: 3 additions & 14 deletions src/components/SuperchatViewDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
focusedSuperchat
} from '../ts/storage';
import Dialog from './common/Dialog.svelte';
import TransparentDialog from './common/TransparentDialog.svelte';
import PaidMessage from './PaidMessage.svelte';
import MembershipItem from './MembershipItem.svelte';

Expand All @@ -14,21 +14,10 @@
$: if (!open) closeDialog();
</script>

<Dialog bind:active={open} noCloseButton class="no-padding">
<TransparentDialog bind:open>
{#if ('superChat' in sc || 'superSticker' in sc)}
<PaidMessage message={sc} />
{:else}
<MembershipItem message={sc} />
{/if}
</Dialog>

<style>
:global(.no-padding>div):nth-child(1), :global(.no-padding>div):nth-child(3) {
display: none;
}
:global(.no-padding) {
padding: 0px !important;
margin: 1rem !important;
background-color: transparent !important;
}
</style>
</TransparentDialog>
19 changes: 19 additions & 0 deletions src/components/common/TransparentDialog.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script lang="ts">
import Dialog from './Dialog.svelte';
export let open = false;
</script>

<Dialog bind:active={open} noCloseButton class="no-padding">
<slot />
</Dialog>

<style>
:global(.no-padding>div):nth-child(1), :global(.no-padding>div):nth-child(3) {
display: none;
}
:global(.no-padding) {
padding: 0px !important;
margin: 1rem !important;
background-color: transparent !important;
}
</style>
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "HyperChat by LiveTL",
"homepage_url": "https://livetl.app/en/hyperchat/",
"description": "YouTube chat, but it's fast and sleek!",
"version": "2.6.3",
"version": "2.6.4",
"permissions": [
"storage"
],
Expand Down
26 changes: 26 additions & 0 deletions src/scripts/chat-background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,26 @@ const sendChatUserActionResponse = (
);
};

const toggleMembershipGifting = (
port: Chat.Port,
message: Chat.toggleMembershipGiftingMsg
): void => {
const interceptor = findInterceptorFromClient(port);
interceptor?.port?.postMessage(message);
};

const sendMembershipGiftingResponse = (
port: Chat.Port,
message: Chat.toggleMembershipGiftingResponse
): void => {
const interceptor = findInterceptorFromPort(port, { message });
if (!interceptor) return;

interceptor.clients.forEach(
(clientPort) => clientPort.postMessage(message)
);
};

chrome.runtime.onConnect.addListener((port) => {
port.onMessage.addListener((message: Chat.BackgroundMessage) => {
switch (message.type) {
Expand Down Expand Up @@ -415,6 +435,12 @@ chrome.runtime.onConnect.addListener((port) => {
case 'chatUserActionResponse':
sendChatUserActionResponse(port, message);
break;
case 'toggleMembershipGifting':
toggleMembershipGifting(port, message);
break;
case 'toggleMembershipGiftingResponse':
sendMembershipGiftingResponse(port, message);
break;
default:
console.error('Unknown message type', port, message);
break;
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/chat-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ const chatLoaded = async (): Promise<void> => {
const params = new URLSearchParams();
params.set('tabid', frameInfo.tabId.toString());
params.set('frameid', frameInfo.frameId.toString());
try {
params.set('isYtFrame', window.parent.location.href !== window.location.href ? '1' : '0');
} catch {
}
if (frameIsReplay) params.set('isReplay', 'true');
const source = chrome.runtime.getURL(
(isLiveTL ? 'hyperchat/index.html' : 'hyperchat.html') +
Expand Down
Loading