From 238b3d9521394d49f2bb193813f8abb111a6afae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Vivet?= Date: Wed, 10 Jul 2024 14:41:04 +0200 Subject: [PATCH] Auto-load the CrazyGames extension when the domain is part of crazygames.com (#1333) --- extensions/reviewed/CrazyGamesAdApi.json | 78 +++++++++++++----------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/extensions/reviewed/CrazyGamesAdApi.json b/extensions/reviewed/CrazyGamesAdApi.json index 87512c00..97800454 100644 --- a/extensions/reviewed/CrazyGamesAdApi.json +++ b/extensions/reviewed/CrazyGamesAdApi.json @@ -8,12 +8,11 @@ "name": "CrazyGamesAdApi", "previewIconUrl": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iODkiIGhlaWdodD0iMTAwIiB2aWV3Qm94PSIwIDAgODkgMTAwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTg0LjkwMzQgMjUuODkyOUM4NS4wNzI3IDE4LjY4MjQgODQuNjQ5NCA2LjExNjk0IDgwLjA3NzYgMC44NzQ4NTlDNzcuNTcyOSAtMS45OTY2NCA3MS42MTgzIDIuODA4MDEgNjcuNzY2MSA2LjUxOTA5QzYxLjM4MSAzLjQwNzcxIDUzLjUzNTUgMS44NzY3MSA0My45OTY4IDEuODc2NzFDMzQuNDU4IDEuODc2NzEgMjYuNjE5NiAzLjQxNDc2IDIwLjI0MTYgNi41MTkwOUMxNi4zODI0IDIuODA4MDEgMTAuNDM0OCAtMS45ODk1OSA3LjkzMDE0IDAuODgxOTE1QzMuMzY1MzcgNi4xMTY5NCAyLjkzNSAxOC42NDAxIDMuMTA0MzIgMjUuODU3NkMxLjA1MTIzIDMxLjUwMTkgMCAzOC4wOTE1IDAgNDUuNjEyNUMwIDYxLjQzMDQgNC41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kuODY5NSA0NC4zMjg0IDM5LjcwNzIgNDQuMzI4NEMzNy4xMTc5IDQ0LjMyODQgMzUuMDIyNSA0Mi4yNDcxIDM1LjAyMjUgMzkuNjc5TDM1LjAyOTYgMzkuNjcxOVpNNTcuMjExNCAzNC44ODg0QzU1LjQxMjMgMzUuNTM3NSA1NC4xMjgyIDM3LjI0NDkgNTQuMTI4MiAzOS4yNTU3VjM5LjI2MjdDNTQuMTI4MiA0MS44MzA4IDU2LjIyMzYgNDMuOTEyMSA1OC44MTI5IDQzLjkxMjFDNTkuMDUyOCA0My45MTIxIDU5LjI4NTYgNDMuODkxIDU5LjUxMTQgNDMuODU1N1Y1MS4xNTc5QzU5LjUxMTQgNTQuMzY4MSA1Ni44NzI3IDU2Ljk4NTYgNTMuNjQ4NCA1Ni45ODU2QzUwLjQyNDIgNTYuOTg1NiA0Ny43ODU1IDU0LjM2MSA0Ny43ODU1IDUxLjE1NzlWMzkuNTAyNkM0Ny43ODU1IDM2LjI5OTUgNTAuNDI0MiAzMy42NzQ5IDUzLjY0ODQgMzMuNjc0OUM1NC45ODg5IDMzLjY3NDkgNTYuMjIzNiAzNC4xMzM1IDU3LjIxMTQgMzQuODg4NFoiIGZpbGw9IiMwQzBEMTQiLz4KPC9zdmc+Cg==", "shortDescription": "Allow games to be hosted on CrazyGames website and display ads.", - "version": "1.3.0", + "version": "1.3.1", "description": [ "Please refer to [CrazyGames' guide](https://docs.crazygames.com/sdk/html5-v2/intro/) to know when to call the different actions.", "", - "### Patch note", - "- 1.3.0: The SDK have to be manually called via an action." + "The SDK is automatically loaded on CrazyGames domains, but can be forced with the action of the same name if it fail." ], "origin": { "identifier": "CrazyGamesAdApi", @@ -48,11 +47,30 @@ " hasVideoAdJustFinishedPlaying: false,", " isAdBlockerDetected: false,", " links: new Map(),", - "};" + " logger: new gdjs.Logger(\"CrazyGames SDK\"),", + "};", + "", + "if (document.referrer && new URL(document.referrer).hostname.endsWith(\".crazygames.com\")) {", + " const addScript = (src) => {", + " return new Promise((resolve, reject) => {", + " const scriptElement = document.createElement('script');", + "", + " scriptElement.setAttribute('src', src);", + " scriptElement.addEventListener('load', resolve);", + " scriptElement.addEventListener('error', reject);", + "", + " document.body.appendChild(scriptElement);", + " });", + " }", + " addScript('https://sdk.crazygames.com/crazygames-sdk-v2.js').then(() => {", + " gdjs._crazyGamesExtension.isSdkReady = true;", + " gdjs._crazyGamesExtension.logger.log(\"CrazyGames SDK successfully initialized.\");", + " });", + "}" ], "parameterObjects": "", "useStrict": true, - "eventsSheetExpanded": false + "eventsSheetExpanded": true } ], "parameters": [], @@ -120,8 +138,6 @@ { "type": "BuiltinCommonInstructions::JsCode", "inlineCode": [ - "const logger = new gdjs.Logger(\"CrazyGames SDK\");", - "", "const roomId = eventsFunctionContext.getArgument(\"RoomId\");", "", "window.CrazyGames.SDK.game.showInviteButton({", @@ -130,9 +146,9 @@ " //param3: \"value\"", "}, (error, result) => {", " if (error) {", - " logger.error(\"Invite button link error\", error);", + " gdjs._crazyGamesExtension.logger.error(\"Invite button link error\", error);", " } else {", - " logger.log(\"Invite button link\", result);", + " gdjs._crazyGamesExtension.logger.log(\"Invite button link\", result);", " }", "});" ], @@ -179,21 +195,20 @@ { "type": "BuiltinCommonInstructions::JsCode", "inlineCode": [ - "const logger = new gdjs.Logger(\"CrazyGames SDK\");\r", - "const addScript = (src) => {\r", - " return new Promise((resolve, reject) => {\r", - " const scriptElement = document.createElement('script');\r", - "\r", - " scriptElement.setAttribute('src', src);\r", - " scriptElement.addEventListener('load', resolve);\r", - " scriptElement.addEventListener('error', reject);\r", - "\r", - " document.body.appendChild(scriptElement);\r", - " });\r", - "}\r", - "addScript('https://sdk.crazygames.com/crazygames-sdk-v2.js').then(() => {\r", - " gdjs._crazyGamesExtension.isSdkReady = true;\r", - " logger.log(\"CrazyGames SDK successfully initialized.\");\r", + "const addScript = (src) => {", + " return new Promise((resolve, reject) => {", + " const scriptElement = document.createElement('script');", + "", + " scriptElement.setAttribute('src', src);", + " scriptElement.addEventListener('load', resolve);", + " scriptElement.addEventListener('error', reject);", + "", + " document.body.appendChild(scriptElement);", + " });", + "}", + "addScript('https://sdk.crazygames.com/crazygames-sdk-v2.js').then(() => {", + " gdjs._crazyGamesExtension.isSdkReady = true;", + " gdjs._crazyGamesExtension.logger.log(\"CrazyGames SDK successfully initialized.\");", "})" ], "parameterObjects": "", @@ -399,8 +414,6 @@ { "type": "BuiltinCommonInstructions::JsCode", "inlineCode": [ - "const logger = new gdjs.Logger(\"CrazyGames SDK\");", - "", "const adType = eventsFunctionContext.getArgument(\"AdType\");", "", "const volume = runtimeScene.getSoundManager().getGlobalVolume();", @@ -422,7 +435,7 @@ " if (runtimeScene.getSoundManager().getGlobalVolume() === 0) {", " runtimeScene.getSoundManager().setGlobalVolume(volume);", " }", - " logger.error(`Error ${adType} ad (callback): `, error, errorData);", + " gdjs._crazyGamesExtension.logger.error(`Error ${adType} ad (callback): `, error, errorData);", " },", "});" ], @@ -544,12 +557,11 @@ "inlineCode": [ "const roomId = eventsFunctionContext.getArgument(\"RoomId\");", "", - "const logger = new gdjs.Logger(\"CrazyGames SDK\");", "window.CrazyGames.SDK.game.inviteLink(", " { roomId },", " (error, link) => {", " if (error) {", - " logger.error(\"Invite link error.\", error);", + " gdjs._crazyGamesExtension.logger.error(\"Invite link error.\", error);", " } else {", " gdjs._crazyGamesExtension.links.set(roomId, link);", " eventsFunctionContext.task.resolve();", @@ -659,10 +671,9 @@ { "type": "BuiltinCommonInstructions::JsCode", "inlineCode": [ - "const logger = new gdjs.Logger(\"CrazyGames SDK\");", "window.CrazyGames.SDK.ad.hasAdblock((error, result) => {", " if (error) {", - " logger.error(\"Unable to scan adblockers.\", error);", + " gdjs._crazyGamesExtension.logger.error(\"Unable to scan adblockers.\", error);", " gdjs._crazyGamesExtension.latestError = error;", " } else {", " gdjs._crazyGamesExtension.isAdBlockerDetected = result;", @@ -750,7 +761,6 @@ { "type": "BuiltinCommonInstructions::JsCode", "inlineCode": [ - "const logger = new gdjs.Logger(\"CrazyGames SDK\");", "const bannerName = eventsFunctionContext.getArgument(\"BannerName\");", "const positionX = eventsFunctionContext.getArgument(\"PositionX\");", "const positionY = eventsFunctionContext.getArgument(\"PositionY\");", @@ -780,10 +790,10 @@ " height: size.height,", "}, (error, result) => {", " if (error) {", - " logger.error(\"Error on request banner.\", error);", + " gdjs._crazyGamesExtension.logger.error(\"Error on request banner.\", error);", " } else {", " // Result is always undefined when requesting banners", - " logger.log(\"End request banner\", result === undefined ? \"Requesting banners\" : result);", + " gdjs._crazyGamesExtension.logger.log(\"End request banner\", result === undefined ? \"Requesting banners\" : result);", " eventsFunctionContext.task.resolve();", " }", "});"