Last active
July 15, 2020 20:37
-
-
Save jespertheend/5f892fa6ffb10450206a972f30df5567 to your computer and use it in GitHub Desktop.
paste this in the browser console then drag an audio file to the page to replace the notification sound
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async function(){ | |
async function writeSound(cache, url){ | |
const el = document.createElement("div"); | |
document.body.appendChild(el); | |
el.style.background = "white"; | |
el.style.width = el.style.height = "100%"; | |
el.style.position = "absolute"; | |
el.style.zIndex = 1000; | |
el.textContent = "drag an audio file to this page"; | |
el.addEventListener("dragover", e => e.preventDefault()); | |
const file = await new Promise(resolve => { | |
el.addEventListener("drop", e => { | |
resolve(e.dataTransfer.files[0]); | |
}); | |
}); | |
const response = new Response(file); | |
cache.put(url, response); | |
el.textContent = "refresh the page to apply the changes"; | |
} | |
const cacheKeys = await caches.keys(); | |
for(const cacheKey of cacheKeys){ | |
const cache = await caches.open(cacheKey); | |
const keys = await cache.keys(); | |
for(const request of keys){ | |
if(/https?:\/\/web\.whatsapp\.com\/notification.*\.mp3/.exec(request.url)){ | |
await writeSound(cache, request.url) | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment