// ==UserScript== // @name 学外语视频外挂悬浮可点复制翻译字幕,Learn-foreign-language-video-floating-plug-in-for-clickable-copying-subtitle // @description 显示按钮:电脑鼠标移动或者移动端触摸屏幕, 视频内鼠标滑轮滚动视频快进, 电脑建议配合欧路词典划词翻译, iphone 建议使用快捷指令获取剪贴板翻译, 安卓手机建议使用屏幕取词软件 // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js // @require https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js // @include * // @match *://*/* // @namespace http://tampermonkey.net/ // @version 2023.12.19.12.09.49 // @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org // @author You // @downloadURL none // ==/UserScript== (()=>{"use strict";const P=e=>{console.log("%c"+e,` background-color: #811f21; color: white; line-height:1.5rem; padding:0 0.5rem; `)};function z(e){!function(e){if(document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement||document.msFullscreenElement){if(e===document.fullscreenElement||e===document.mozFullScreenElement||e===document.webkitFullscreenElement||e===document.msFullscreenElement)return console.log("元素处于全屏状态"),1;console.log("元素不处于全屏状态")}else console.log("不处于全屏状态")}(e)?(P("全屏视频"),e.requestFullscreen?e.requestFullscreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen&&e.msRequestFullscreen(),void 0!==window.ActiveXObject&&null!=(e=new ActiveXObject("WScript.Shell"))&&e.SendKeys("{F11}")):(P("退出全屏视频"),document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.msExitFullscreen&&document.msExitFullscreen())}let E=0;const q=(e=[],t=0,o=0,s=0,n=e?.length,l=Math?.floor((s+n)/2),i=1e3)=>{if(console.log("二分查找递归:",t,s,n,l),i=t:P("二分查找 :找到字幕了");var a=item?.text?.split(/\s+/)?.map((e=>`${e} `)).join("");a=(clickable_subtitle_wapper.html(`

${a}

`),$(".clickable_subtitle_middle"));a.on("mousedown","span",copyWord),a.on("touchstart","span",copyWord),a.on("mouseenter","span",copyWord),a.on("mouseleave","span",(function(e){isMovesONword=!1,$(this).css({"background-color":"#fff0","border-radius":"1vw"})}));break;case i?.startTimet&&i?.startTime>t:P("二分查找 :字幕在后"),q(e,t,++E,l+1,n)}};window.addEventListener("load",(function(){P("视频外挂西悬浮可点复制翻译字幕-floating-plug-in-for-clickable-subtitle-copying"),$("iframe").each((function(){$(this).attr("allowfullscreen","true")}));const t=$("video");let e=!1;t.on("mouseenter",(()=>{e=!0})),t.on("mouseleave",(()=>{e=!1})),t.on("wheel",(function(e){console.log("event :",e),P("视频滚动"),e.stopPropagation(),e.deltaY<0?(console.log("向上滚动"),t.currentTime-=5):(console.log("向下滚动"),t.currentTime+=5)}));var o=t.parent(),s=(o=(o.addClass("videoWrapper"),o.css({position:"relative"}),t.append(""),t.attr("controls","true"),t.attr("playsInline","true"),$("")),o.on("click",(function(e){e.stopPropagation(),P("全屏开关点击"),z(document.querySelector(".videoWrapper"))})),{"z-index":"2147483647",color:"#fff",position:"absolute",transition:"all 0.2s ease-in-out"}),n={margin:"1vw",display:"block",padding:"0.5vw","border-radius":".5vw","background-color":"#1118","font-size":"1.5vw",cursor:"pointer","user-select":"text","line-height":"2.5rem !important",color:"#fffb",transition:"all 0.2s ease-in-out"},l=(o.css({...n}),$(""));let a=!0;l.css({...n});const r=$("
");r.on("wheel",(function(e){console.log("event :",e),P("视频滚动"),e.stopPropagation(),e.deltaY<0?(console.log("向上滚动"),t.currentTime-=5):(console.log("向下滚动"),t.currentTime+=5)})),l.on("click",(function(e){e.stopPropagation(),P("字幕显示开关点击"),a=!a,r.css({display:a?"block":"none"})})),r.click((function(e){P("字幕外层点击"),e.stopPropagation()})),r.on("mousedown",(e=>{e.stopPropagation(),console.log(" :",[t]),t?.[0].pause(),P("视频暂停")})),r.on("touchstart",(e=>{e.stopPropagation(),console.log(" :",[t]),t?.[0].pause(),P("视频暂停")})),r.on("mouseup",(e=>{e.stopPropagation(),window?.getSelection()?.toString()?(console.log(" :",[t]),t?.[0].pause(),P("视频暂停")):(console.log(" :",[t]),_||(t?.[0].play(),P("视频播放")))})),r.on("touchend",(e=>{e.stopPropagation(),window?.getSelection()?.toString()?(console.log(" :",[t]),t?.[0].pause(),P("视频暂停")):(console.log(" :",[t]),t?.[0].play(),P("视频播放"))})),r.css({...s,border:"2px solid #aaa8",transform:"translateX(-50%)",display:"block","user-select":"text",width:"80vw",bottom:"0",left:"50%",padding:"3vw 3vw 10vh 3vw","background-color":"#1b2129ee","font-size":" 3vw","text-align":" center",mask:"linear-gradient(180deg, black 0%, rgba(0, 0, 0, 1) 80%,rgba(0, 0, 0, 0.0) 95%)","border-radius":"3vw 3vw 0 0","box-shadow":"inset 0 0 2vw #666"});var c=$(' '),p=(c=(t.prepend(c),c.on("loadeddata",(e=>{e.stopPropagation(),P("轨道数据缓存"),console.log("数据 :",e)})),$(`
`)),c.css({"font-size":" 2vw","background-color":"#0004","order-radius":" 2vw !important",padding:"1vw 4vw",display:"flex","justify-content":"space-between","align-items":"center"}),$(` 字幕文件转格式: (.srt->.vtt)网站 (.srt->.txt)网站1 (.srt->.txt)网站2 `));p.css({"line-height":"5vw"}),c.css({"font-size":"2vw","line-height":"5vw"}),c.on("change",(e=>{e.stopPropagation();e=e.target.files[0];console.log("file :",e),e&&(document.querySelector(".videoTrack").src=URL.createObjectURL(e),console.log("视频元素 :",[t]))}));let u=0,d=-1,m=-1,w=!1;function b(e){P($(this).text()+"被点击了"),$(this).css({"background-color":"#fff3","border-radius":"1vw"}),console.log("单词元素 :",[this]);var t=document?.createRange();t?.selectNode(this),window?.getSelection()?.addRange(t);const o=e?.target?.textContent.match(/\b[\w]+\b/);navigator?.clipboard?.writeText(o)?.then((()=>{P("复制成功 "+o)}))?.catch((()=>{P("复制失败 "+o)}))}t.on("timeupdate",(e=>{e.stopPropagation();e=e?.target;var t=e?.currentTime+u,o=e?.textTracks[0]?.cues;if(e?.textTracks[0]?.cues?.length&&d!==parseInt(e?.currentTime))if(isDevelopment)q(e?.textTracks[0]?.cues,t,++E);else if(m!==i){q(e?.textTracks[0]?.cues,t,++E);for(let e=0;e=t){m!==e&&(s=s?.text?.split(/\s+/)?.map((e=>`${e} `)).join(""),r.html(`

${s}

`),(s=$(".clickable_subtitle_middle")).on("mousedown","span",b),s.on("touchstart","span",b),s.on("mouseenter","span",b),s.on("mouseleave","span",(function(e){w=!1,$(this).css({"background-color":"#fff0","border-radius":"1vw"})})),m=e);break}}}d=parseInt(e?.currentTime)}));var g=$("找字幕文件网1 "),f=$("找字幕文件网2 "),v=$("找字幕文件网3 "),h=(g.css({color:"#fff"}),f.css({color:"#fff"}),v.css({color:"#fff"}),$("
")),k=(h.css({"line-height":"6vw !important"}),$("
"));k.css({display:"flex","justify-content":"space-between","align-items":"center","font-size":"2vw","order-radius":"2vw !important",padding:"1vw 4vw","background-color":"#0004","line-height":"5vw"}),k.append(g),k.append(f),k.append(v),h.append(c),h.append(p),h.append(k),r.prepend(h);let _=!1;r.on("mouseenter",(function(e){e.stopPropagation(),_=!0,console.log("鼠标移入了外框!"),t?.[0].pause(),P("视频暂停")})),r.on("mouseleave",(function(e){e.stopPropagation(),_=!1,console.log("鼠标移出了外框!"),r.css({height:"auto"}),$(".clickable_subtitle_middle").css({"margin-top":"0"}),t?.[0].play(),P("视频播放")}));g=$(".videoWrapper");g.css({"font-size":"2vw",padding:"0 1rem !important"});const y=$('
');let x=!1,T=void(y.on("mouseenter",(function(){console.log("鼠标移入了按钮!"),x=!0})),y.on("mouseleave",(function(){console.log("鼠标移出了按钮!"),x=!1})),y.css({...s,top:"50%",right:"0",color:"#fff",transform:"translateY(-50%)"}),t.on("touchstart",(e=>{e.stopPropagation(),y.css({opacity:"1",transition:"all 0.2s ease-in-out"})})),t.on("touchend",(e=>{e.stopPropagation(),this.setTimeout((()=>{y.css({opacity:"0.1",transition:"all 0.2s ease-in-out"})}),1e3)})));$(document).on("mousemove",(function(e){e.stopPropagation(),T=!1,clearTimeout($.data(this,"timer")),y.css({opacity:"1",transition:"all 0.2s ease-in-out"}),x||$.data(this,"timer",setTimeout((()=>{x=!1,y.css({opacity:"0.1",transition:"all 0.2s ease-in-out"})}),1e3))}));f=$("");f.css({...n});const F=$("
0秒
"),S=(F.css({...n}),()=>{F.text(u+"秒")});f.on("click",(e=>{e.stopPropagation(),u++,S()}));v=$("");v.css({...n}),v.on("click",(e=>{e.stopPropagation(),u--,S()})),$("
").css({display:"flex","justify-content":"space-between","align-items":"center"}),y.append(o),y.append(l),y.append($("
  
")),y.append(v),y.append(F),y.append(f),g.append(y),g.append(r),$("*").css("user-select","text")}),!1)})();