Skip to content

Commit

Permalink
Merge pull request #523 from SashaXser/dev
Browse files Browse the repository at this point in the history
Поддержка Newgrounds.com и мелкие правки кода
  • Loading branch information
ilyhalight authored Feb 15, 2024
2 parents 05f71e7 + 777b50a commit 9da1583
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 168 deletions.
3 changes: 2 additions & 1 deletion dist/vot-cloudflare-min.user.js

Large diffs are not rendered by default.

102 changes: 41 additions & 61 deletions dist/vot-cloudflare.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
// @match *://youtube.googleapis.com/embed/*
// @match *://*.banned.video/*
// @match *://*.weverse.io/*
// @match *://*.newgrounds.com/*
// @connect api.browser.yandex.ru
// @downloadURL https://raw.githubusercontent.com/ilyhalight/voice-over-translation/dev/dist/vot-cloudflare.user.js
// @grant GM_xmlhttpRequest
Expand Down Expand Up @@ -1161,6 +1162,8 @@ const getVideoId = (service, video) => {
return url.searchParams.get("id");
case "weverse":
return url.pathname.match(/([^/]+)\/(live|media)\/([^/]+)/)?.[0];
case "newgrounds":
return url.pathname.match(/([^/]+)\/(view)\/([^/]+)/)?.[0];
default:
return false;
}
Expand Down Expand Up @@ -3136,25 +3139,22 @@ class SubtitlesWidget {

if (top && bottom) {
this.votSubtitlesContainer.style.top = `${y - this.containerRect.y}px`;
} else if (!top) {
this.votSubtitlesContainer.style.top = `${0}px`;
} else {
if (!top) {
this.votSubtitlesContainer.style.top = `${0}px`;
} else {
this.votSubtitlesContainer.style.top = `${
this.containerRect.height - this.subtitlesContainerRect.height
}px`;
}
this.votSubtitlesContainer.style.top = `${
this.containerRect.height - this.subtitlesContainerRect.height
}px`;
}

if (left && right) {
this.votSubtitlesContainer.style.left = `${x - this.containerRect.x}px`;
} else if (!left) {
this.votSubtitlesContainer.style.left = `${0}px`;
} else {
if (!left) {
this.votSubtitlesContainer.style.left = `${0}px`;
} else {
this.votSubtitlesContainer.style.left = `${
this.containerRect.width - this.subtitlesContainerRect.width
}px`;
}
this.votSubtitlesContainer.style.left = `${
this.containerRect.width - this.subtitlesContainerRect.width
}px`;
}
}
}
Expand Down Expand Up @@ -3244,22 +3244,20 @@ class SubtitlesWidget {
: ""
}>${token.text}</span>`;
}
} else {
if (line.text.length > this.maxLength) {
let chunks = line.text.match(this.maxLengthRegexp);
let chunkDurationMs = line.durationMs / chunks.length;
for (let i = 0; i < chunks.length; i++) {
if (
line.startMs + chunkDurationMs * i < time &&
time < line.startMs + chunkDurationMs * (i + 1)
) {
content = chunks[i].trim();
break;
}
} else if (line.text.length > this.maxLength) {
let chunks = line.text.match(this.maxLengthRegexp);
let chunkDurationMs = line.durationMs / chunks.length;
for (let i = 0; i < chunks.length; i++) {
if (
line.startMs + chunkDurationMs * i < time &&
time < line.startMs + chunkDurationMs * (i + 1)
) {
content = chunks[i].trim();
break;
}
} else {
content = line.text;
}
} else {
content = line.text;
}
}
if (content !== this.lastContent) {
Expand Down Expand Up @@ -3698,24 +3696,6 @@ async function createHash(pathname) {
};
}

// f = function (e, t, n) {
// let r = "?";
// -1 !== e.indexOf("?") && (r = "&");
// const i = (function (e, t) {
// let n = e.substring(0, Math.min(255, e.length));
// n += t;
// let r = u.createHmac("sha1", c.active).update(n).digest("base64");
// return (r = encodeURIComponent(r)), { wmsgpad: t, wmd: r };
// })(
// (e = ""
// .concat(e)
// .concat(r)
// .concat((0, l.stringify)({ ...t, wpf: (0, s.li)() ? "mweb" : "pc" }))),
// n,
// );
// return e + "&wmsgpad=" + i.wmsgpad + "&wmd=" + i.wmd;
// };

function getURLData() {
return {
appId: API_APP_ID,
Expand Down Expand Up @@ -4120,6 +4100,12 @@ const sites = () => {
match: /^weverse.io$/,
selector: ".webplayer-internal-source-wrapper",
},
{
host: "newgrounds",
url: "https://www.newgrounds.com/",
match: /^www.newgrounds.com$/,
selector: ".ng-video-player",
},
// Нужно куда-то заливать данные о плейлисте
// {
// host: "epicgames",
Expand Down Expand Up @@ -5022,13 +5008,12 @@ class VideoHandler {

try {
debug/* default */.Z.log("[click translationBtn] trying execute translation");
const VIDEO_ID = (0,utils/* getVideoId */.gJ)(this.site.host, this.video);

if (!VIDEO_ID) {
if (!this.videoData.videoId) {
throw new VOTLocalizedError("VOTNoVideoIDFound");
}

await this.translateExecutor(VIDEO_ID);
await this.translateExecutor(this.videoData.videoId);
} catch (err) {
console.error("[VOT]", err);
if (err?.name === "VOTLocalizedError") {
Expand Down Expand Up @@ -5502,15 +5487,13 @@ class VideoHandler {
return;
}

const VIDEO_ID = (0,utils/* getVideoId */.gJ)(this.site.host, this.video);

if (!VIDEO_ID) {
if (!this.videoData.videoId) {
throw new VOTLocalizedError("VOTNoVideoIDFound");
}

try {
this.firstPlay = false;
await this.translateExecutor(VIDEO_ID);
await this.translateExecutor(this.videoData.videoId);
} catch (err) {
console.error("[VOT]", err);
if (err?.name === "VOTLocalizedError") {
Expand Down Expand Up @@ -5598,9 +5581,7 @@ class VideoHandler {
async updateSubtitles() {
await this.changeSubtitlesLang("disabled");

const VIDEO_ID = (0,utils/* getVideoId */.gJ)(this.site.host, this.video);

if (!VIDEO_ID) {
if (!this.videoData.videoId) {
console.error(
`[VOT] ${localizationProvider/* localizationProvider */.V.getDefault("VOTNoVideoIDFound")}`,
);
Expand All @@ -5610,19 +5591,19 @@ class VideoHandler {
return;
}

if (this.subtitlesListVideoId === VIDEO_ID) {
if (this.subtitlesListVideoId === this.videoData.videoId) {
return;
}

this.subtitlesList = await subtitles_getSubtitles(
this.site,
VIDEO_ID,
this.videoData.videoId,
this.videoData.detectedLanguage,
);
if (!this.subtitlesList) {
await this.changeSubtitlesLang("disabled");
} else {
this.subtitlesListVideoId = VIDEO_ID;
this.subtitlesListVideoId = this.videoData.videoId;
}
await this.updateSubtitlesLangSelect();
}
Expand Down Expand Up @@ -5790,9 +5771,8 @@ class VideoHandler {
}
return videoData;
}

videoValidator() {
if (this.site.host === "youtube" || this.site.host === "ok.ru") {
if (["youtube", "ok.ru"].includes(this.site.host)) {
debug/* default */.Z.log("VideoValidator videoData: ", this.videoData);
if (
this.data.dontTranslateYourLang === 1 &&
Expand Down
3 changes: 2 additions & 1 deletion dist/vot-min.user.js

Large diffs are not rendered by default.

Loading

0 comments on commit 9da1583

Please sign in to comment.