BTW, there is a lot of boilerplate in the code, but the actual interesting part is quite simple, except a few quirks:
https://github.com/rugk/googerteller/blob/c10981574a4876fd1426a28d605e5f162409238b/src/background/modules/SoundModule.js
Top-level
BTW, there is a lot of boilerplate in the code, but the actual interesting part is quite simple, except a few quirks: 13 comments
Problem 2: Parsing a JSON is a thing JS is made for, so that's simple enough, but checking subnets is not. Stackoverflow questions basically are all like “come on, learn that thing and implement it yourself”, but a) as a dev you should know that this is certainly a step to use a library, especially given that b) I really really do not want to care thinking about parsing IPv6 IPs now. Fortunately I found a nice subnet checking library by @natevancouver Problem 3: However, having a list of IPs and access to web requests (the listener is simple) is not enough. As browsers are too high-level, we only get the URL/domain here. However, we need to get the IP here. Fortunately Firefox (only!) has an API: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/dns/resolve Problem 4: Having all that, we should be done, should not we? Well… no! I still hear nothing! Playing a sound was surprisingly difficult, given browsers usually now limit that websites (browser extensions are basically websites) should not play a random sound out of nowhere. I am still trying here, but depending on how you load the sound file, you may end up getting weird errors. The worst thing is that you need to copy the sound element to have multiple sound effects starting at the same time, so they can overlap each other. All in all, note that due to the way ad blockers are/will be handled in Chrome, some of these things I did will not be possible. This includes modifying by injecting a header + the DNS API is not even there in Chrome. For what this means, check out this: (Thread is a response to https://twitter.com/bert_hu_bert/status/1561650689474011136, who made the same thing as a C app that works across applications.) @rugk where are you loading your sound and what codec are you using? I found that using some codecs will not work out of the box on all OSes when playing in the background page for https://github.com/freaktechnik/notification-sounds @rugk it should allow you to read repsonses even without cors, see also https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions |
Problem 1: I wanted to load the IP ranges directly from the gstatic server, so the result is up-to-date.
However, the server does not set the header for cross-origin requests (CORS), so I had to use the power of a browser extension to actually inject it:
https://github.com/rugk/googerteller/blob/v0.1/src/background/modules/GStaticCorsFaker.js