Last active
June 16, 2023 14:18
-
-
Save Meridiano/99315935e1ac4ec40d5af0ebc9ad6cf1 to your computer and use it in GitHub Desktop.
Redirects Imgur pages to images or videos.
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 Imgur Redirector | |
// @version 1.1 | |
// @description Redirects Imgur pages to images or videos. | |
// @author Meridiano | |
// @match https://imgur.com/* | |
// @icon https://imgur.com/favicon.ico | |
// @license MIT License | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js | |
// ==/UserScript== | |
'use strict'; | |
// enable for console logs // =================== | |
const debugEnabled = false; | |
// ============================================== | |
var timerVariable = ''; | |
const myImage = '.PostContent-imageWrapper-rounded > [src]'; | |
const myVideo = '.PostContent-imageWrapper-rounded > .PostVideo > .PostVideo-video-wrapper > video'; | |
const igImage = '.Gallery-Content--media > .imageContainer > .image-placeholder'; | |
const igVideo = '.Gallery-Content--media > .PostVideo > .PostVideo-video-wrapper > video'; | |
Process(); | |
function Process() { | |
var imgurURL = new URL(document.URL); | |
Logger('imgurURL = ' + imgurURL); | |
if (typeof imgurURL !== 'object') { | |
return; | |
} | |
var splitPath = imgurURL.pathname.split('/'); | |
var splitLength = splitPath.length; | |
Logger('splitPath = [' + splitPath + '] / splitLength = ' + splitLength); | |
if (splitLength === 2 && splitPath[0] == '' && splitPath[1] !== '') { | |
timerVariable = setInterval(function() { Waiter(splitPath[1]); }, 500); | |
} | |
} | |
function Waiter(imgurID) | |
{ | |
var fileExtension = ''; | |
if ($(myImage).length + $(igImage).length > 0) { | |
fileExtension = '.png'; | |
} else if ($(myVideo).length + $(igVideo).length > 0) { | |
fileExtension = ".mp4"; | |
} | |
if (fileExtension) { | |
clearInterval(timerVariable); | |
timerVariable = ''; | |
window.stop(); | |
var newURL = 'https://i.imgur.com/' + imgurID + fileExtension; | |
Logger('newURL = ' + newURL); | |
window.location.replace(newURL); | |
} else { | |
Logger('Waiting for content load'); | |
} | |
} | |
function Logger(info) { | |
debugEnabled && console.log('[Imgur Redirector] ' + info); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment