Skip to content

Commit f32dd48

Browse files
authored
Merge pull request #978 from SashaXser/dev
Поддержка тачскрина
2 parents cda2705 + 5abad9e commit f32dd48

File tree

6 files changed

+215
-138
lines changed

6 files changed

+215
-138
lines changed

dist/vot-min.user.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vot.user.js

+89-69
Original file line numberDiff line numberDiff line change
@@ -6395,27 +6395,32 @@ async function getLanguage(player, response, title, description) {
63956395
!window.location.hostname.includes("m.youtube.com") &&
63966396
player?.getAudioTrack
63976397
) {
6398-
// ! Experimental ! get lang from selected audio track if availabled
6399-
const audioTracks = player.getAudioTrack();
6400-
const trackInfo = audioTracks?.getLanguageInfo(); // get selected track info (id === "und" if tracks are not available)
6398+
// Experimental: Get language from selected audio track if available
6399+
const trackInfo = player.getAudioTrack()?.getLanguageInfo(); // Get selected track info
64016400
if (trackInfo?.id !== "und") {
64026401
return normalizeLang(trackInfo.id.split(".")[0]);
64036402
}
6404-
}
64056403

6406-
// TODO: If the audio tracks will work fine, transfer the receipt of captions to the audioTracks variable
6407-
// Check if there is an automatic caption track in the response
6408-
const captionTracks =
6409-
response?.captions?.playerCaptionsTracklistRenderer?.captionTracks;
6410-
if (captionTracks?.length) {
6411-
const autoCaption = captionTracks.find((caption) => caption.kind === "asr");
6412-
if (autoCaption && autoCaption.languageCode) {
6404+
// Get available audio tracks
6405+
const audioTracks = player.getAvailableAudioTracks();
6406+
// Find automatic caption track in audio tracks
6407+
const autoCaption = audioTracks?.find(
6408+
track => track.kind === "asr" && track.languageCode
6409+
);
6410+
if (autoCaption) {
64136411
return normalizeLang(autoCaption.languageCode);
64146412
}
64156413
}
64166414

64176415
// If there is no caption track, use detect to get the language code from the description
6416+
const autoCaption = response?.captions?.playerCaptionsTracklistRenderer?.captionTracks?.find(
6417+
(caption) => caption.kind === "asr" && caption.languageCode
6418+
);
6419+
if (autoCaption) {
6420+
return normalizeLang(autoCaption.languageCode);
6421+
}
64186422

6423+
// Use the description text to detect the language if no captions are available
64196424
const text = cleanText(title, description);
64206425

64216426
debug.log(`Detecting language text: ${text}`);
@@ -6948,24 +6953,21 @@ class SubtitlesWidget {
69486953

69496954
bindEvents() {
69506955
const { signal } = this.abortController;
6951-
6952-
this.onMouseDownBound = (e) => this.onMouseDown(e);
6953-
this.onMouseUpBound = () => this.onMouseUp();
6954-
this.onMouseMoveBound = (e) => this.onMouseMove(e);
6956+
this.onPointerDownBound = (e) => this.onPointerDown(e);
6957+
this.onPointerUpBound = () => this.onPointerUp();
6958+
this.onPointerMoveBound = (e) => this.onPointerMove(e);
69556959
this.onTimeUpdateBound = this.debounce(() => this.update(), 100);
6956-
6957-
document.addEventListener("mousedown", this.onMouseDownBound, { signal });
6958-
document.addEventListener("mouseup", this.onMouseUpBound, { signal });
6959-
document.addEventListener("mousemove", this.onMouseMoveBound, { signal });
6960-
this.video?.addEventListener("timeupdate", this.onTimeUpdateBound, {
6961-
signal,
6962-
});
6963-
6960+
6961+
document.addEventListener("pointerdown", this.onPointerDownBound, { signal });
6962+
document.addEventListener("pointerup", this.onPointerUpBound, { signal });
6963+
document.addEventListener("pointermove", this.onPointerMoveBound, { signal });
6964+
6965+
this.video?.addEventListener("timeupdate", this.onTimeUpdateBound, { signal });
69646966
this.resizeObserver = new ResizeObserver(() => this.onResize());
69656967
this.resizeObserver.observe(this.container);
69666968
}
69676969

6968-
onMouseDown(e) {
6970+
onPointerDown(e) {
69696971
if (!this.subtitlesContainer.contains(e.target)) return;
69706972

69716973
const rect = this.subtitlesContainer.getBoundingClientRect();
@@ -6983,12 +6985,11 @@ class SubtitlesWidget {
69836985
},
69846986
};
69856987
}
6986-
6987-
onMouseUp() {
6988+
onPointerUp() {
69886989
this.dragging.active = false;
69896990
}
69906991

6991-
onMouseMove(e) {
6992+
onPointerMove(e) {
69926993
if (!this.dragging.active) return;
69936994

69946995
e.preventDefault();
@@ -10726,50 +10727,69 @@ class VideoHandler {
1072610727
this.votButton.translateButton.addEventListener("click", async () => {
1072710728
await this.handleTranslationBtnClick();
1072810729
});
10729-
10730-
this.votButton.pipButton.addEventListener("click", () => {
10731-
(async () => {
10732-
if (this.video !== document.pictureInPictureElement) {
10733-
await this.video.requestPictureInPicture();
10734-
} else {
10735-
await document.exitPictureInPicture();
10736-
}
10737-
})();
10730+
10731+
this.votButton.pipButton.addEventListener("click", async () => {
10732+
const isPiPActive = this.video === document.pictureInPictureElement;
10733+
await (isPiPActive ? document.exitPictureInPicture() : this.video.requestPictureInPicture());
1073810734
});
10739-
1074010735
this.votButton.menuButton.addEventListener("click", () => {
1074110736
this.votMenu.container.hidden = !this.votMenu.container.hidden;
1074210737
});
10743-
10744-
this.votButton.container.addEventListener("mousedown", () => {
10738+
10739+
// Position update logic
10740+
const updateButtonPosition = async (percentX) => {
10741+
const isBigContainer = this.container.clientWidth > 550;
10742+
const position = isBigContainer
10743+
? (percentX <= 44 ? "left" : percentX >= 66 ? "right" : "default")
10744+
: "default";
10745+
10746+
this.data.buttonPos = position;
10747+
this.votButton.container.dataset.direction = position === "default" ? "row" : "column";
10748+
this.votButton.container.dataset.position = position;
10749+
this.votMenu.container.dataset.position = position;
10750+
10751+
if (isBigContainer) {
10752+
await votStorage.set("buttonPos", position);
10753+
}
10754+
};
10755+
10756+
// Drag event handler
10757+
const handleDragMove = async (clientX, rect = this.container.getBoundingClientRect()) => {
10758+
if (!this.dragging) return;
10759+
10760+
const x = rect ? clientX - rect.left : clientX;
10761+
const percentX = (x / (rect ? rect.width : this.container.clientWidth)) * 100;
10762+
await updateButtonPosition(percentX);
10763+
};
10764+
10765+
// Mouse/pointer events
10766+
this.votButton.container.addEventListener("pointerdown", (e) => {
1074510767
this.dragging = true;
10768+
e.preventDefault();
1074610769
});
10747-
10748-
this.container.addEventListener("mouseup", () => {
10749-
this.dragging = false;
10750-
});
10751-
10752-
this.container.addEventListener("mousemove", async (e) => {
10753-
if (this.dragging) {
10754-
e.preventDefault();
10755-
10756-
const percentX = (e.clientX / this.container.clientWidth) * 100;
10757-
// const percentY = (e.clientY / this.video.clientHeight) * 100;
10758-
const isBigContainer = this.container.clientWidth > 550;
10759-
const isLeft = percentX <= 44;
10760-
const isRightSide = percentX >= 66 ? "right" : "default";
10761-
const side = isLeft ? "left" : isRightSide;
10762-
10763-
this.data.buttonPos = isBigContainer ? side : "default";
10764-
this.votButton.container.dataset.direction =
10765-
this.data.buttonPos === "default" ? "row" : "column";
10766-
this.votButton.container.dataset.position = this.data.buttonPos;
10767-
this.votMenu.container.dataset.position = this.data.buttonPos;
10768-
if (isBigContainer) {
10769-
await votStorage.set("buttonPos", this.data.buttonPos);
10770-
}
10771-
}
10770+
10771+
this.container.addEventListener("pointerup", () => this.dragging = false);
10772+
this.container.addEventListener("pointermove", (e) => {
10773+
e.preventDefault();
10774+
handleDragMove(e.clientX);
1077210775
});
10776+
10777+
// Touch events
10778+
this.votButton.container.addEventListener("touchstart", (e) => {
10779+
this.dragging = true;
10780+
e.preventDefault();
10781+
}, { passive: false });
10782+
10783+
this.container.addEventListener("touchend", () => this.dragging = false);
10784+
this.container.addEventListener("touchmove", (e) => {
10785+
e.preventDefault();
10786+
handleDragMove(e.touches[0].clientX, this.container.getBoundingClientRect());
10787+
}, { passive: false });
10788+
10789+
// Cancel events
10790+
for (const event of ["pointercancel", "touchcancel"]) {
10791+
document.addEventListener(event, () => this.dragging = false);
10792+
}
1077310793
}
1077410794

1077510795
// VOT Menu
@@ -11460,18 +11480,18 @@ class VideoHandler {
1146011480
if (eventContainer)
1146111481
addExtraEventListeners(
1146211482
eventContainer,
11463-
["mousemove", "mouseout"],
11483+
["pointermove", "pointerout"],
1146411484
this.resetTimer,
1146511485
);
1146611486

1146711487
addExtraEventListener(
1146811488
this.votButton.container,
11469-
"mousemove",
11489+
"pointermove",
1147011490
this.changeOpacityOnEvent,
1147111491
);
1147211492
addExtraEventListener(
1147311493
this.votMenu.container,
11474-
"mousemove",
11494+
"pointermove",
1147511495
this.changeOpacityOnEvent,
1147611496
);
1147711497
// remove listener on xvideos to fix #866
@@ -11484,10 +11504,10 @@ class VideoHandler {
1148411504
}
1148511505

1148611506
// fix youtube hold to fast
11487-
addExtraEventListener(this.votButton.container, "mousedown", (e) => {
11507+
addExtraEventListener(this.votButton.container, "pointerdown", (e) => {
1148811508
e.stopImmediatePropagation();
1148911509
});
11490-
addExtraEventListener(this.votMenu.container, "mousedown", (e) => {
11510+
addExtraEventListener(this.votMenu.container, "pointerdown", (e) => {
1149111511
e.stopImmediatePropagation();
1149211512
});
1149311513

scripts/wiki-gen/index.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,18 @@ function fixRegexStr(str) {
6262
brackets = brackets.map((bracket) => bracket[0]);
6363
const optionalBrackets = brackets.filter((bracket) => bracket.includes("?"));
6464
if (optionalBrackets.length) {
65-
getDomainFromRegex(domain, optionalBrackets).map((dom) => domains.add(dom));
65+
for (const dom of getDomainFromRegex(domain, optionalBrackets)) {
66+
domains.add(dom);
67+
}
6668
}
6769

6870
for (const bracket of brackets) {
6971
const parts = bracket.replace(/[?()]+/g, "").split("|");
7072
for (const part of parts) {
7173
let partedDomain = domain.replace(bracket, part);
72-
getDomainFromRegex(partedDomain, optionalBrackets).map((dom) =>
73-
domains.add(dom),
74-
);
74+
for (const dom of getDomainFromRegex(partedDomain, optionalBrackets)) {
75+
domains.add(dom);
76+
}
7577
}
7678
}
7779

@@ -107,7 +109,7 @@ function genMarkdown(supportedSites, lang = "ru") {
107109

108110
return removeDuplicatesKeepLast(sitesData, "host").map((site) => {
109111
const hasData = Object.hasOwn(siteData, site.host);
110-
const limitsData = hasData ? siteData[site.host].limits ?? [] : [];
112+
const limitsData = hasData ? (siteData[site.host].limits ?? []) : [];
111113
if (site.needBypassCSP && !limitsData.includes(locales.needBypassCSP)) {
112114
limitsData.push(locales.needBypassCSP);
113115
}

0 commit comments

Comments
 (0)