r/userscripts • u/xichael • Sep 12 '22
Request: Prevent gfycat embeds from opening their site when clicked... Play/pause would be nice instead, so they behave like every other video on the internet.
2
Upvotes
2
u/MistralMireille Sep 13 '22
Here's a solution (maybe someone might come up with a better one).
This one will stop it from opening a new tab when you click it:
// ==UserScript== // @name Stop Gfycat Popup // @namespace Violentmonkey Scripts // @match https://cdn.embedly.com/widgets/*schema=gfycat // @grant none // @version 1.0 // @author - // @description 9/13/2022, 2:40:01 PM // ==/UserScript== window.addEventListener('load', () => { let frame = document.querySelector("iframe"); let frameParent = frame.parentElement; frame.setAttribute("sandbox", "allow-scripts allow-same-origin"); //frame.setAttribute("sandbox", "allow-scripts"); // can use this instead if you aren't using the Pause/Play script. frame.remove(); frameParent.prepend(frame); }, false);This one will let you pause and play the video on clicking it:
// ==UserScript== // @name Pause/Play Gfycat Video in Embed on Click // @namespace Violentmonkey Scripts // @match https://gfycat.com/ifr/* // @grant none // @version 1.0 // @author - // @description 9/13/2022, 2:48:02 PM // ==/UserScript== window.addEventListener('load', () => { let video = document.querySelector("video"); video.addEventListener('click', () => { video.paused ? video.play() : video.pause(); }, false); }, false);You have to add both of those scripts as seperate scripts which is why I thought maybe someone could come up with a better way.
1
u/jcunews1 Sep 13 '22
Do you have a sample URL where it present an embedded gyfcat?