From 08c94f5a7a2a54c1d02bcbf384e6b518ec8937c9 Mon Sep 17 00:00:00 2001 From: Jai A Date: Fri, 30 Aug 2024 10:31:10 -0700 Subject: [PATCH] Fix ad links opening multiple times --- apps/app/src/api/ads-init.js | 25 +++++++++++++---------- apps/frontend/src/public/promo-frame.html | 10 --------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/apps/app/src/api/ads-init.js b/apps/app/src/api/ads-init.js index b1ebb879e..23291a894 100644 --- a/apps/app/src/api/ads-init.js +++ b/apps/app/src/api/ads-init.js @@ -1,16 +1,19 @@ -document.addEventListener('click', function (e) { - let target = e.target - while (target != null) { - if (target.matches('a')) { - e.preventDefault() - if (target.href) { - window.top.postMessage({ modrinthOpenUrl: target.href }, 'https://modrinth.com') +if (!window.modrinthClickListener) { + window.modrinthClickListener = true + document.addEventListener('click', function (e) { + let target = e.target + while (target != null) { + if (target.matches('a')) { + e.preventDefault() + if (target.href) { + window.top.postMessage({ modrinthOpenUrl: target.href }, 'https://modrinth.com') + } + break } - break + target = target.parentElement } - target = target.parentElement - } -}) + }) +} window.open = (url, target, features) => { window.top.postMessage({ modrinthOpenUrl: url }, 'https://modrinth.com') diff --git a/apps/frontend/src/public/promo-frame.html b/apps/frontend/src/public/promo-frame.html index 5dd993cee..1a09f4eaf 100644 --- a/apps/frontend/src/public/promo-frame.html +++ b/apps/frontend/src/public/promo-frame.html @@ -78,16 +78,6 @@ } }); - document.getElementById("plus-link").addEventListener("click", (event) => { - event.preventDefault(); - - if (event.data.modrinthOpenUrl && window.__TAURI_INTERNALS__) { - window.__TAURI_INTERNALS__.invoke("plugin:shell|open", { - path: this.href, - }); - } - }); - document.addEventListener("contextmenu", (event) => event.preventDefault());