Skip to content

Instantly share code, notes, and snippets.

@jespertheend
Last active July 15, 2020 20:37
Show Gist options
  • Save jespertheend/5f892fa6ffb10450206a972f30df5567 to your computer and use it in GitHub Desktop.
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
(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