// ==UserScript== // @name 视频外挂悬浮可点复制翻译字幕,floating-plug-in-for-clickable-subtitle-copying // @description 视频外挂悬浮可点复制翻译字幕,floating plug-in for clickable subtitle copying // @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.18.14.36.47 // @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org // @author You // @downloadURL none // ==/UserScript== (()=>{"use strict";const y=e=>{console.log("%c"+e,"background-color: #811f21; color: white;line-height:1.5rem; padding:0 0.5rem;")};function x(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)?(y("全屏视频"),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}")):(y("退出全屏视频"),document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.msExitFullscreen&&document.msExitFullscreen())}window.addEventListener("load",(function(){y("视频外挂西悬浮可点复制翻译字幕-floating-plug-in-for-clickable-subtitle-copying"),$("iframe").each((function(){$(this).attr("allowfullscreen","true")}));const t=$("video");var e=t.parent(),o=(e=(e.addClass("videoWrapper"),e.css({position:"relative"}),t.append(""),t.attr("controls","true"),t.attr("playsInline","true"),$("")),e.on("click",(function(e){e.stopPropagation(),y("全屏开关点击"),x(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"},s=(e.css({...n}),$(""));let l=!0;s.css({...n});const i=$("
");s.on("click",(function(e){e.stopPropagation(),y("字幕显示开关点击"),l=!l,i.css({display:l?"block":"none"})})),i.click((function(e){y("字幕外层点击"),e.stopPropagation()})),i.on("mousedown",(e=>{e.stopPropagation(),console.log(" :",[t]),t?.[0].pause(),y("视频暂停")})),i.on("touchstart",(e=>{e.stopPropagation(),console.log(" :",[t]),t?.[0].pause(),y("视频暂停")})),i.on("mouseup",(e=>{e.stopPropagation(),window?.getSelection()?.toString()?(console.log(" :",[t]),t?.[0].pause(),y("视频暂停")):(console.log(" :",[t]),f||(t?.[0].play(),y("视频播放")))})),i.on("touchend",(e=>{e.stopPropagation(),window?.getSelection()?.toString()?(console.log(" :",[t]),t?.[0].pause(),y("视频暂停")):(console.log(" :",[t]),t?.[0].play(),y("视频播放"))})),i.css({...o,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","line-height":"4rem !important","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 a=$(' '),c=(a=(t.prepend(a),a.on("loadeddata",(e=>{e.stopPropagation(),y("轨道数据缓存"),console.log("数据 :",e)})),$("
")),a.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)网站"));a.css({"font-size":"2vw"}),a.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]),document.querySelector("video").textTracks[0].oncuechange=e=>{console.log(" :",e?.currentTarget?.activeCues[0]?.text);e=e?.currentTarget?.activeCues[0]?.text?.split(/\s+/)?.map((e=>`${e} `)).join(""),i.html(`

${e}

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