Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @version 0.1
- // @description display thumbnails as if they were images
- // @match *://kpop.re/*
- // ==/UserScript==
- (function() {
- function handlePost(p) {
- let files = p.querySelector('.post-files');
- if (!files) {
- files = document.createElement('div');
- files.className = 'post-files';
- p.querySelector('.post-body').insertAdjacentElement('afterbegin', files);
- }
- let embeds = p.querySelectorAll('.post-embed');
- embeds.forEach(function(e) {
- let thumbnail = e.getAttribute('data-thumbnail_url');
- let link = e.getAttribute('href');
- let figure = document.createElement('figure');
- figure.className = 'post-file';
- let a = document.createElement('a');
- a.className = 'post-file-link';
- a.href = link;
- figure.appendChild(a);
- let img = document.createElement('img');
- img.className = 'post-file-thumb';
- img.src = thumbnail;
- img.style.maxWidth = '200px';
- img.style.maxHeight = '200px';
- img.loading = 'lazy';
- a.appendChild(img);
- console.log('adding' + figure + thumbnail);
- p.querySelector('.post-files').insertAdjacentElement('beforeend', figure);
- });
- }
- function handleInitialPosts() {
- console.log('initial posts:');
- let posts = document.querySelectorAll('.post');
- posts.forEach(function(p) { handlePost(p) });
- }
- //document.addEventListener('DOMContentLoaded', handleInitialPosts); // this shit doesn't fucking work
- setTimeout(() => handleInitialPosts(), 5000)
- })();
Add Comment
Please, Sign In to add comment