web: Rename from snake_case to camelCase

This commit is contained in:
Toad06 2020-12-14 10:58:47 +01:00 committed by Mike Welsh
parent d6a857803a
commit b9aed2c7bb
2 changed files with 52 additions and 52 deletions

View File

@ -6,9 +6,9 @@ window.RufflePlayer = PublicAPI.negotiate(
new SourceAPI("extension") new SourceAPI("extension")
); );
if (obfuscated_event_prefix) { if (obfuscatedEventPrefix) {
document.addEventListener( document.addEventListener(
obfuscated_event_prefix + "_request", obfuscatedEventPrefix + "_request",
function (e) { function (e) {
let body = JSON.parse(e.detail); let body = JSON.parse(e.detail);
let response = {}; let response = {};
@ -17,7 +17,7 @@ if (obfuscated_event_prefix) {
//response.page_options = page_options; //response.page_options = page_options;
} }
let event = new CustomEvent(obfuscated_event_prefix + "_response", { let event = new CustomEvent(obfuscatedEventPrefix + "_response", {
detail: JSON.stringify(response), detail: JSON.stringify(response),
}); });
document.dispatchEvent(event); document.dispatchEvent(event);

View File

@ -26,18 +26,18 @@ const {
} = require("./util.js"); } = require("./util.js");
get_sync_storage(["ruffle_enable", "ignore_optout"], function (data) { get_sync_storage(["ruffle_enable", "ignore_optout"], function (data) {
let page_optout = document.documentElement.hasAttribute( let pageOptout = document.documentElement.hasAttribute(
"data-ruffle-optout" "data-ruffle-optout"
); );
try { try {
if ( if (
!page_optout && !pageOptout &&
window.top && window.top &&
window.top.document && window.top.document &&
window.top.document.documentElement window.top.document.documentElement
) { ) {
/* In case the opting out page uses iframes */ /* In case the opting out page uses iframes */
page_optout = window.top.document.documentElement.hasAttribute( pageOptout = window.top.document.documentElement.hasAttribute(
"data-ruffle-optout" "data-ruffle-optout"
); );
} }
@ -45,28 +45,28 @@ get_sync_storage(["ruffle_enable", "ignore_optout"], function (data) {
console.log("Unable to check top-level optout: " + e.message); console.log("Unable to check top-level optout: " + e.message);
} }
let should_load_untrusted_world = !(page_optout || window.RufflePlayer); let shouldLoadUntrustedWorld = !(pageOptout || window.RufflePlayer);
let obfuscated_event_prefix = let obfuscatedEventPrefix =
"rufEvent" + Math.floor(Math.random() * 100000000000); "rufEvent" + Math.floor(Math.random() * 100000000000);
let next_response_promise = null; let nextResponsePromise = null;
let next_response_promise_resolve = null; let nextResponsePromiseResolve = null;
if (data) { if (data) {
should_load_untrusted_world = shouldLoadUntrustedWorld =
data.ruffle_enable && data.ruffle_enable &&
!((page_optout && !data.ignore_optout) || window.RufflePlayer); !((pageOptout && !data.ignore_optout) || window.RufflePlayer);
} else { } else {
console.log("Couldn't read settings."); console.log("Couldn't read settings.");
} }
document.addEventListener( document.addEventListener(
obfuscated_event_prefix + "_response", obfuscatedEventPrefix + "_response",
function (e) { function (e) {
if (next_response_promise_resolve !== null) { if (nextResponsePromiseResolve !== null) {
next_response_promise_resolve(e); nextResponsePromiseResolve(e);
next_response_promise = null; nextResponsePromise = null;
next_response_promise_resolve = null; nextResponsePromiseResolve = null;
} }
} }
); );
@ -75,14 +75,14 @@ get_sync_storage(["ruffle_enable", "ignore_optout"], function (data) {
* Returns a promise which resolves the next time we receive our custom * Returns a promise which resolves the next time we receive our custom
* event response. * event response.
*/ */
function next_response() { function nextResponse() {
if (next_response_promise == null) { if (nextResponsePromise == null) {
next_response_promise = new Promise(function (resolve) { nextResponsePromise = new Promise(function (resolve) {
next_response_promise_resolve = resolve; nextResponsePromiseResolve = resolve;
}); });
} }
return next_response_promise; return nextResponsePromise;
} }
/** /**
@ -95,29 +95,29 @@ get_sync_storage(["ruffle_enable", "ignore_optout"], function (data) {
* @param request The request data from the background/popup page * @param request The request data from the background/popup page
* @returns Response data to reply to the sender with. * @returns Response data to reply to the sender with.
*/ */
async function marshal_message_into_untrusted_world(request) { async function marshalMessageIntoUntrustedWorld(request) {
let req_event = new CustomEvent(obfuscated_event_prefix + "_request", { let reqEvent = new CustomEvent(obfuscatedEventPrefix + "_request", {
detail: JSON.stringify(request), detail: JSON.stringify(request),
}); });
let resp_event_handler = next_response(); let respEventHandler = nextResponse();
document.dispatchEvent(req_event); document.dispatchEvent(reqEvent);
let resp_event = await resp_event_handler; let respEvent = await respEventHandler;
return JSON.parse(resp_event.detail); return JSON.parse(respEvent.detail);
} }
set_message_listener(function (request, sender, response_callback) { set_message_listener(function (request, sender, responseCallback) {
if (should_load_untrusted_world) { if (shouldLoadUntrustedWorld) {
let response_promise = marshal_message_into_untrusted_world( let responsePromise = marshalMessageIntoUntrustedWorld(
request request
); );
response_promise responsePromise
.then(function (response) { .then(function (response) {
response_callback({ responseCallback({
loaded: true, loaded: true,
tab_settings: data, tab_settings: data,
optout: page_optout, optout: pageOptout,
untrusted_response: response, untrusted_response: response,
}); });
}) })
@ -131,46 +131,46 @@ get_sync_storage(["ruffle_enable", "ignore_optout"], function (data) {
return true; return true;
} else { } else {
response_callback({ responseCallback({
loaded: false, loaded: false,
tab_settings: data, tab_settings: data,
optout: page_optout, optout: pageOptout,
}); });
return false; return false;
} }
}); });
const ext_path = get_extension_url(); const extPath = get_extension_url();
if (should_load_untrusted_world) { if (shouldLoadUntrustedWorld) {
// We must run the plugin polyfill before any flash detection scripts. // 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). // Unfortunately, this might still be too late for some websites when using Chrome (issue #969).
let polyfill_script = document.createElement("script"); let polyfillScript = document.createElement("script");
polyfill_script.innerHTML = polyfillScript.innerHTML =
'(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<a.length&&!navigator.mimeTypes.install&&Object.defineProperty(navigator,"mimeTypes",{value:new RuffleMimeTypeArray(navigator.mimeTypes),writable:!1});for(var b=0;b<a.length;b+=1)navigator.mimeTypes.install(a[b])}install_plugin(FLASH_PLUGIN);})();'; '(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<a.length&&!navigator.mimeTypes.install&&Object.defineProperty(navigator,"mimeTypes",{value:new RuffleMimeTypeArray(navigator.mimeTypes),writable:!1});for(var b=0;b<a.length;b+=1)navigator.mimeTypes.install(a[b])}install_plugin(FLASH_PLUGIN);})();';
(document.head || document.documentElement).appendChild( (document.head || document.documentElement).appendChild(
polyfill_script polyfillScript
); );
// Load Ruffle script asynchronously. By doing so, we can inject extra variables and isolate them from the global scope. // Load Ruffle script asynchronously. By doing so, we can inject extra variables and isolate them from the global scope.
(async function () { (async function () {
let ruffle_src_resp = await fetch(ext_path + "dist/ruffle.js"); let ruffleSrcResp = await fetch(extPath + "dist/ruffle.js");
if (ruffle_src_resp.ok) { if (ruffleSrcResp.ok) {
let ruffle_source = let ruffleSource =
'(function () { var ruffleRuntimePath = "' + '(function () { var ruffleRuntimePath = "' +
ext_path + extPath +
'";\nvar obfuscated_event_prefix = "' + '";\nvar obfuscatedEventPrefix = "' +
obfuscated_event_prefix + obfuscatedEventPrefix +
'";\n' + '";\n' +
(await ruffle_src_resp.text()) + (await ruffleSrcResp.text()) +
"}())"; "}())";
let ruffle_script = document.createElement("script"); let ruffleScript = document.createElement("script");
ruffle_script.appendChild( ruffleScript.appendChild(
document.createTextNode(ruffle_source) document.createTextNode(ruffleSource)
); );
(document.head || document.documentElement).appendChild( (document.head || document.documentElement).appendChild(
ruffle_script ruffleScript
); );
} else { } else {
console.error("Critical error loading Ruffle into page"); console.error("Critical error loading Ruffle into page");