Dearrow: Add option to not dearrow by default (#2818)
This commit is contained in:
parent
df8aec8e3c
commit
244cb26c32
1 changed files with 18 additions and 7 deletions
|
@ -46,7 +46,7 @@ const embedUrlRe = /https:\/\/www\.youtube\.com\/embed\/([a-zA-Z0-9_-]{11})/;
|
||||||
async function embedDidMount(this: Component<Props>) {
|
async function embedDidMount(this: Component<Props>) {
|
||||||
try {
|
try {
|
||||||
const { embed } = this.props;
|
const { embed } = this.props;
|
||||||
const { replaceElements } = settings.store;
|
const { replaceElements, dearrowByDefault } = settings.store;
|
||||||
|
|
||||||
if (!embed || embed.dearrow || embed.provider?.name !== "YouTube" || !embed.video?.url) return;
|
if (!embed || embed.dearrow || embed.provider?.name !== "YouTube" || !embed.video?.url) return;
|
||||||
|
|
||||||
|
@ -63,18 +63,22 @@ async function embedDidMount(this: Component<Props>) {
|
||||||
|
|
||||||
if (!hasTitle && !hasThumb) return;
|
if (!hasTitle && !hasThumb) return;
|
||||||
|
|
||||||
|
|
||||||
embed.dearrow = {
|
embed.dearrow = {
|
||||||
enabled: true
|
enabled: dearrowByDefault
|
||||||
};
|
};
|
||||||
|
|
||||||
if (hasTitle && replaceElements !== ReplaceElements.ReplaceThumbnailsOnly) {
|
if (hasTitle && replaceElements !== ReplaceElements.ReplaceThumbnailsOnly) {
|
||||||
embed.dearrow.oldTitle = embed.rawTitle;
|
const replacementTitle = titles[0].title.replace(/(^|\s)>(\S)/g, "$1$2");
|
||||||
embed.rawTitle = titles[0].title.replace(/(^|\s)>(\S)/g, "$1$2");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
embed.dearrow.oldTitle = dearrowByDefault ? embed.rawTitle : replacementTitle;
|
||||||
|
if (dearrowByDefault) embed.rawTitle = replacementTitle;
|
||||||
|
}
|
||||||
if (hasThumb && replaceElements !== ReplaceElements.ReplaceTitlesOnly) {
|
if (hasThumb && replaceElements !== ReplaceElements.ReplaceTitlesOnly) {
|
||||||
embed.dearrow.oldThumb = embed.thumbnail.proxyURL;
|
const replacementProxyURL = `https://dearrow-thumb.ajay.app/api/v1/getThumbnail?videoID=${videoId}&time=${thumbnails[0].timestamp}`;
|
||||||
embed.thumbnail.proxyURL = `https://dearrow-thumb.ajay.app/api/v1/getThumbnail?videoID=${videoId}&time=${thumbnails[0].timestamp}`;
|
|
||||||
|
embed.dearrow.oldThumb = dearrowByDefault ? embed.thumbnail.proxyURL : replacementProxyURL;
|
||||||
|
if (embed.thumbnail.proxyURL) embed.thumbnail.proxyURL = replacementProxyURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
|
@ -96,6 +100,7 @@ function DearrowButton({ component }: { component: Component<Props>; }) {
|
||||||
className={"vc-dearrow-toggle-" + (embed.dearrow.enabled ? "on" : "off")}
|
className={"vc-dearrow-toggle-" + (embed.dearrow.enabled ? "on" : "off")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const { enabled, oldThumb, oldTitle } = embed.dearrow;
|
const { enabled, oldThumb, oldTitle } = embed.dearrow;
|
||||||
|
settings.store.dearrowByDefault = !enabled;
|
||||||
embed.dearrow.enabled = !enabled;
|
embed.dearrow.enabled = !enabled;
|
||||||
if (oldTitle) {
|
if (oldTitle) {
|
||||||
embed.dearrow.oldTitle = embed.rawTitle;
|
embed.dearrow.oldTitle = embed.rawTitle;
|
||||||
|
@ -153,6 +158,12 @@ const settings = definePluginSettings({
|
||||||
{ label: "Titles", value: ReplaceElements.ReplaceTitlesOnly },
|
{ label: "Titles", value: ReplaceElements.ReplaceTitlesOnly },
|
||||||
{ label: "Thumbnails", value: ReplaceElements.ReplaceThumbnailsOnly },
|
{ label: "Thumbnails", value: ReplaceElements.ReplaceThumbnailsOnly },
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
dearrowByDefault: {
|
||||||
|
description: "Dearrow videos automatically",
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
default: true,
|
||||||
|
restartNeeded: false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue