Last active
September 15, 2018 06:43
-
-
Save pacochi/a4bc2c8014086dcf5b9cadb1a03050a4 to your computer and use it in GitHub Desktop.
Mastodon の通知音カスタマイズ例。
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
// ==UserScript== | |
// @name [:don:] boop → "erait!" | |
// @namespace hen.acho.co | |
// @version 0.180915 | |
// @description Proxy Audio sample | |
// @author pacochi | |
// @include https://mstdn.maud.io/web/* | |
// @run-at document-start | |
// @downloadURL https://gist.github.com/pacochi/a4bc2c8014086dcf5b9cadb1a03050a4/raw/mastodon_boop_erait.user.js | |
// @grant none | |
// ==/UserScript== | |
(() => { | |
'use strict'; | |
Audio = new Proxy(Audio, { construct: (target, url) => { | |
const audio = Reflect.construct(target, url); | |
audio.addEventListener('loadeddata', e => { | |
if (audio.firstChild.src.includes('boop') && !audio.src.includes('erait')) { | |
// ほんとに使うなら canPlayType とか見た方がいいと思う | |
audio.src = 'https://hen.acho.co/files/erait.ogg'; | |
audio.load(); | |
} | |
/* | |
// こゆ書き方しよーとしたけどそんなん反映されないよってされた | |
audio.childNodes.forEach((node, i, m) => { | |
m = node.src.match(/^.+boop(\.\w+)$/); | |
if (m) { | |
node.src = 'https://hen.acho.co/files/erait' + m[1]; | |
if (i) audio.load(); | |
} | |
}) | |
*/ | |
}); | |
return audio; | |
} }); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment