Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Copy direct image link - Imgur
- // @namespace https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
- // @version 1
- // @description Click on the image to quickly copy the direct image url after uploading one or more images.
- // @author hacker09
- // @match https://imgur.com/a/*
- // @icon https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://imgur.com/upload&size=64
- // @require https://greasyfork.org/scripts/21927-arrive-js/code/arrivejs.js
- // @grant window.close
- // @run-at document-end
- // ==/UserScript==
- (async function() {
- 'use strict';
- var Imgs = []; //Creates a new array
- /* window.onload = setTimeout(() => { //After the window loads
- document.querySelector("div.Gallery-ContentWrapper").onclick = async function(){ //When an image preview box is clicked
- async function test(){
- document.querySelector('.AppDialogs').scrollIntoView({ behavior: "smooth" }); //Scrolls down the website till the all imgs are loaded
- document.arrive('img.image-placeholder[src*=".webp"]', (async function() { //Create a new async arrive function
- document.querySelectorAll('img.image-placeholder[src*=".webp"]').forEach(el => Imgs.push(el.src.split('?')[0].split('_d')[0] + el.src.split('?')[0].split('_d')[1])); //Save the img(s) link(s) to an array
- console.log( Array.from(new Set(Imgs)).join('\n') )
- navigator.clipboard.writeText( Array.from(new Set(Imgs)).join('\n') ); //Copy the image(s) direct link
- //setTimeout(() => { document.querySelector('div.Info-Wrapper.hidden-post').scrollIntoView({ behavior: "smooth" }); }, 500); //Scrolls up the website till the all imgs are loaded
- //setTimeout(() => { document.querySelector('.AppDialogs').scrollIntoView({ behavior: "smooth" }); }, 1500); //Scrolls down the website till the all imgs are loaded
- //setTimeout(() => { document.querySelector('div.Info-Wrapper.hidden-post').scrollIntoView({ behavior: "smooth" }); }, 2500); //Scrolls up the website till the all imgs are loaded
- //window.top.close(); //Closes the actual tab
- })); //Finishes the async arrive function
- }
- test()
- }; //Finishes the onclick event listener
- }, 500); //Finishes the settimeout function */
- window.onload = setTimeout(() => { //After the window loads
- document.querySelectorAll('img.image-placeholder[src*=".png"],img.image-placeholder[src*=".jpg"],img.image-placeholder[src*=".jepg"],img.image-placeholder[src*=".gif"]').forEach(el => Imgs.push( el.src.split('?')[0].split('_d')[0] + el.src.split('?')[0].split('_d')[1]) ); //Save the img(s) link(s) to an array
- document.body.onclick = function (body){
- document.querySelectorAll('div.Gallery-Content--mediaContainer').forEach(el => setTimeout(() => { window.scrollTo(0, 500); }, 500) ); //Scrolls down the website till the all imgs are loaded
- } //Scrolls the website till the all imgs are loaded
- new MutationObserver(async function() { //When the weather bar is scrolled
- document.querySelectorAll('img.image-placeholder[src*=".png"],img.image-placeholder[src*=".jpg"],img.image-placeholder[src*=".jepg"],img.image-placeholder[src*=".gif"]').forEach(el => Imgs.push( el.src.split('?')[0].split('_d')[0] + el.src.split('?')[0].split('_d')[1]) ); //Save the img(s) link(s) to an array
- var unique = Imgs.filter((element, index) => { return Imgs.indexOf(element) === index;});
- console.log( unique.join('\n') );
- navigator.clipboard.writeText( unique.join('\n') ); //Copy the image(s) direct link
- window.onscroll = async function() {
- var BodyoffsetHeight = document.querySelector('body').offsetHeight;
- if (window.scrollY * 1.2 >= BodyoffsetHeight - window.innerHeight) {
- setTimeout(() => { document.querySelector('div.Info-Wrapper.hidden-post').scrollIntoView({ behavior: "smooth" }); }, 500); //Scrolls up the website till the all imgs are loaded
- setTimeout(() => { window.top.close(); }, 1000); //Closes the actual tab
- }
- }
- }).observe(document.querySelector("div.Gallery-ContentWrapper"), { //Defines the element and the characteristics to be observed
- attributes: false,
- attributeOldValue: false,
- characterData: false,
- characterDataOldValue: false,
- childList: true,
- subtree: true
- }); //Finishes the definitions to be observed */
- }, 700); //Finishes the settimeout function */
- /* //window.scrollTo(0, document.body.scrollHeight); //Scrolls the website till the all imgs are loaded
- document.querySelector("div.Gallery-ContentWrapper").onclick = async function(){ //When an image preview box is clicked
- setTimeout(() => { //Starts the settimeout function
- var Imgs = []; //Creates a new array
- document.querySelectorAll("div.Gallery-Content--media > div > img").forEach(el => Imgs.push(el.src.split('?')[0])); //Save the img(s) link(s) to an array
- document.querySelectorAll("div.Gallery-Content--media > div > img").forEach(function(el) { el.src = '' }); //Save the img(s) link(s) to an array
- console.log( Imgs.join('\n') )
- navigator.clipboard.writeText( Imgs.join('\n') ); //Copy the image(s) direct link
- //window.top.close(); //Closes the actual tab
- }, 500); //Finishes the settimeout function
- }; //Finishes the onclick event listener
- }, 500); //Finishes the settimeout function */
- /* if (document.querySelectorAll("div.Gallery-Content--mediaContainer").length === 1) //If the user uploaded only 1 image
- { //Starts the if condition
- document.querySelector("div.Gallery-ContentWrapper").onclick = async function(){ //When the image preview box is clicked
- setTimeout(() => { //Starts the settimeout function
- navigator.clipboard.writeText(document.querySelector("div.ImageViewerContent > img").src); //Copy the image direct link
- window.top.close(); //Closes the actual tab
- }, 0); //Finishes the settimeout function
- }; //Finishes the onclick event listener
- } //Finishes the if condition
- else
- { //Starts the else condition
- document.querySelector("div.Gallery-ContentWrapper").onclick = async function(){ //When the image preview box is clicked
- setTimeout(() => { //Starts the settimeout function
- var Imgs = []; //Creates a new array
- document.querySelectorAll("div.Gallery-Content--media > div > img").forEach(el => Imgs.push(el.src.split('?')[0])); //Save the img(s) link(s) to an array
- console.log( Imgs.join('\n') )
- navigator.clipboard.writeText( Imgs.join('\n') ); //Copy the image(s) direct link
- //window.top.close(); //Closes the actual tab
- }, 500); //Finishes the settimeout function
- }; //Finishes the onclick event listener
- var Title = document.title; //Saves the default tab title
- document.querySelectorAll("div.Gallery-Content--mediaContainer").forEach(async function(el){ //Starts the foreach loop
- el.onclick = async function(){ //When the image preview box is clicked
- setTimeout(() => { //Starts the settimeout function
- alert(document.querySelector("div.ImageViewerContent > img").src.split('?')[0])
- navigator.clipboard.writeText(document.querySelector("div.ImageViewerContent > img").src); //Copy the image direct link
- document.title = 'Copied!!!'; //Shows a message
- setTimeout(() => { document.title = Title; }, 1500); //Finishes the settimeout function
- }, 0); //Finishes the settimeout function
- }; //Finishes the onclick event listener
- }) //Finishes the foreach loop
- } //Finishes the else condition
- }, 500); //Finishes the settimeout function */
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement