TimeBarAllActivities: Support new activity cards (#2813)
This commit is contained in:
parent
eb0d91fd8e
commit
00276cad7c
5
src/plugins/timeBarAllActivities/README.md
Normal file
5
src/plugins/timeBarAllActivities/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# TimeBarAllActivities
|
||||||
|
|
||||||
|
Adds the Spotify time bar to all activities if they have start and end timestamps.
|
||||||
|
|
||||||
|
![](https://github.com/user-attachments/assets/9fbbe33c-8218-43c9-8b8d-f907a4e809fe)
|
|
@ -1,35 +0,0 @@
|
||||||
/*
|
|
||||||
* Vencord, a modification for Discord's desktop app
|
|
||||||
* Copyright (c) 2022 Vendicated and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Devs } from "@utils/constants";
|
|
||||||
import definePlugin from "@utils/types";
|
|
||||||
|
|
||||||
export default definePlugin({
|
|
||||||
name: "TimeBarAllActivities",
|
|
||||||
description: "Adds the Spotify time bar to all activities if they have start and end timestamps",
|
|
||||||
authors: [Devs.fawn],
|
|
||||||
patches: [
|
|
||||||
{
|
|
||||||
find: "}renderTimeBar(",
|
|
||||||
replacement: {
|
|
||||||
match: /renderTimeBar\((.{1,3})\){.{0,50}?let/,
|
|
||||||
replace: "renderTimeBar($1){let"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
});
|
|
76
src/plugins/timeBarAllActivities/index.tsx
Normal file
76
src/plugins/timeBarAllActivities/index.tsx
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { definePluginSettings } from "@api/Settings";
|
||||||
|
import { Devs } from "@utils/constants";
|
||||||
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
|
import { findComponentByCodeLazy } from "@webpack";
|
||||||
|
|
||||||
|
interface Activity {
|
||||||
|
timestamps?: ActivityTimestamps;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ActivityTimestamps {
|
||||||
|
start?: string;
|
||||||
|
end?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ActivityTimeBar = findComponentByCodeLazy<ActivityTimestamps>(".Millis.HALF_SECOND", ".bar", ".progress");
|
||||||
|
|
||||||
|
export const settings = definePluginSettings({
|
||||||
|
hideActivityDetailText: {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
description: "Hide the large title text next to the activity",
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
hideActivityTimerBadges: {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
description: "Hide the timer badges next to the activity",
|
||||||
|
default: true,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default definePlugin({
|
||||||
|
name: "TimeBarAllActivities",
|
||||||
|
description: "Adds the Spotify time bar to all activities if they have start and end timestamps",
|
||||||
|
authors: [Devs.fawn, Devs.niko],
|
||||||
|
settings,
|
||||||
|
patches: [
|
||||||
|
{
|
||||||
|
find: ".Messages.USER_ACTIVITY_PLAYING",
|
||||||
|
replacement: [
|
||||||
|
// Insert Spotify time bar component
|
||||||
|
{
|
||||||
|
match: /\(0,.{0,30}activity:(\i),className:\i\.badges\}\)/g,
|
||||||
|
replace: "$&,$self.getTimeBar($1)"
|
||||||
|
},
|
||||||
|
// Hide the large title on listening activities, to make them look more like Spotify (also visible from hovering over the large icon)
|
||||||
|
{
|
||||||
|
match: /(\i).type===(\i\.\i)\.WATCHING/,
|
||||||
|
replace: "($self.settings.store.hideActivityDetailText&&$self.isActivityTimestamped($1)&&$1.type===$2.LISTENING)||$&"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
// Hide the "badge" timers that count the time since the activity starts
|
||||||
|
{
|
||||||
|
find: ".TvIcon).otherwise",
|
||||||
|
replacement: {
|
||||||
|
match: /null!==\(\i=null===\(\i=(\i)\.timestamps\).{0,50}created_at/,
|
||||||
|
replace: "($self.settings.store.hideActivityTimerBadges&&$self.isActivityTimestamped($1))?null:$&"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
isActivityTimestamped(activity: Activity) {
|
||||||
|
return activity.timestamps != null && activity.timestamps.start != null && activity.timestamps.end != null;
|
||||||
|
},
|
||||||
|
|
||||||
|
getTimeBar(activity: Activity) {
|
||||||
|
if (this.isActivityTimestamped(activity)) {
|
||||||
|
return <ActivityTimeBar start={activity.timestamps!.start} end={activity.timestamps!.end} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
|
@ -554,6 +554,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
||||||
name: "SerStars",
|
name: "SerStars",
|
||||||
id: 861631850681729045n,
|
id: 861631850681729045n,
|
||||||
},
|
},
|
||||||
|
niko: {
|
||||||
|
name: "niko",
|
||||||
|
id: 341377368075796483n,
|
||||||
|
},
|
||||||
} satisfies Record<string, Dev>);
|
} satisfies Record<string, Dev>);
|
||||||
|
|
||||||
// iife so #__PURE__ works correctly
|
// iife so #__PURE__ works correctly
|
||||||
|
|
Loading…
Reference in a new issue