/* tslint:disable:quotemark */ import { domain } from '../bbcode/core'; export interface ImagePreviewMutatorCollection { [key: string]: string; } export class ImagePreviewMutator { private mutators: ImagePreviewMutatorCollection = {}; constructor() { this.init(); } getMutatorJsForSite(url: string): string | undefined { const urlDomain = domain(url); if (!urlDomain) return; // console.log('Domain is', urlDomain); let mutatorJs = this.mutators[urlDomain]; if (!mutatorJs) mutatorJs = this.mutators['default']; return `(() => { try { ${mutatorJs} } catch (err) { console.error(err); } })()`; } protected add(domain: string, mutatorJs: string) { this.mutators[domain] = mutatorJs; } protected init() { this.add('default', this.getBaseJsMutatorScript('#video, #image, video, img')); this.add('e621.net', this.getBaseJsMutatorScript('#image, video')); this.add('e-hentai.org', this.getBaseJsMutatorScript('#img, video')); this.add('gelbooru.com', this.getBaseJsMutatorScript('#image, video')); this.add('chan.sankakucomplex.com', this.getBaseJsMutatorScript('#image, video')); this.add('danbooru.donmai.us', this.getBaseJsMutatorScript('#image, video')); this.add('gfycat.com', this.getBaseJsMutatorScript('video')); this.add('gfycatporn.com', this.getBaseJsMutatorScript('video')); this.add('www.youtube.com', this.getBaseJsMutatorScript('video')); this.add('youtube.com', this.getBaseJsMutatorScript('video')); this.add('instantfap.com', this.getBaseJsMutatorScript('#post img, #post video')); this.add('www.webmshare.com', this.getBaseJsMutatorScript('video')); this.add('webmshare.com', this.getBaseJsMutatorScript('video')); this.add('pornhub.com', this.getBaseJsMutatorScript('.mainPlayerDiv video, .photoImageSection img')); this.add('www.sex.com', this.getBaseJsMutatorScript('.image_frame img, .image_frame video')); this.add('sex.com', this.getBaseJsMutatorScript('.image_frame img, .image_frame video')); this.add('redirect.media.tumblr.com', this.getBaseJsMutatorScript('picture img, picture video')); this.add('i.imgur.com', this.getBaseJsMutatorScript('video, img')); this.add( 'imgur.com', ` const imageCount = $('.post-container video, .post-container img').length; ${this.getBaseJsMutatorScript('.post-container video, .post-container img', true)} if(imageCount > 1) $('#flistWrapper').append('