From 4dfbff5f2ff3d92cbea8da58a7495f4a4982803e Mon Sep 17 00:00:00 2001 From: relrelb Date: Fri, 24 Sep 2021 09:08:39 +0300 Subject: [PATCH] extension: Invert `shouldLoad` condition This is a pure mechanical change, in order to lower the indentation level. --- web/packages/extension/src/content.ts | 56 ++++++++++++++------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/web/packages/extension/src/content.ts b/web/packages/extension/src/content.ts index f45afffc6..5177ba47f 100644 --- a/web/packages/extension/src/content.ts +++ b/web/packages/extension/src/content.ts @@ -130,32 +130,34 @@ function isXMLDocument(): boolean { } }); - if (shouldLoad) { - // We must run the plugin polyfill before any flash detection scripts. - // Unfortunately, this might still be too late for some websites when using Chrome (issue #969). - // TODO: use plugin-polyfill.ts - injectScriptRaw( - '(function(){class RuffleMimeType{constructor(a,b,c){this.type=a,this.description=b,this.suffixes=c}}class RuffleMimeTypeArray{constructor(a){this.__mimetypes=[],this.__named_mimetypes={};for(let b of a)this.install(b)}install(a){let b=this.__mimetypes.length;this.__mimetypes.push(a),this.__named_mimetypes[a.type]=a,this[a.type]=a,this[b]=a}item(a){return this.__mimetypes[a]}namedItem(a){return this.__named_mimetypes[a]}get length(){return this.__mimetypes.length}}class RufflePlugin extends RuffleMimeTypeArray{constructor(a,b,c,d){super(d),this.name=a,this.description=b,this.filename=c}install(a){a.enabledPlugin||(a.enabledPlugin=this),super.install(a)}}class RufflePluginArray{constructor(a){this.__plugins=[],this.__named_plugins={};for(let b of a)this.install(b)}install(a){let b=this.__plugins.length;this.__plugins.push(a),this.__named_plugins[a.name]=a,this[a.name]=a,this[b]=a}item(a){return this.__plugins[a]}namedItem(a){return this.__named_plugins[a]}get length(){return this.__plugins.length}}const FLASH_PLUGIN=new RufflePlugin("Shockwave Flash","Shockwave Flash 32.0 r0","ruffle.js",[new RuffleMimeType("application/futuresplash","Shockwave Flash","spl"),new RuffleMimeType("application/x-shockwave-flash","Shockwave Flash","swf"),new RuffleMimeType("application/x-shockwave-flash2-preview","Shockwave Flash","swf"),new RuffleMimeType("application/vnd.adobe.flash-movie","Shockwave Flash","swf")]);function install_plugin(a){navigator.plugins.install||Object.defineProperty(navigator,"plugins",{value:new RufflePluginArray(navigator.plugins),writable:!1}),navigator.plugins.install(a),0 { - // We only accept messages from ourselves. - if (event.source !== window) { - return; - } - - const { to, index, data } = event.data; - if (to === `ruffle_content${ID}`) { - const request = pendingMessages[index]; - if (request) { - pendingMessages[index] = null; - request.resolve(data); - } else { - // TODO: Handle page-initiated messages. - console.warn("No pending request."); - } - } - }); + if (!shouldLoad) { + return; } + + // We must run the plugin polyfill before any flash detection scripts. + // Unfortunately, this might still be too late for some websites when using Chrome (issue #969). + // TODO: use plugin-polyfill.ts + injectScriptRaw( + '(function(){class RuffleMimeType{constructor(a,b,c){this.type=a,this.description=b,this.suffixes=c}}class RuffleMimeTypeArray{constructor(a){this.__mimetypes=[],this.__named_mimetypes={};for(let b of a)this.install(b)}install(a){let b=this.__mimetypes.length;this.__mimetypes.push(a),this.__named_mimetypes[a.type]=a,this[a.type]=a,this[b]=a}item(a){return this.__mimetypes[a]}namedItem(a){return this.__named_mimetypes[a]}get length(){return this.__mimetypes.length}}class RufflePlugin extends RuffleMimeTypeArray{constructor(a,b,c,d){super(d),this.name=a,this.description=b,this.filename=c}install(a){a.enabledPlugin||(a.enabledPlugin=this),super.install(a)}}class RufflePluginArray{constructor(a){this.__plugins=[],this.__named_plugins={};for(let b of a)this.install(b)}install(a){let b=this.__plugins.length;this.__plugins.push(a),this.__named_plugins[a.name]=a,this[a.name]=a,this[b]=a}item(a){return this.__plugins[a]}namedItem(a){return this.__named_plugins[a]}get length(){return this.__plugins.length}}const FLASH_PLUGIN=new RufflePlugin("Shockwave Flash","Shockwave Flash 32.0 r0","ruffle.js",[new RuffleMimeType("application/futuresplash","Shockwave Flash","spl"),new RuffleMimeType("application/x-shockwave-flash","Shockwave Flash","swf"),new RuffleMimeType("application/x-shockwave-flash2-preview","Shockwave Flash","swf"),new RuffleMimeType("application/vnd.adobe.flash-movie","Shockwave Flash","swf")]);function install_plugin(a){navigator.plugins.install||Object.defineProperty(navigator,"plugins",{value:new RufflePluginArray(navigator.plugins),writable:!1}),navigator.plugins.install(a),0 { + // We only accept messages from ourselves. + if (event.source !== window) { + return; + } + + const { to, index, data } = event.data; + if (to === `ruffle_content${ID}`) { + const request = pendingMessages[index]; + if (request) { + pendingMessages[index] = null; + request.resolve(data); + } else { + // TODO: Handle page-initiated messages. + console.warn("No pending request."); + } + } + }); })();