Skip to content

Commit

Permalink
with toastr notifs
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangts committed Sep 10, 2020
1 parent 321dec0 commit a8051ea
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
4 changes: 4 additions & 0 deletions css/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#toast-container .cool-toast {
background-color: #333;
opacity: 0.9;
}
1 change: 1 addition & 0 deletions css/toastr.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions js/toastr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
"matches": [
"<all_urls>"
],
"css": [
"css/toastr.min.css",
"css/index.css"
],
"js": [
"js/jquery-2.2.4.min.js",
"js/mousetrap.min.js",
"js/toastr.min.js",
"src/inject/index.js"
]
}
Expand Down
35 changes: 32 additions & 3 deletions src/inject/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,66 @@ $(() => {
medias = $('video, audio')
}, 333)

const fmtMSS = s => {
s = Math.round(s)
return (s-(s%=60))/60+(9<s?':':':0')+s
}
const notify = (msg) => {
toastr.remove()
toastr.info('', msg, {
showDuration: 100,
hideDuration: 100,
positionClass: 'toast-top-center',
toastClass: 'cool-toast',
timeOut: 1000,
// timeOut: 0,
// extendedTimeOut: 0,
})
}


const togglePlayPause = () => async e => {
let media = lastPlayed || medias[0]
if(!media) return
if(media.paused) await media.play()
else media.pause()
if(media.paused) {
await media.play()
notify(`Play (${fmtMSS(media.duration - media.currentTime)} remaining)`)
}
else {
media.pause()
notify(`Pause (${fmtMSS(media.duration - media.currentTime)} remaining)`)
}
}

const jump = (sec) => async e => {
let media = lastPlayed || medias[0]
if(!media) return
media.currentTime += sec
notify(`Time: ${fmtMSS(media.currentTime)} / ${fmtMSS(media.duration)}`)
}

const playbackRate = (rate) => async e => {
let media = lastPlayed || medias[0]
if(!media) return
media.playbackRate += rate
notify(`Rate: ${media.playbackRate}x`)
}

const seekPercent = (percent) => async e => {
let media = lastPlayed || medias[0]
if(!media) return
media.currentTime = media.duration * percent / 100
notify(`Time: ${fmtMSS(media.currentTime)} / ${fmtMSS(media.duration)}`)
}

const toggleMute = () => async e => {
let media = lastPlayed || medias[0]
if(!media) return
media.muted = !media.muted
notify(media.muted ? 'Muted' : 'Unmuted')
}

hotkeys['space'] = togglePlayPause();
// hotkeys['space'] = togglePlayPause();
hotkeys['k'] = togglePlayPause();
hotkeys['j'] = jump(-10);
hotkeys['l'] = jump(10);
Expand All @@ -54,6 +82,7 @@ $(() => {
Mousetrap.bind('ctrl+m', () => {
mm = !mm
mm ? bindAll() : unbindAll()
notify(mm ? 'Media hotkeys on' : 'Media hotkeys off')
});

const bindAll = () => {
Expand Down

0 comments on commit a8051ea

Please sign in to comment.