| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | /* tslint:disable:quotemark */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  | import * as _ from 'lodash'; | 
					
						
							| 
									
										
										
										
											2019-07-13 12:32:35 -05:00
										 |  |  | import * as urlHelper from 'url'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-15 11:23:39 -05:00
										 |  |  | import { domain as extractDomain } from '../../bbcode/core'; | 
					
						
							| 
									
										
										
										
											2020-03-30 16:52:25 -05:00
										 |  |  | import { PornhubIntegration } from './integration/pornhub'; | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  | export interface PreviewMutator { | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |     match: string | RegExp; | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |     injectJs: string; | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |     eventName: string; | 
					
						
							| 
									
										
										
										
											2019-07-13 12:32:35 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     urlMutator?(url: string): string; | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | export interface ImagePreviewMutatorCollection { | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |     [key: string]: PreviewMutator; | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-15 13:17:36 -05:00
										 |  |  | // tslint:disable-next-line:max-line-length
 | 
					
						
							|  |  |  | const imgurOuterStyle = 'z-index: 1000000; position: absolute; bottom: 0.75rem; right: 0.75rem; background: rgba(0, 128, 0, 0.8); border: 2px solid rgba(144, 238, 144, 0.5); width: 3rem; height: 3rem; font-size: 15pt; font-weight: normal; color: white; border-radius: 3rem; margin: 0; font-family: Helvetica,Arial,sans-serif; box-shadow: 2px 2px 2px rgba(0,0,0,0.5)'; | 
					
						
							|  |  |  | // tslint:disable-next-line:max-line-length
 | 
					
						
							|  |  |  | const imgurInnerStyle = 'position: absolute; top: 50%; left: 50%; transform: translateY(-50%) translateX(-50%); text-shadow: 1px 1px 2px rgba(0,0,0,0.4);'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | export class ImagePreviewMutator { | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |     // tslint:disable: prefer-function-over-method
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |     private hostMutators: ImagePreviewMutatorCollection = {}; | 
					
						
							|  |  |  |     private regexMutators: PreviewMutator[] = []; | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |     private debug: boolean; | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |     constructor(debug: boolean) { | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  |         this.init(); | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 16:52:25 -05:00
										 |  |  |         // this.debug = debug;
 | 
					
						
							|  |  |  |         this.debug = debug || true; | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     setDebug(debug: boolean): void { | 
					
						
							|  |  |  |         this.debug = debug; | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-13 12:32:35 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     mutateUrl(url: string): string { | 
					
						
							|  |  |  |         const mutator = this.matchMutator(url); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ((!mutator) || (!mutator.urlMutator)) | 
					
						
							|  |  |  |             return url; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return mutator.urlMutator(url); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |     getMutatorJsForSite(url: string, eventName: string): string | undefined { | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |         let mutator = this.matchMutator(url); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!mutator) | 
					
						
							|  |  |  |             mutator = this.hostMutators['default']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |         if (mutator.eventName !== eventName) | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 17:11:55 -05:00
										 |  |  |         return this.wrapJs(mutator.injectJs) + this.getReShowMutator(); | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     matchMutator(url: string): PreviewMutator | undefined { | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |         const urlDomain = extractDomain(url); | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!urlDomain) | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |         if (urlDomain in this.hostMutators) | 
					
						
							|  |  |  |             return this.hostMutators[urlDomain]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return _.find( | 
					
						
							|  |  |  |             this.regexMutators, | 
					
						
							|  |  |  |             (m: PreviewMutator) => { | 
					
						
							|  |  |  |                 const match = m.match; | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |                 return (match instanceof RegExp) ? (urlDomain.match(match) !== null) : (match === urlDomain); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |     protected wrapJs(mutatorJs: string): string { | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |         return `(() => { try { ${mutatorJs} } catch (err) { console.error('Mutator error', err); } })();`; | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |     protected add( | 
					
						
							|  |  |  |         domain: string | RegExp, | 
					
						
							|  |  |  |         mutatorJs: string, | 
					
						
							|  |  |  |         urlMutator?: (url: string) => string, | 
					
						
							|  |  |  |         eventName: string = 'update-target-url' | 
					
						
							|  |  |  |     ): void { | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |         if (domain instanceof RegExp) { | 
					
						
							|  |  |  |             this.regexMutators.push( | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     match: domain, | 
					
						
							| 
									
										
										
										
											2019-07-13 12:32:35 -05:00
										 |  |  |                     injectJs: mutatorJs, | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |                     urlMutator, | 
					
						
							|  |  |  |                     eventName | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |                 } | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.hostMutators[domain] = { | 
					
						
							|  |  |  |             match: domain, | 
					
						
							| 
									
										
										
										
											2019-07-13 12:32:35 -05:00
										 |  |  |             injectJs: mutatorJs, | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |             urlMutator, | 
					
						
							|  |  |  |             eventName | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |     protected init(): void { | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |         this.add('default', this.getBaseJsMutatorScript(['#video, video', '#image, img'])); | 
					
						
							|  |  |  |         this.add('e621.net', this.getBaseJsMutatorScript(['video', '#image'])); | 
					
						
							|  |  |  |         this.add('e-hentai.org', this.getBaseJsMutatorScript(['video', '#img'])); | 
					
						
							|  |  |  |         this.add('gelbooru.com', this.getBaseJsMutatorScript(['video', '#image'])); | 
					
						
							|  |  |  |         this.add('chan.sankakucomplex.com', this.getBaseJsMutatorScript(['video', '#image'])); | 
					
						
							|  |  |  |         this.add('danbooru.donmai.us', this.getBaseJsMutatorScript(['video', '#image'])); | 
					
						
							| 
									
										
										
										
											2020-04-01 17:19:55 -05:00
										 |  |  |         this.add('gfycat.com', this.getBaseJsMutatorScript(['video']) /*, undefined, 'dom-ready' */); | 
					
						
							|  |  |  |         this.add('gfycatporn.com', this.getBaseJsMutatorScript(['video']) /*, undefined, 'dom-ready'*/); | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |         this.add('youtube.com', this.getBaseJsMutatorScript(['video']), undefined, 'dom-ready'); | 
					
						
							|  |  |  |         this.add('instantfap.com', this.getBaseJsMutatorScript(['#post video', '#post img'])); | 
					
						
							|  |  |  |         this.add('webmshare.com', this.getBaseJsMutatorScript(['video'])); | 
					
						
							| 
									
										
										
										
											2020-03-21 16:28:03 -05:00
										 |  |  |         this.add('vimeo.com', this.getBaseJsMutatorScript(['#video, video', '#image, img'])); | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |         this.add('sex.com', this.getBaseJsMutatorScript(['.image_frame video', '.image_frame img'])); | 
					
						
							|  |  |  |         this.add('redirect.media.tumblr.com', this.getBaseJsMutatorScript(['picture video', 'picture img'])); | 
					
						
							|  |  |  |         this.add('postimg.cc', this.getBaseJsMutatorScript(['video', '#main-image'])); | 
					
						
							|  |  |  |         this.add('gifsauce.com', this.getBaseJsMutatorScript(['video'])); | 
					
						
							|  |  |  |         this.add('motherless.com', this.getBaseJsMutatorScript(['.content video', '.content img'])); | 
					
						
							|  |  |  |         this.add(/^media[0-9]\.giphy\.com$/, this.getBaseJsMutatorScript(['video', 'img[alt]'])); | 
					
						
							|  |  |  |         this.add('giphy.com', this.getBaseJsMutatorScript(['video', 'a > div > img'])); | 
					
						
							|  |  |  |         this.add(/^media[0-9]\.tenor\.com$/, this.getBaseJsMutatorScript(['#view .file video', '#view .file img'])); | 
					
						
							|  |  |  |         this.add('tenor.com', this.getBaseJsMutatorScript(['#view video', '#view img'])); | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 16:52:25 -05:00
										 |  |  |         this.add( | 
					
						
							|  |  |  |             'pornhub.com', | 
					
						
							|  |  |  |             PornhubIntegration.preprocess() | 
					
						
							|  |  |  |                 + this.getBaseJsMutatorScript(['#__flistCore', '#player'], true) | 
					
						
							|  |  |  |                 + PornhubIntegration.postprocess() | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-27 14:31:45 -05:00
										 |  |  |         this.add( | 
					
						
							|  |  |  |             'i.imgur.com', | 
					
						
							|  |  |  |             `
 | 
					
						
							|  |  |  |                 const imageCount = (new URL(window.location.href)).searchParams.get('flist_gallery_image_count'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 ${this.getBaseJsMutatorScript(['video', 'img'])} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if(imageCount > 1) { | 
					
						
							| 
									
										
										
										
											2020-03-15 13:17:36 -05:00
										 |  |  |                     ${this.injectHtmlJs(`<div id="imageCount" style="${imgurOuterStyle}"><div id="imageCountInner" style="${imgurInnerStyle}"></div></div>`)} | 
					
						
							| 
									
										
										
										
											2019-10-27 14:31:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     const imageCountEl = document.getElementById('imageCountInner'); | 
					
						
							| 
									
										
										
										
											2020-03-14 21:31:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-07 09:32:49 -06:00
										 |  |  |                     if (imageCountEl) { | 
					
						
							| 
									
										
										
										
											2020-03-15 13:17:36 -05:00
										 |  |  |                         imageCountEl.innerHTML = '' + (imageCount); | 
					
						
							| 
									
										
										
										
											2019-12-07 09:32:49 -06:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2019-10-27 14:31:45 -05:00
										 |  |  |                 } | 
					
						
							|  |  |  |             `
 | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  |         this.add( | 
					
						
							|  |  |  |             'imgur.com', | 
					
						
							|  |  |  |             `
 | 
					
						
							| 
									
										
										
										
											2019-06-23 16:15:21 -05:00
										 |  |  |                 const imageCount = $('.post-container video, .post-container img').length; | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |                 ${this.getBaseJsMutatorScript(['.post-container video', '.post-container img'], true)} | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 if(imageCount > 1) | 
					
						
							| 
									
										
										
										
											2020-03-15 13:17:36 -05:00
										 |  |  |                     $('#flistWrapper').append('<div id="imageCount" style="${imgurOuterStyle}"><div style="${imgurInnerStyle}">+' + (imageCount - 1) + '</div></div>'); | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  |             `
 | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.add( | 
					
						
							|  |  |  |             'rule34.xxx', | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |             `${this.getBaseJsMutatorScript(['video', '#image'])}
 | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  |                 const content = document.querySelector('#content'); | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 if (content) content.remove(); | 
					
						
							|  |  |  |             `,
 | 
					
						
							|  |  |  |             undefined, | 
					
						
							|  |  |  |             'dom-ready' | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2019-07-13 12:32:35 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.add( | 
					
						
							|  |  |  |             'hentai-foundry.com', | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |             this.getBaseJsMutatorScript(['main video', 'main img']), | 
					
						
							| 
									
										
										
										
											2019-07-13 12:32:35 -05:00
										 |  |  |             (url: string): string => { | 
					
						
							|  |  |  |                 const u = urlHelper.parse(url, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (!u) | 
					
						
							|  |  |  |                     return url; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // tslint:disable-next-line no-any
 | 
					
						
							|  |  |  |                 (u.query as any).enterAgree = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 delete u.search; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return urlHelper.format(u); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 16:28:03 -05:00
										 |  |  |     getBaseJsMutatorScript(elSelector: string[], skipElementRemove: boolean = false, safeTags: string[] = []): string { | 
					
						
							| 
									
										
										
										
											2020-03-14 21:31:28 -05:00
										 |  |  |         return `const { ipcRenderer } = require('electron');
 | 
					
						
							|  |  |  |             const body = document.querySelector('body'); | 
					
						
							| 
									
										
										
										
											2019-10-26 17:20:53 -05:00
										 |  |  |             const html = document.querySelector('html'); | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |             const selectors = ${JSON.stringify(elSelector)}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // writing this out because sometimes .map and .reduce are overridden
 | 
					
						
							|  |  |  |             let selected = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (selector of selectors) { | 
					
						
							|  |  |  |                 const selectedElements = (Array.from(document.querySelectorAll(selector)).filter((i) => ((i.width !== 1) && (i.height !== 1)))); | 
					
						
							|  |  |  |                 selected = selected.concat(selectedElements); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-15 09:02:31 -05:00
										 |  |  |             ${this.debug ? `console.log('Selector', '${elSelector.toString()}'); console.log('Selected', selected);` : ''} | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             const img = selected.shift(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-27 14:31:45 -05:00
										 |  |  |             ${this.debug ? `console.log('Img', img);` : ''} | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (!img) { return; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 16:52:25 -05:00
										 |  |  |             const sizePairs = [ | 
					
						
							|  |  |  |                 ['naturalWidth', 'naturalHeight'], | 
					
						
							|  |  |  |                 ['videoWidth', 'videoHeight'], | 
					
						
							|  |  |  |                 ['width', 'height'], | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 17:19:55 -05:00
										 |  |  |             const resolveImgSize = function() { | 
					
						
							| 
									
										
										
										
											2020-04-01 19:27:21 -05:00
										 |  |  |                 const solved = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 for (let ri = 0; ri < sizePairs.length; ri++) { | 
					
						
							|  |  |  |                     const val = sizePairs[ri]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if ((img[val[0]]) && (img[val[1]])) { | 
					
						
							|  |  |  |                         solved.width = img[val[0]]; | 
					
						
							|  |  |  |                         solved.height = img[val[1]]; | 
					
						
							|  |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return solved; | 
					
						
							| 
									
										
										
										
											2020-04-01 17:19:55 -05:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-03-30 16:52:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:27:21 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             const preImSize = resolveImgSize(); | 
					
						
							|  |  |  |             ipcRenderer.sendToHost('webview.img', preImSize.width, preImSize.height, 'preImSize'); | 
					
						
							| 
									
										
										
										
											2020-03-14 21:31:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |             const el = document.createElement('div'); | 
					
						
							|  |  |  |             el.id = 'flistWrapper'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             el.style = 'width: 100% !important; height: 100% !important; position: absolute !important;' | 
					
						
							|  |  |  |                 + 'top: 0 !important; left: 0 !important; z-index: 100000 !important;' | 
					
						
							|  |  |  |                 + 'background-color: black !important; background-size: contain !important;' | 
					
						
							|  |  |  |                 + 'background-repeat: no-repeat !important; background-position: top left !important;' | 
					
						
							| 
									
										
										
										
											2019-10-26 17:20:53 -05:00
										 |  |  |                 + 'opacity: 1 !important; padding: 0 !important; border: 0 !important; margin: 0 !important;' | 
					
						
							|  |  |  |                 + 'min-width: unset !important; min-height: unset !important; max-width: unset !important; max-height: unset !important;'; | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |             try { | 
					
						
							|  |  |  |                 img.remove(); | 
					
						
							|  |  |  |             } catch(err) { | 
					
						
							|  |  |  |                 console.error('Failed remove()', err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 try { | 
					
						
							|  |  |  |                     img.parentNode.removeChild(img); | 
					
						
							|  |  |  |                 } catch(err2) { | 
					
						
							|  |  |  |                     console.error('Failed removeChild()', err2); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |             el.append(img); | 
					
						
							|  |  |  |             body.append(el); | 
					
						
							|  |  |  |             body.class = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             body.style = 'border: 0 !important; padding: 0 !important; margin: 0 !important; overflow: hidden !important;' | 
					
						
							|  |  |  |                 + 'width: 100% !important; height: 100% !important; opacity: 1 !important;' | 
					
						
							| 
									
										
										
										
											2019-10-26 17:20:53 -05:00
										 |  |  |                 + 'top: 0 !important; left: 0 !important; position: absolute !important;' | 
					
						
							| 
									
										
										
										
											2020-04-01 17:19:55 -05:00
										 |  |  |                 + 'min-width: initial !important; min-height: initial !important; max-width: initial !important; max-height: initial !important;' | 
					
						
							| 
									
										
										
										
											2020-03-21 16:28:03 -05:00
										 |  |  |                 + 'display: block !important; visibility: visible !important'; | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             img.style = 'object-position: top left !important; object-fit: contain !important;' | 
					
						
							|  |  |  |                 + 'width: 100% !important; height: 100% !important; opacity: 1 !important;' | 
					
						
							| 
									
										
										
										
											2019-10-26 17:20:53 -05:00
										 |  |  |                 + 'margin: 0 !imporant; border: 0 !important; padding: 0 !important;' | 
					
						
							| 
									
										
										
										
											2020-04-01 17:19:55 -05:00
										 |  |  |                 + 'min-width: initial !important; min-height: initial !important; max-width: initial !important; max-height: initial !important;' | 
					
						
							|  |  |  |                 + 'display: block !important; visibility: visible !important;'; | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:27:21 -05:00
										 |  |  |             img.removeAttribute('width'); | 
					
						
							|  |  |  |             img.removeAttribute('height'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |             img.class = ''; | 
					
						
							|  |  |  |             el.class = ''; | 
					
						
							| 
									
										
										
										
											2019-10-26 17:20:53 -05:00
										 |  |  |             html.class = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             html.style = 'border: 0 !important; padding: 0 !important; margin: 0 !important; overflow: hidden !important;' | 
					
						
							|  |  |  |                 + 'width: 100% !important; height: 100% !important; opacity: 1 !important;' | 
					
						
							|  |  |  |                 + 'top: 0 !important; left: 0 !important; position: absolute !important;' | 
					
						
							| 
									
										
										
										
											2020-04-01 17:19:55 -05:00
										 |  |  |                 + 'min-width: initial !important; min-height: initial !important; max-width: initial !important; max-height: initial !important;' | 
					
						
							| 
									
										
										
										
											2020-03-21 16:28:03 -05:00
										 |  |  |                 + 'display: block !important; visibility: visible !important'; | 
					
						
							| 
									
										
										
										
											2019-10-26 17:20:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |             ${this.debug ? "console.log('Wrapper', el);" : ''} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-07 07:58:11 -06:00
										 |  |  |             if ((!img.src) && (img.tagName) && (img.tagName.toUpperCase() === 'VIDEO')) { | 
					
						
							|  |  |  |                 ${this.debug ? "console.log('Nedds a content URL', img);" : ''} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 const contentUrls = document.querySelectorAll('meta[itemprop="contentURL"]'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if ((contentUrls) && (contentUrls.length > 0)) { | 
					
						
							|  |  |  |                     ${this.debug ? "console.log('Found content URLs', contentUrls);" : ''} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     const cu = contentUrls[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if ((cu.attributes) && (cu.attributes.content) && (cu.attributes.content.value)) { | 
					
						
							|  |  |  |                         ${this.debug ? "console.log('Content URL', cu.attributes.content.value);" : ''} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         img.src = cu.attributes.content.value; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |             document.addEventListener('DOMContentLoaded', (event) => { | 
					
						
							| 
									
										
										
										
											2019-10-27 14:31:45 -05:00
										 |  |  |                 ${this.debug ? "console.log('on DOMContentLoaded');" : ''} | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 17:19:55 -05:00
										 |  |  |                 const imSize = resolveImgSize(); | 
					
						
							| 
									
										
										
										
											2020-04-01 19:27:21 -05:00
										 |  |  |                 ipcRenderer.sendToHost('webview.img', imSize.width, imSize.height, 'dom-content-loaded'); | 
					
						
							| 
									
										
										
										
											2020-03-14 21:31:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |                 if ( | 
					
						
							|  |  |  |                     (img.play) | 
					
						
							|  |  |  |                     && ((!img.paused) && (!img.ended) && (!(img.currentTime > 0))) | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2020-03-14 21:31:28 -05:00
										 |  |  |                 { img.muted = true; img.loop = true; img.play(); } | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             document.addEventListener('load', (event) => { | 
					
						
							| 
									
										
										
										
											2019-10-27 14:31:45 -05:00
										 |  |  |                 ${this.debug ? "console.log('on load');" : ''} | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 17:19:55 -05:00
										 |  |  |                 const imSize = resolveImgSize(); | 
					
						
							| 
									
										
										
										
											2020-04-01 19:27:21 -05:00
										 |  |  |                 ipcRenderer.sendToHost('webview.img', imSize.width, imSize.height, 'load'); | 
					
						
							| 
									
										
										
										
											2020-03-14 21:31:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |                 if ( | 
					
						
							|  |  |  |                     (img.play) | 
					
						
							|  |  |  |                     && ((!img.paused) && (!img.ended) && (!(img.currentTime > 0))) | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2020-03-14 21:31:28 -05:00
										 |  |  |                 { img.muted = true; img.loop = true; img.play(); } | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             try { | 
					
						
							| 
									
										
										
										
											2020-03-14 21:31:28 -05:00
										 |  |  |                 if (img.play) { img.muted = true; img.loop = true; img.play(); } | 
					
						
							| 
									
										
										
										
											2019-10-06 18:08:22 -05:00
										 |  |  |             } catch (err) { | 
					
						
							|  |  |  |                 console.error('Failed img.play()', err); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-01 19:27:21 -05:00
										 |  |  |             const updateSize = () => { | 
					
						
							|  |  |  |                 const imSize = resolveImgSize(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if ((imSize.width) && (imSize.height)) { | 
					
						
							|  |  |  |                     ipcRenderer.sendToHost('webview.img', imSize.width, imSize.height, 'updateSize'); | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     setTimeout(() => updateSize(), 200); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             updateSize(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |             let removeList = []; | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |             const safeIds = ['flistWrapper', 'flistError', 'flistHider']; | 
					
						
							| 
									
										
										
										
											2020-03-21 16:28:03 -05:00
										 |  |  |             const safeTags = [${_.map(safeTags, (t) => `'${t.toLowerCase()}'`).join(',')}]; | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 16:28:03 -05:00
										 |  |  |             body.childNodes.forEach((el) => ( | 
					
						
							|  |  |  |                 ( | 
					
						
							|  |  |  |                     (safeIds.indexOf(el.id) < 0) | 
					
						
							|  |  |  |                     && ((!el.tagName) || (safeTags.indexOf(el.tagName.toLowerCase())) < 0) | 
					
						
							|  |  |  |                 ) ? removeList.push(el) : true) | 
					
						
							|  |  |  |             ); | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             ${skipElementRemove ? '' : 'removeList.forEach((el) => el.remove());'} | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |             removeList = []; | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  |         `;
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |     getErrorMutator(code: number, description: string): string { | 
					
						
							|  |  |  |         const errorHtml = `
 | 
					
						
							|  |  |  |             <div id="flistError" style=" | 
					
						
							|  |  |  |                 width: 100% !important; | 
					
						
							|  |  |  |                 height: 100% !important; | 
					
						
							|  |  |  |                 background-color: black !important; | 
					
						
							|  |  |  |                 position: absolute !important; | 
					
						
							|  |  |  |                 top: 0 !important; | 
					
						
							|  |  |  |                 left: 0 !important; | 
					
						
							|  |  |  |                 right: 0 !important; | 
					
						
							|  |  |  |                 bottom: 0 !important; | 
					
						
							|  |  |  |                 z-index: 200000 !important; | 
					
						
							|  |  |  |                 margin: 0 !important; | 
					
						
							|  |  |  |                 padding: 0 !important; | 
					
						
							|  |  |  |                 line-height: 100% !important; | 
					
						
							|  |  |  |                 border: 0 !important; | 
					
						
							|  |  |  |                 opacity: 1 !important; | 
					
						
							|  |  |  |                 text-align: center !important; | 
					
						
							|  |  |  |             "><h1 style=" | 
					
						
							|  |  |  |                 color: #FF4444 !important; | 
					
						
							|  |  |  |                 font-size: 45pt !important; | 
					
						
							|  |  |  |                 margin: 0 !important; | 
					
						
							|  |  |  |                 margin-top: 10pt !important; | 
					
						
							|  |  |  |                 line-height: 100% !important; | 
					
						
							|  |  |  |                 padding: 0 !important; | 
					
						
							|  |  |  |                 border: 0 !important; | 
					
						
							|  |  |  |                 background: none !important; | 
					
						
							|  |  |  |                 font-family: Helvetica, Arial, sans-serif !important; | 
					
						
							|  |  |  |                 font-weight: bold !important; | 
					
						
							|  |  |  |             ">${code}</h1><p style=" | 
					
						
							|  |  |  |                 max-width: 400px !important; | 
					
						
							|  |  |  |                 color: #ededed !important; | 
					
						
							|  |  |  |                 display: inline-block !important; | 
					
						
							|  |  |  |                 font-size: 15pt !important; | 
					
						
							|  |  |  |                 font-family: Helvetica, Arial, sans-serif !important; | 
					
						
							|  |  |  |                 font-weight: 300 !important; | 
					
						
							|  |  |  |                 border: 0 !important; | 
					
						
							|  |  |  |                 margin: 0 !important; | 
					
						
							|  |  |  |                 padding: 0 !important; | 
					
						
							|  |  |  |                 margin-top: 5pt !important; | 
					
						
							|  |  |  |                 line-height: 130% !important; | 
					
						
							|  |  |  |             ">${description}</p></div> | 
					
						
							|  |  |  |         `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |         return this.injectHtmlJs(errorHtml); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected injectHtmlJs(html: string): string { | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |         return this.wrapJs(`
 | 
					
						
							|  |  |  |             const range = document.createRange(); | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |             range.selectNode(document.body); | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             const error = range.createContextualFragment(\`${html}\`);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-04 14:34:21 -05:00
										 |  |  |             document.body.appendChild(error); | 
					
						
							|  |  |  |         `);
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |     getHideMutator(): string { | 
					
						
							|  |  |  |         return this.injectHtmlJs(`
 | 
					
						
							|  |  |  |             <div id="flistHider" style=" | 
					
						
							|  |  |  |                 width: 100% !important; | 
					
						
							|  |  |  |                 height: 100% !important; | 
					
						
							|  |  |  |                 background-color: black !important; | 
					
						
							|  |  |  |                 position: absolute !important; | 
					
						
							|  |  |  |                 top: 0 !important; | 
					
						
							|  |  |  |                 left: 0 !important; | 
					
						
							|  |  |  |                 right: 0 !important; | 
					
						
							|  |  |  |                 bottom: 0 !important; | 
					
						
							|  |  |  |                 z-index: 300000 !important; | 
					
						
							|  |  |  |                 margin: 0 !important; | 
					
						
							|  |  |  |                 padding: 0 !important; | 
					
						
							|  |  |  |                 line-height: 100% !important; | 
					
						
							|  |  |  |                 border: 0 !important; | 
					
						
							|  |  |  |                 opacity: 1 !important; | 
					
						
							|  |  |  |                 text-align: center !important; | 
					
						
							|  |  |  |             "></div> | 
					
						
							| 
									
										
										
										
											2019-07-12 17:11:55 -05:00
										 |  |  |         `) + this.wrapJs(
 | 
					
						
							|  |  |  |             `
 | 
					
						
							|  |  |  |                 window.__flistUnhide = () => { | 
					
						
							|  |  |  |                     const elements = document.querySelectorAll('#flistHider'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (elements) { | 
					
						
							|  |  |  |                         elements.forEach( (el) => el.remove() ); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 }; | 
					
						
							|  |  |  |             `
 | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2019-07-06 11:49:19 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-07-06 20:37:15 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     getReShowMutator(): string { | 
					
						
							|  |  |  |         return this.wrapJs( | 
					
						
							|  |  |  |             `
 | 
					
						
							| 
									
										
										
										
											2019-07-12 17:11:55 -05:00
										 |  |  |             const elements = document.querySelectorAll('#flistHider'); | 
					
						
							| 
									
										
										
										
											2019-07-06 20:37:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-12 17:11:55 -05:00
										 |  |  |             if (elements) { | 
					
						
							|  |  |  |                 elements.forEach( (el) => el.remove() ); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-07-06 20:37:15 -05:00
										 |  |  |             `
 | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-08 17:51:04 -05:00
										 |  |  | } |