diff --git a/src/components/Hyperchat.svelte b/src/components/Hyperchat.svelte
index 253b70f..80d5901 100644
--- a/src/components/Hyperchat.svelte
+++ b/src/components/Hyperchat.svelte
@@ -65,7 +65,8 @@
ytDark,
confirmDialog,
initialSetupDone,
- defaultFilterPresetId
+ defaultFilterPresetId,
+ autoClear
} from '../ts/storage';
import { version } from '../manifest.json';
import { shouldFilterMessage, saveMessageActions, findSavedMessageActionKey, getSavedMessageDumpActions, getSavedMessageDumpInfo, getAutoActivatedPreset, downloadAsJson, downloadAsTxt, redirectIfInitialSetup, importJsonDump, mergeVideoInfoObjs } from '../ts/ytcf-logic';
@@ -677,7 +678,7 @@
};
let key = '';
const initMessageStorage = async () => {
- let tempKey = paramsArchiveKey || await findSavedMessageActionKey(paramsContinuation, $videoInfo, true);
+ let tempKey = paramsArchiveKey || await findSavedMessageActionKey(paramsContinuation, $videoInfo, $autoClear);
tempKey = tempKey === null ? getRandomString() : tempKey;
const newMsgs = await getSavedMessageDumpActions(tempKey);
if (newMsgs?.length) {
diff --git a/src/components/settings/YtcFilterGeneral.svelte b/src/components/settings/YtcFilterGeneral.svelte
index 0858e44..a2d0ea8 100644
--- a/src/components/settings/YtcFilterGeneral.svelte
+++ b/src/components/settings/YtcFilterGeneral.svelte
@@ -1,13 +1,15 @@
@@ -120,6 +146,40 @@
+
+
+
+
About
@@ -153,4 +213,7 @@
vertical-align: bottom;
margin: 0px 10px;
}
+ input[type=number]::-webkit-inner-spin-button {
+ opacity: 1;
+ }
diff --git a/src/ts/chat-constants.ts b/src/ts/chat-constants.ts
index f092d38..f6a5bdb 100644
--- a/src/ts/chat-constants.ts
+++ b/src/ts/chat-constants.ts
@@ -73,6 +73,13 @@ export enum ChatReportUserOptions {
MISINFORMATION = 'MISINFORMATION',
}
+export enum TimeUnit {
+ HOURS = 'HOURS',
+ DAYS = 'DAYS',
+ WEEKS = 'WEEKS',
+ MONTHS = 'MONTHS'
+}
+
export const chatReportUserOptions = [
{ value: ChatReportUserOptions.UNWANTED_SPAM, label: 'Unwanted commercial content or spam' },
{ value: ChatReportUserOptions.PORN_OR_SEX, label: 'Pornography or sexually explicit material' },
diff --git a/src/ts/storage.ts b/src/ts/storage.ts
index e8aafa9..6aae91a 100644
--- a/src/ts/storage.ts
+++ b/src/ts/storage.ts
@@ -3,7 +3,7 @@ import { derived, readable, writable } from 'svelte/store';
import type { Writable } from 'svelte/store';
import { getClient, AvailableLanguages } from 'iframe-translator';
import type { IframeTranslatorClient, AvailableLanguageCodes } from 'iframe-translator';
-import { ChatReportUserOptions, Theme, YoutubeEmojiRenderMode, isLiveTL } from './chat-constants';
+import { ChatReportUserOptions, Theme, TimeUnit, YoutubeEmojiRenderMode, isLiveTL } from './chat-constants';
const INITIAL_PRESET_ID = 'initial-preset-id'; // all other ids will be random
@@ -228,3 +228,8 @@ export const getPresetById = async (id: string): Promise => {
export const findSavedMessageActionKey = async (
continuation: string | null,
info: SimpleVideoInfo | null,
- clearOldItems = false
+ autoClearDurationObject: YtcF.AutoClearDurationObject
): Promise => {
// return await new Promise((resolve) => {
// chrome.storage.local.get(null, (s) => {
@@ -637,13 +637,21 @@ export const findSavedMessageActionKey = async (
// });
// });
const allInfoDumps = await getAllMessageDumpInfoItems();
+ let returnValue = null;
for (const dump of allInfoDumps) {
- if ((continuation != null && continuation && dump.continuation.includes(continuation)) ||
+ if (
+ autoClearDurationObject.enabled &&
+ dump.lastEdited < Date.now() - convertDurationObjectToMs(autoClearDurationObject)
+ ) {
+ await deleteSavedMessageActions(dump.key);
+ } else if ((continuation != null && continuation && dump.continuation.includes(continuation)) ||
(info?.video != null && dump.info?.video?.videoId === info.video.videoId && info.video.videoId)) {
- return dump.key;
+ // return dump.key;
+ returnValue = dump.key;
}
}
- return null;
+ // return null;
+ return returnValue;
};
export const getAllMessageDumpInfoItems = async (): Promise => {
diff --git a/src/ts/ytcf-utils.ts b/src/ts/ytcf-utils.ts
index 3d75b43..70cf950 100644
--- a/src/ts/ytcf-utils.ts
+++ b/src/ts/ytcf-utils.ts
@@ -1,3 +1,5 @@
+import { TimeUnit } from "./chat-constants";
+
export const stringifyRuns = (msg: Ytc.ParsedRun[], ignoreEmoji = false): string => {
return msg.map(m => {
if (m.type === 'text') {
@@ -17,3 +19,13 @@ export const download = (data: string, filename: string): void => {
a.click();
a.remove();
};
+
+export const convertDurationObjectToMs = (duration: YtcF.AutoClearDurationObject): number => {
+ let multiplier = 1;
+ if (!duration.enabled) multiplier = 0;
+ if (duration.unit === TimeUnit.MONTHS) multiplier = 30 * 24 * 60 * 60 * 1000;
+ if (duration.unit === TimeUnit.WEEKS) multiplier = 7 * 24 * 60 * 60 * 1000;
+ if (duration.unit === TimeUnit.DAYS) multiplier = 24 * 60 * 60 * 1000;
+ if (duration.unit === TimeUnit.HOURS) multiplier = 60 * 60 * 1000;
+ return duration.duration * multiplier;
+};