Skip to content

Commit

Permalink
Fix ad links opening multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Aug 30, 2024
1 parent 436be3e commit 08c94f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
25 changes: 14 additions & 11 deletions apps/app/src/api/ads-init.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
10 changes: 0 additions & 10 deletions apps/frontend/src/public/promo-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -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());
</script>
</body>
Expand Down

0 comments on commit 08c94f5

Please sign in to comment.