Play video on hover

Facebook, Vimeo, Youtube, Streamable, Tiktok, Instagram , Twitter - play on hover

目前为 2023-12-06 提交的版本。查看 最新版本

// ==UserScript==
// @name         Play video on hover
// @namespace    https://lukaszmical.pl/
// @version      0.3.0
// @description  Facebook, Vimeo, Youtube, Streamable, Tiktok, Instagram , Twitter - play on hover
// @author       Łukasz Micał
// @match        *://*/*
// @exclude      https://vimeo.com/*
// @exclude      https://player.vimeo.com/*
// @exclude      https://youtube.com/*
// @exclude      https://youtu.be/*
// @exclude      https://streamable.com/*
// @exclude      https://facebbok.com/*
// @exclude      https://twitter.com/*
// @exclude      https://instagram.com/*
// @exclude      https://tiktok.com/*
// @icon         https://static-00.iconduck.com/assets.00/cursor-hover-icon-512x439-vou7bdac.png
// ==/UserScript==
(()=>{"use strict";var e={751:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(326);class o{constructor(){this.iframeActive=!1,this.iframe=document.createElement("iframe"),this.popup=document.createElement("div"),this.setupIframe(),this.setupPopup(),this.setupEvent()}setupIframe(){this.iframe.allowFullscreen=!0,this.iframe.allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share",(0,s.default)(this.iframe,{height:"100%",width:"100%"}),this.popup.appendChild(this.iframe)}setupPopup(){(0,s.default)(this.popup,{background:"#444",height:"300px",width:"500px",position:"absolute",display:"none","z-index":9999,"box-shadow":"rgb(218, 218, 218) 1px 1px 5px"}),this.popup.id=o.ID,document.querySelector(`#${o.ID}`)||document.body.appendChild(this.popup)}setupEvent(){document.addEventListener("click",this.hidePopup.bind(this))}showPopup(e,t,i){this.iframeActive||(this.iframeActive=!0,(0,s.default)(this.popup,{display:"block",top:`${e.pageY}px`,left:`${e.pageX}px`,width:`${i.config.width}px`,height:`${i.config.height}px`}),this.iframe.src=t)}hidePopup(){this.iframeActive=!1,this.iframe.src="",(0,s.default)(this.popup,{display:"none"})}}o.ID="play-on-hover-popup",t.default=o},472:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){let i=!1,s=0;e.addEventListener("mouseenter",(o=>{i=!0,s=window.setTimeout((()=>{i&&t.call(e,o)}),1e3)})),e.addEventListener("mouseleave",(()=>{clearTimeout(s),i=!1}))}},326:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){Object.entries(t).forEach((([t,i])=>{e.style.setProperty(t,`${i}`)}))}},905:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.default=class{isHTMLAnchorElement(e){return e instanceof HTMLAnchorElement}getLinks(e){return[...document.querySelectorAll(e)].reduce(((e,t)=>this.isHTMLAnchorElement(t)?[...e,t]:e),[])}}},665:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class o extends s.default{constructor(){super(...arguments),this.config={width:500,height:282}}async embeddedVideoUrl(e){return`https://www.facebook.com/plugins/video.php?autoplay=true&width=500&show_text=false&height=300&appId&href=${e.href}`}videoLinks(){return this.getLinks('a[href*="facebook.com"]').filter((e=>{return t=e.href,/https:\/\/www\.facebook\.com\/[\w\d\-_]+\/videos\//.test(t);var t}))}}t.default=o},802:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class o extends s.default{constructor(){super(...arguments),this.config={width:300,height:500}}async embeddedVideoUrl({href:e}){const{groups:{id:t}}=e.match(/reel\/(?<id>[^\/]+)\//);return`https://www.instagram.com/p/${t}/embed/`}videoLinks(){return this.getLinks('a[href*="instagram.com"]').filter((e=>e.href.includes("instagram.com/reel")))}}t.default=o},87:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class o extends s.default{constructor(){super(...arguments),this.config={width:500,height:300}}async embeddedVideoUrl({href:e}){const{groups:{id:t}}=e.match(/\.com\/([s|o]\/)?(?<id>[^?\/]+).*$/);return`https://streamable.com/o/${t}?autoplay=1`}videoLinks(){return this.getLinks('a[href*="streamable.com"]')}}t.default=o},764:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class o extends s.default{constructor(){super(...arguments),this.config={width:338,height:575}}async embeddedVideoUrl({href:e}){const{groups:{id:t}}=e.match(/video\/(?<id>\d+)/);return`https://www.tiktok.com/embed/v2/${t}`}videoLinks(){return this.getLinks('a[href*="tiktok.com"]').filter((e=>{return t=e.href,/video\/\d+/.test(t);var t}))}}t.default=o},641:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class o extends s.default{constructor(){super(...arguments),this.config={width:500,height:500}}async embeddedVideoUrl({href:e}){const{groups:{id:t}}=e.match(/status\/(?<id>[^\/]+)\//);return`https://platform.twitter.com/embed/Tweet.html?id=${t}&maxWidth=500px`}videoLinks(){return this.getLinks('a[href*="twitter.com"]').filter((e=>{return t=e.href,/https:\/\/twitter\.com\/.+\/status\/\d+/.test(t);var t}))}}t.default=o},706:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class o extends s.default{constructor(){super(...arguments),this.config={width:500,height:300}}async embeddedVideoUrl(e){let t="";if(/\/\d+(\/.*)?$/.test(e.pathname))t=e.pathname.replace(/\D+/g,"");else{const i=await fetch(`https://vimeo.com/api/oembed.json?url=${e.href}`);t=(await i.json()).video_id}return`https://player.vimeo.com/video/${t}?autoplay=1`}videoLinks(){return this.getLinks('a[href*="vimeo.com"]')}}t.default=o},453:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class o extends s.default{constructor(){super(...arguments),this.config={width:500,height:300}}async embeddedVideoUrl({href:e,search:t}){const i=new URLSearchParams(t);let s=i.get("v")||"",o=i.get("t")||"0";if(e.includes("//youtu.be/")){const t=e.match(/\.be\/(?<id>[^?/]+).*$/),{groups:{id:i}={id:s}}=t||{groups:{id:s}};s=i}else if(e.includes("youtube.com/attribution_link")){const e=decodeURIComponent(i.get("u")||`/watch?v=${s}`),t=new URL(`https://youtube.com${e}`),r=new URLSearchParams(t.search);s=r.get("v")||s,o=r.get("t")||o}const[r="0",d="0",a]=o.match(/(?:(\d+)h)?(?:(\d+)m)?(\d+)s/)||["0","0","-1"];return o="-1"!==a?`${60*(60*Number(r)+Number(d))+a}`:"0",`https://www.youtube.com/embed/${s}?fs=1&autoplay=1&enablejsapi=1&start=${o}`}videoLinks(){return[...this.getLinks('a[href*="youtube.com"]'),...this.getLinks('a[href*="youtu.be"]')].filter((e=>{return(t=e.href).includes("youtube.com/attribution_link")||t.includes("youtube.com/watch")||t.includes("//youtu.be/");var t}))}}t.default=o}},t={};function i(s){var o=t[s];if(void 0!==o)return o.exports;var r=t[s]={exports:{}};return e[s](r,r.exports,i),r.exports}(()=>{const e=i(751),t=i(472),s=i(87),o=i(706),r=i(453),d=i(665),a=i(764),u=i(802),n=i(641),c=[r.default,o.default,s.default,d.default,a.default,u.default,n.default].map((e=>new e)),h=new e.default;c.map((e=>{e.videoLinks().map((i=>{(0,t.default)(i,(t=>{e.embeddedVideoUrl(i).then((i=>{h.showPopup(t,i,e)}))}))}))}))})()})();