Greasy Fork is available in English.

Play video on hover

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

// ==UserScript==
// @name         Play video on hover
// @namespace    https://lukaszmical.pl/
// @version      0.3.2
// @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 r{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=r.ID,document.querySelector(`#${r.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"})}}r.ID="play-on-hover-popup",t.default=r},472:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){let i=!1,s=0;e.addEventListener("mouseenter",(r=>{i=!0,s=window.setTimeout((()=>{i&&t.call(e,r)}),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),[])}extractId(e,t){var i;const s=e.match(t);return s&&(null===(i=s.groups)||void 0===i?void 0:i.id)||""}}},665:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class r 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=r},802:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class r extends s.default{constructor(){super(...arguments),this.config={width:300,height:500}}async embeddedVideoUrl({href:e}){return`https://www.instagram.com/p/${this.extractId(e,/reel\/(?<id>[^/]+)\//)}/embed/`}videoLinks(){return this.getLinks('a[href*="instagram.com"]').filter((e=>e.href.includes("instagram.com/reel")))}}t.default=r},87:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class r extends s.default{constructor(){super(...arguments),this.config={width:500,height:300}}async embeddedVideoUrl({href:e}){return`https://streamable.com/o/${this.extractId(e,/\.com\/([s|o]\/)?(?<id>[^?/]+).*$/)}?autoplay=1`}videoLinks(){return this.getLinks('a[href*="streamable.com"]')}}t.default=r},764:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class r extends s.default{constructor(){super(...arguments),this.config={width:338,height:575}}async embeddedVideoUrl({href:e}){return`https://www.tiktok.com/embed/v2/${this.extractId(e,/video\/(?<id>\d+)/)}`}videoLinks(){return this.getLinks('a[href*="tiktok.com"]').filter((e=>{return t=e.href,/video\/\d+/.test(t);var t}))}}t.default=r},641:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class r extends s.default{constructor(){super(...arguments),this.config={width:500,height:500}}async embeddedVideoUrl({href:e}){return`https://platform.twitter.com/embed/Tweet.html?id=${this.extractId(e,/status\/(?<id>[^/]+)\//)}&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=r},706:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class r 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=r},453:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});const s=i(905);class r 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")||"",r=i.get("t")||"0";if(e.includes("//youtu.be/"))s=this.extractId(e,/\.be\/(?<id>[^?/]+).*$/);else if(e.includes("youtube.com/attribution_link")){const e=decodeURIComponent(i.get("u")||`/watch?v=${s}`),t=new URL(`https://youtube.com${e}`),o=new URLSearchParams(t.search);s=o.get("v")||s,r=o.get("t")||r}const[o="0",d="0",a]=r.match(/(?:(\d+)h)?(?:(\d+)m)?(\d+)s/)||["0","0","-1"];return r="-1"!==a?`${60*(60*Number(o)+Number(d))+a}`:"0",`https://www.youtube.com/embed/${s}?fs=1&autoplay=1&enablejsapi=1&start=${r}`}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=r}},t={};function i(s){var r=t[s];if(void 0!==r)return r.exports;var o=t[s]={exports:{}};return e[s](o,o.exports,i),o.exports}(()=>{const e=i(751),t=i(472),s=i(87),r=i(706),o=i(453),d=i(665),a=i(764),u=i(802),n=i(641),c=[o.default,r.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)}))}))}))}))})()})();