Anonymous ID: cc9e6e Sept. 4, 2021, 7:14 p.m. No.14522617   🗄️.is 🔗kun   >>2701

>>14522593

Options - user JS

Add script below, then save. Don't click gifs.

 

(function($) {

"use strict";

/**

  • Text Utils

*/

class TextUtil {};

TextUtil.IMG_SELECTOR = 'img';

TextUtil.LINK_SELECTOR = 'a';

TextUtil.NEW_POST_EVENT = 'new_post';

TextUtil.POST_REPLY_SELECTOR = 'div.post.reply';

TextUtil.POST_FILE_SELECTOR = 'div.file';

TextUtil.MEDIA_SERVER = 'media.8kun.top'

TextUtil.SYS_SERVER = 'sys.8kun.top'

/**

  • Wrapper for 8kun active_page variable to determine the type of

  • page the user is on.

*/

class ActivePage {

/**

  • Are we on a thread page?

  • @return {boolean} True if on thread

*/

static isThread() {

return window.active_page == ActivePage.Thread;

}

}

ActivePage.Thread = 'thread';

class FixImages {

/**

  • Construct an object to fix images

*/

constructor(addPostEvents = []) {

this._setupListeners();

this._fixExistingPosts();

}

/**

  • Sets up listeners to run on certain events

*

  • Runs fixPost on new post events

*/

_setupListeners() {

$(document).on(TextUtil.NEW_POST_EVENT, function(e, post) {

this._fixPost(post);

}.bind(this));

}

_fixPost(post) {

let pFiles = post.querySelectorAll(TextUtil.POST_FILE_SELECTOR);

pFiles.forEach(f ={

let links = f.querySelectorAll(TextUtil.LINK_SELECTOR);

links.forEach(l ={

// Don't replace unless the sys server can handle the request

let needsReplaced = l.href.match(/media.8kun.top\/.*[a-f0-9]{64}.(png|jpg|jpeg)/);

if (!needsReplaced) { return; }

let href = l.href.replace(TextUtil.MEDIA_SERVER, TextUtil.SYS_SERVER);

let pngMatch = href.match(/.*([a-f0-9]{64}).png$/);

if (pngMatch) {

let hash = pngMatch[1];

href = href.replace(${hash}.png, ${hash}.png/${hash}.jpg);

}

l.href = href;

let img = l.querySelector(TextUtil.IMG_SELECTOR);

if (!img) { return; }

img.src = l.href;

});

});

}

/**

  • Fixes any posts that already exist

*/

_fixExistingPosts() {

let posts = Array.from(document.querySelectorAll(TextUtil.POST_REPLY_SELECTOR));

posts.forEach(p ={

this._fixPost(p);

});

}

}

/**

  • MAIN

*/

if (ActivePage.isThread()) { // Only setup if we are on a thread

$(document).ready(function() {

window.temp = {};

window.temp.fixImages = new FixImages();

});

}

}(window.jQuery));