Skip to content

Commit

Permalink
Remove ads muting (#2511)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically authored Oct 16, 2024
1 parent 42ade0f commit fce516a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 87 deletions.
2 changes: 1 addition & 1 deletion apps/app-frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@modrinth/app-frontend",
"private": true,
"version": "0.8.8",
"version": "0.8.9",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion apps/app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "theseus_gui"
version = "0.8.8"
version = "0.8.9"
description = "The Modrinth App is a desktop application for managing your Minecraft mods"
license = "GPL-3.0-only"
repository = "https://github.com/modrinth/code/apps/app/"
Expand Down
83 changes: 0 additions & 83 deletions apps/app/src/api/ads-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,86 +21,3 @@ document.addEventListener(
window.open = (url, target, features) => {
window.top.postMessage({ modrinthOpenUrl: url }, 'https://modrinth.com')
}

function muteAudioContext() {
if (window.AudioContext || window.webkitAudioContext) {
const AudioContext = window.AudioContext || window.webkitAudioContext
const originalCreateMediaElementSource = AudioContext.prototype.createMediaElementSource
const originalCreateMediaStreamSource = AudioContext.prototype.createMediaStreamSource
const originalCreateMediaStreamTrackSource = AudioContext.prototype.createMediaStreamTrackSource
const originalCreateBufferSource = AudioContext.prototype.createBufferSource
const originalCreateOscillator = AudioContext.prototype.createOscillator

AudioContext.prototype.createGain = function () {
const gain = originalCreateGain.call(this)
gain.gain.value = 0
return gain
}

AudioContext.prototype.createMediaElementSource = function (mediaElement) {
const source = originalCreateMediaElementSource.call(this, mediaElement)
source.connect(this.createGain())
return source
}

AudioContext.prototype.createMediaStreamSource = function (mediaStream) {
const source = originalCreateMediaStreamSource.call(this, mediaStream)
source.connect(this.createGain())
return source
}

AudioContext.prototype.createMediaStreamTrackSource = function (mediaStreamTrack) {
const source = originalCreateMediaStreamTrackSource.call(this, mediaStreamTrack)
source.connect(this.createGain())
return source
}

AudioContext.prototype.createBufferSource = function () {
const source = originalCreateBufferSource.call(this)
source.connect(this.createGain())
return source
}

AudioContext.prototype.createOscillator = function () {
const oscillator = originalCreateOscillator.call(this)
oscillator.connect(this.createGain())
return oscillator
}
}
}

function muteVideo(mediaElement) {
let count = Number(mediaElement.getAttribute('data-modrinth-muted-count') ?? 0)

if (!mediaElement.muted || mediaElement.volume !== 0) {
mediaElement.muted = true
mediaElement.volume = 0

mediaElement.setAttribute('data-modrinth-muted-count', count + 1)
}

if (count > 5) {
// Video is detected as malicious, so it is removed from the page
mediaElement.remove()
}
}

function muteVideos() {
document.querySelectorAll('video, audio').forEach(function (mediaElement) {
muteVideo(mediaElement)

if (!mediaElement.hasAttribute('data-modrinth-muted')) {
mediaElement.addEventListener('volumechange', () => muteVideo(mediaElement))

mediaElement.setAttribute('data-modrinth-muted', 'true')
}
})
}

document.addEventListener('DOMContentLoaded', () => {
muteVideos()
muteAudioContext()

const observer = new MutationObserver(muteVideos)
observer.observe(document.body, { childList: true, subtree: true })
})
2 changes: 1 addition & 1 deletion apps/app/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
]
},
"productName": "Modrinth App",
"version": "0.8.8",
"version": "0.8.9",
"mainBinaryName": "Modrinth App",
"identifier": "ModrinthApp",
"plugins": {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "theseus"
version = "0.8.8"
version = "0.8.9"
authors = ["Jai A <[email protected]>"]
edition = "2021"

Expand Down

0 comments on commit fce516a

Please sign in to comment.