Skip to content

Instantly share code, notes, and snippets.

View jgphilpott's full-sized avatar

Jacob Philpott jgphilpott

View GitHub Profile
@jgphilpott
jgphilpott / hearken.coffee
Last active September 14, 2023 14:48
A helpful interface for the SpeechRecognition class.
class Hearken
constructor: (args = lang: "en-US", interim: false, continuous: false, alternatives: 1) ->
args.lang ?= "en-US"
args.interim ?= false
args.continuous ?= false
args.alternatives ?= 1
# Help: https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognitionEvent
@jgphilpott
jgphilpott / geo.coffee
Created September 13, 2023 14:09
A helpful interface for the navigator geolocation object.
# Credit: https://www.w3schools.com/js/js_api_geolocation.asp
class Geo
constructor: ->
@location = navigator.geolocation
position: (callback = this.log) ->
@jgphilpott
jgphilpott / history.coffee
Last active September 13, 2023 14:00
A helpful interface for the window history object.
# Credit: https://www.w3schools.com/js/js_window_history.asp
class History
back: ->
return window.history.back()
forward: ->
@jgphilpott
jgphilpott / page.coffee
Last active September 13, 2023 14:00
A helpful interface for the window location object.
# Credit: https://www.w3schools.com/js/js_window_location.asp
class Page
constructor: ->
@url = window.location
href: ->
@jgphilpott
jgphilpott / popup.coffee
Last active September 13, 2023 13:59
A helpful interface for the window popup functions.
# Credit: https://www.w3schools.com/js/js_popup.asp
class Popup
constructor: ->
null
alert: (text = "") ->
@jgphilpott
jgphilpott / fullscreen.coffee
Created September 11, 2023 12:37
Functions for enabling, disabling and checking fullscreen mode.
# Credit: https://stackoverflow.com/a/65943962/1544937
activeFullScreen = ->
Boolean document.isFullScreen or document.fullscreenElement or document.webkitFullscreenElement or document.mozFullScreenElement or document.msFullscreenElement
openFullScreen = ->
if not activeFullScreen()
@jgphilpott
jgphilpott / utterance.js
Last active September 8, 2023 20:38
A helpful interface for the SpeechSynthesisUtterance class.
class Utterance {
constructor(args = {lang: "en-US", voice: "Alex", volume: 1, pitch: 1, rate: 1}) {
this.utterance = new SpeechSynthesisUtterance() // Help: https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance
this.synth = window.speechSynthesis // Help: https://developer.mozilla.org/en-US/docs/Web/API/Window/speechSynthesis
if (args.lang == null) args.lang = "en-US"
if (args.voice == null) args.voice = "Alex"
if (args.volume == null) args.volume = 1
@jgphilpott
jgphilpott / string.coffee
Last active September 20, 2023 13:34
A collection of JavaScript String prototype updates.
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
# Source: https://gist.github.com/jgphilpott/c4e0c275c808ae1a01386942dfc2a225
Object.defineProperty String.prototype, "lower",
value: ->
this.trim().toLowerCase()
@jgphilpott
jgphilpott / object.coffee
Last active September 20, 2023 13:32
A collection of JavaScript Object prototype updates.
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
# Source: https://gist.github.com/jgphilpott/8971e9e9760895d1a87ae58e5a740f11
Object.defineProperty Object.prototype, "attach",
value: (path, item) ->
this[path] = item
@jgphilpott
jgphilpott / boolean.coffee
Last active September 20, 2023 13:37
A collection of JavaScript Boolean prototype updates.
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
# Info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
# Source: https://gist.github.com/jgphilpott/a876171a09ce00e450d7f4325542d819
Object.defineProperty Boolean.prototype, "true",
value: ->
this is true