Created
March 22, 2022 21:31
-
-
Save bviktor/b494cd88c96cf59222db0227d99fde9f to your computer and use it in GitHub Desktop.
Close IMDb image galleries by pressing the Escape button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name IMDb Close Gallery | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Close the fucking image overlay when pressing the Esc button | |
// @author Viktor Berke | |
// @match https://www.imdb.com/* | |
// @icon https://m.media-amazon.com/images/G/01/imdb/images-ANDW73HA/favicon_iPhone_retina_180x180._CB1582158069_.png | |
// @grant none | |
// ==/UserScript== | |
(function() | |
{ | |
'use strict'; | |
document.addEventListener('keydown', function(event) | |
{ | |
if(event.key === "Escape") | |
{ | |
// there should be only one element, so don't care about indexing | |
var closeButton = document.querySelectorAll('[data-testid="mv-breadcrumb-close-button"]')[0]; | |
var closeUrl = closeButton.getAttribute('href'); | |
// braindamage, if you don't add an arbitrary sleep, it only works after a random amount of keypresses | |
// https://stackoverflow.com/a/60040846/1708230 | |
setTimeout(function(){document.location.href = closeUrl;},10); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment