Guest User

kpop.re_thumbnail_files.user.js

a guest
Apr 24th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @version      0.1
  3. // @description  display thumbnails as if they were images
  4. // @match        *://kpop.re/*
  5. // ==/UserScript==
  6.  
  7. (function() {
  8.     function handlePost(p) {
  9.         let files = p.querySelector('.post-files');
  10.         if (!files) {
  11.             files = document.createElement('div');
  12.             files.className = 'post-files';
  13.             p.querySelector('.post-body').insertAdjacentElement('afterbegin', files);
  14.         }
  15.                
  16.         let embeds = p.querySelectorAll('.post-embed');
  17.         embeds.forEach(function(e) {
  18.             let thumbnail = e.getAttribute('data-thumbnail_url');
  19.             let link = e.getAttribute('href');
  20.  
  21.             let figure = document.createElement('figure');
  22.             figure.className = 'post-file';
  23.             let a = document.createElement('a');
  24.             a.className = 'post-file-link';
  25.             a.href = link;
  26.             figure.appendChild(a);
  27.             let img = document.createElement('img');
  28.             img.className = 'post-file-thumb';
  29.             img.src = thumbnail;
  30.             img.style.maxWidth = '200px';
  31.             img.style.maxHeight = '200px';
  32.             img.loading = 'lazy';
  33.             a.appendChild(img);
  34.             console.log('adding' + figure + thumbnail);
  35.  
  36.             p.querySelector('.post-files').insertAdjacentElement('beforeend', figure);
  37.         });
  38.     }
  39.  
  40.     function handleInitialPosts() {
  41.         console.log('initial posts:');
  42.         let posts = document.querySelectorAll('.post');
  43.         posts.forEach(function(p) { handlePost(p) });
  44.     }
  45.  
  46.     //document.addEventListener('DOMContentLoaded', handleInitialPosts); // this shit doesn't fucking work
  47.     setTimeout(() => handleInitialPosts(), 5000)
  48. })();
  49.  
Add Comment
Please, Sign In to add comment