Advertisement
Guest User

Untitled

a guest
May 21st, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Copy direct image link - Imgur
  3. // @namespace    https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
  4. // @version      1
  5. // @description  Click on the image to quickly copy the direct image url after uploading one or more images.
  6. // @author       hacker09
  7. // @match        https://imgur.com/a/*
  8. // @icon         https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://imgur.com/upload&size=64
  9. // @require      https://greasyfork.org/scripts/21927-arrive-js/code/arrivejs.js
  10. // @grant        window.close
  11. // @run-at       document-end
  12. // ==/UserScript==
  13.  
  14. (async function() {
  15.   'use strict';
  16.   var Imgs = []; //Creates a new array
  17.   /*  window.onload = setTimeout(() => { //After the window loads
  18.     document.querySelector("div.Gallery-ContentWrapper").onclick = async function(){ //When an image preview box is clicked
  19.       async function test(){
  20.         document.querySelector('.AppDialogs').scrollIntoView({ behavior: "smooth" }); //Scrolls down the website till the all imgs are loaded
  21.         document.arrive('img.image-placeholder[src*=".webp"]', (async function() { //Create a new async arrive function
  22.           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
  23.           console.log( Array.from(new Set(Imgs)).join('\n') )
  24.           navigator.clipboard.writeText( Array.from(new Set(Imgs)).join('\n') ); //Copy the image(s) direct link
  25.           //setTimeout(() => { document.querySelector('div.Info-Wrapper.hidden-post').scrollIntoView({ behavior: "smooth" }); }, 500); //Scrolls up the website till the all imgs are loaded
  26.           //setTimeout(() => { document.querySelector('.AppDialogs').scrollIntoView({ behavior: "smooth" }); }, 1500); //Scrolls down the website till the all imgs are loaded
  27.           //setTimeout(() => { document.querySelector('div.Info-Wrapper.hidden-post').scrollIntoView({ behavior: "smooth" }); }, 2500); //Scrolls up the website till the all imgs are loaded
  28.           //window.top.close(); //Closes the actual tab
  29.         })); //Finishes the async arrive function
  30.       }
  31.       test()
  32.     }; //Finishes the onclick event listener
  33.   }, 500); //Finishes the settimeout function */
  34.  
  35.  
  36.   window.onload = setTimeout(() => { //After the window loads
  37.     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
  38.  
  39.     document.body.onclick = function (body){
  40.       document.querySelectorAll('div.Gallery-Content--mediaContainer').forEach(el => setTimeout(() => { window.scrollTo(0, 500); }, 500) ); //Scrolls down the website till the all imgs are loaded
  41.     } //Scrolls the website till the all imgs are loaded
  42.  
  43.     new MutationObserver(async function() { //When the weather bar is scrolled
  44.       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
  45.  
  46.       var unique = Imgs.filter((element, index) => { return Imgs.indexOf(element) === index;});
  47.  
  48.       console.log( unique.join('\n') );
  49.       navigator.clipboard.writeText( unique.join('\n') ); //Copy the image(s) direct link
  50.  
  51.       window.onscroll = async function() {
  52.         var BodyoffsetHeight = document.querySelector('body').offsetHeight;
  53.         if (window.scrollY * 1.2 >= BodyoffsetHeight - window.innerHeight) {
  54.           setTimeout(() => { document.querySelector('div.Info-Wrapper.hidden-post').scrollIntoView({ behavior: "smooth" }); }, 500); //Scrolls up the website till the all imgs are loaded
  55.           setTimeout(() => { window.top.close(); }, 1000); //Closes the actual tab
  56.         }
  57.       }
  58.  
  59.     }).observe(document.querySelector("div.Gallery-ContentWrapper"), { //Defines the element and the characteristics to be observed
  60.       attributes: false,
  61.       attributeOldValue: false,
  62.       characterData: false,
  63.       characterDataOldValue: false,
  64.       childList: true,
  65.       subtree: true
  66.     }); //Finishes the definitions to be observed */
  67.   }, 700); //Finishes the settimeout function */
  68.  
  69.   /*    //window.scrollTo(0, document.body.scrollHeight); //Scrolls the website till the all imgs are loaded
  70.     document.querySelector("div.Gallery-ContentWrapper").onclick = async function(){ //When an image preview box is clicked
  71.       setTimeout(() => { //Starts the settimeout function
  72.         var Imgs = []; //Creates a new array
  73.         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
  74.         document.querySelectorAll("div.Gallery-Content--media > div > img").forEach(function(el) { el.src = '' }); //Save the img(s) link(s) to an array
  75.         console.log( Imgs.join('\n') )
  76.         navigator.clipboard.writeText( Imgs.join('\n') ); //Copy the image(s) direct link
  77.         //window.top.close(); //Closes the actual tab
  78.       }, 500); //Finishes the settimeout function
  79.     }; //Finishes the onclick event listener
  80.   }, 500); //Finishes the settimeout function */
  81.  
  82.   /*      if (document.querySelectorAll("div.Gallery-Content--mediaContainer").length === 1) //If the user uploaded only 1 image
  83.     { //Starts the if condition
  84.       document.querySelector("div.Gallery-ContentWrapper").onclick = async function(){ //When the image preview box is clicked
  85.         setTimeout(() => { //Starts the settimeout function
  86.           navigator.clipboard.writeText(document.querySelector("div.ImageViewerContent > img").src); //Copy the image direct link
  87.           window.top.close(); //Closes the actual tab
  88.         }, 0); //Finishes the settimeout function
  89.       }; //Finishes the onclick event listener
  90.     } //Finishes the if condition
  91.     else
  92.     { //Starts the else condition
  93.       document.querySelector("div.Gallery-ContentWrapper").onclick = async function(){ //When the image preview box is clicked
  94.         setTimeout(() => { //Starts the settimeout function
  95.           var Imgs = []; //Creates a new array
  96.           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
  97.           console.log( Imgs.join('\n') )
  98.           navigator.clipboard.writeText( Imgs.join('\n') ); //Copy the image(s) direct link
  99.           //window.top.close(); //Closes the actual tab
  100.         }, 500); //Finishes the settimeout function
  101.       }; //Finishes the onclick event listener
  102.  
  103.             var Title = document.title; //Saves the default tab title
  104.       document.querySelectorAll("div.Gallery-Content--mediaContainer").forEach(async function(el){ //Starts the foreach loop
  105.         el.onclick = async function(){ //When the image preview box is clicked
  106.  
  107.            setTimeout(() => { //Starts the settimeout function
  108.             alert(document.querySelector("div.ImageViewerContent > img").src.split('?')[0])
  109.             navigator.clipboard.writeText(document.querySelector("div.ImageViewerContent > img").src); //Copy the image direct link
  110.             document.title = 'Copied!!!'; //Shows a message
  111.             setTimeout(() => { document.title = Title; }, 1500); //Finishes the settimeout function
  112.           }, 0); //Finishes the settimeout function
  113.         }; //Finishes the onclick event listener
  114.       }) //Finishes the foreach loop
  115.     } //Finishes the else condition
  116.   }, 500); //Finishes the settimeout function  */
  117. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement