import React from 'react'; import { useState } from 'react'; const vote = async (item, dislike = false) => { if (!dislike) //liked { if (item.vliked) return item.vlikes = item.vlikes ? item.vlikes + 1 : 1; item.vdislikes = item.vdislikes ? item.vdislikes - 1 : 0; if (item.vlikes < 0) item.vlikes = 0; if (item.vdislikes < 0) item.vdislikes = 0; item.vliked = true; item.vdisliked = false; } else { if (item.vdisliked) return item.vlikes = item.vlikes ? item.vlikes - 1 : 0; item.vdislikes = item.vdislikes ? item.vdislikes + 1 : 1; if (item.vlikes < 0) item.vlikes = 0; if (item.vdislikes < 0) item.vdislikes = 0 item.vliked = false; item.vdisliked = true; } fetch("/api/explore/videovote", { method: "POST", body: JSON.stringify({ like: !dislike, dislike: dislike, expid: item.expid, }) }).then(async r => { let json = await r.json(); if (json.code == 0) { } }) } export default (props) => { var region = lang.region || "en-US" var vid = props.vid var containerwidth = 0; var dragtopercent = 0; var mousedown = false; var [item, setItem] = useState(props.item) props.item.vlikes = item.vlikes; props.item.vdislikes = item.vdislikes; props.item.vliked = item.vliked; props.item.vdisliked = item.vdisliked; var frameimage = global.cdn("/files/youtube1.svg") var playbytext = lang.playbyyoutube if (props.videoobj?.iframe?.includes("aparat")) { frameimage = global.cdn("/files/aparat.svg") playbytext = lang.playbyaparat } var seekedtimer = 0; var applyseek = () => { let vel = document.getElementById(props.vid) as HTMLVideoElement if (vel && !isNaN(seekedtimer) && isFinite(seekedtimer)) vel.currentTime = seekedtimer } var ontimerseek = (p) => { if (isNaN(p)) { return; } let vel = document.getElementById(props.vid) as HTMLVideoElement if (!vel) return seekedtimer = Math.floor(p * vel.duration / 100); var h = Math.floor(seekedtimer / 3600).toString().padStart(2, "0"); var m = Math.floor(seekedtimer % 3600 / 60).toString().padStart(2, "0");; var s = Math.floor(seekedtimer % 3600 % 60).toString().padStart(2, "0");; document.getElementById(props.subtid + "_timer").innerHTML = h + ":" + m + ":" + s } return <> {props.screen == "iframe" ? null : <>
00:00:00
{ containerwidth = parseInt(window.getComputedStyle(document.getElementById(props.subtid + "_container")).width.replace("px","")) document.getElementById(props.subtid + "_track").style.opacity = "1" }} onMouseLeave={() => { document.getElementById(props.subtid + "_track").style.opacity = "0.4" }} onTouchStart={(e) => { props.onstoptimer?.() containerwidth = parseInt(window.getComputedStyle(document.getElementById(props.subtid + "_container")).width.replace("px", "")) document.getElementById(props.subtid + "_track").style.opacity = "1" var bcr = e.currentTarget.getBoundingClientRect(); var x = e.targetTouches[0].clientX - bcr.x; mousedown = true document.getElementById(props.subtid + "_bar").style.width = x + "px" document.getElementById(props.subtid + "_voice").style.zIndex = "-1" dragtopercent = (x * 100 / containerwidth); if (isNaN(dragtopercent)) { props.onresumetimer?.() } else { ontimerseek?.(dragtopercent) } }} onMouseDown={(e) => { props.onstoptimer?.() containerwidth = parseInt(window.getComputedStyle(document.getElementById(props.subtid + "_container")).width.replace("px", "")) mousedown = true document.getElementById(props.subtid + "_bar").style.width = e.nativeEvent.offsetX + "px" document.getElementById(props.subtid + "_voice").style.zIndex = "-1" dragtopercent = (e.nativeEvent.offsetX * 100 / containerwidth); if (isNaN(dragtopercent)) { props.onresumetimer?.() } else { ontimerseek?.(dragtopercent) } }} onMouseUp={() => { props.onresumetimer?.() mousedown = false document.getElementById(props.subtid + "_voice").style.zIndex = null applyseek?.(); }} onTouchEnd={() => { setTimeout(() => { props.onresumetimer?.() document.getElementById(props.subtid + "_track").style.opacity = "0.4" }, 2000) mousedown = false document.getElementById(props.subtid + "_voice").style.zIndex = null; applyseek?.(); }} onMouseMove={(e) => { if (mousedown) { document.getElementById(props.subtid + "_bar").style.width = e.nativeEvent.offsetX + "px" dragtopercent = (e.nativeEvent.offsetX * 100 / containerwidth); ontimerseek?.(dragtopercent) } }} onTouchMove={(e) => { var bcr = e.currentTarget.getBoundingClientRect(); var x = e.targetTouches[0].clientX - bcr.x; if (mousedown) { document.getElementById(props.subtid + "_bar").style.width = x + "px" dragtopercent = (x * 100 / containerwidth); ontimerseek?.(dragtopercent) } }} >
{ var video = document.getElementById(vid) as HTMLVideoElement if (!video) return var muteimg = document.getElementById(props.item.expid + "_mute") as HTMLImageElement if (video.muted) { props.onunmute?.() muteimg.src = global.cdn("/files/unmute.svg") video.muted = false } else { muteimg.src = global.cdn("/files/mute.svg") video.muted = true } }}> } {/* props.changemode?.()} /> {!props.novote ? { if (!global.user.loggedin) { props.loginrequired?.() return } props.onvlike?.() e.target.className = styles.nopale document.getElementById(item.expid + "_vlr").className = null; vote(item) setItem(JSON.parse(JSON.stringify(item))) props.onrefresh?.(); }} /> {(item.vlikes || 0).toLocaleString(lang.region)} { if (!global.user.loggedin) { props.loginrequired?.() return } props.onvdislike?.() e.target.className = styles.nopaler document.getElementById(item.expid + "_vlg").className = null; vote(item, true) setItem(JSON.parse(JSON.stringify(item))) props.onrefresh?.(); }} /> {(item.vdislikes || 0).toLocaleString(lang.region)} : null}
{props.screen == "iframe" ? null : <>
AUTO
{ let video = document.getElementById(vid); video?.requestFullscreen?.() props.onfullscreen?.() }}>
} {props.screen == "iframe" ? <> {lang.orglink} : null}
*/} }