SHARE
TWEET

Ig

RyukiChan May 31st, 2020 (edited) 1,231 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Code By Webdevtrick ( https://webdevtrick.com )
  3. const _ = e => document.querySelector(e);
  4. const render = _('.result');
  5.  
  6.  
  7. // create video
  8. const createVideo = data => {
  9.   let v = document.createElement('video');
  10.   v.id = "instavideo";
  11.   v.src = data.content;
  12.   v.controls = true;
  13.   v.autoplay = true;
  14.  
  15.   // create info
  16.   let info = document.createElement('p');
  17.   info.textContent = "Click the right button on video and select save as.";
  18.  
  19.   render.innerHTML = "";
  20.   render.appendChild(v);
  21.   render.appendChild(info);
  22. };
  23. // create image
  24. const createImg = data => {
  25.   // create image
  26.   let i = document.createElement('img');
  27.   i.id = "instaImg";
  28.   i.src = data.content;
  29.  
  30.   // create info
  31.   let info = document.createElement('p');
  32.   info.textContent = "Click the right button on the image and select save image..";
  33.  
  34.   render.innerHTML = "";
  35.   render.appendChild(i);    
  36.   render.appendChild(info);
  37.  
  38. };
  39.  
  40. // extract html
  41. const getMedia = () => {
  42.   render.innerHTML = "<div class='image-placeholder'></div>";
  43.   // get input value
  44.   let url = _('input').value;
  45.   if (url) {
  46.     fetch(url).
  47.     then(r => r.text()).
  48.     then(r => {
  49.       // render html
  50.       render.innerHTML = r;
  51.       // wait, find meta and create video or image
  52.       let w = setTimeout(() => {
  53.         let v = _('meta[property="og:video"]');
  54.         if (v) {
  55.           createVideo(v);
  56.         } else {
  57.           let img = _('meta[property="og:image"]');
  58.           if (img) {
  59.             createImg(img);
  60.           } else {
  61.             document.body.innerHTML = body;
  62.             alert('Error extracting Instagram image / video.');
  63.           };
  64.         }
  65.         clearTimeout(w);
  66.       }, 200);
  67.     });
  68.   } else {
  69.     _('input').setAttribute('placeholder', 'Invalid address, use a proper Insagram link');
  70.  
  71.   }
  72. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top