This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbrowser.js
158 lines (128 loc) · 5.04 KB
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const electron = require("electron")
const ipc = electron.ipcRenderer
const storage = electron.remote.require("./storage")
// const NativeNotification = Notification
// Notification = (title, options) => {
// const notification = new NativeNotification(title, options)
// notification.addEventListener('click', () => {
// ipc.send('notification-click')
// })
//
// return notification
// }
//
// Notification.prototype = NativeNotification.prototype
// Notification.permission = NativeNotification.permission
// Notification.requestPermission = NativeNotification.requestPermission.bind(Notification)
class Overcast {
constructor(options){
this.elements = {}
this.templates = {}
this.elements.player = document.querySelector("audio")
this.elements.coverart = document.querySelector(".fullart_container .art")
this.elements.episodecell = document.querySelectorAll(".episodecell")
this.elements.styles = document.querySelectorAll("link[rel='stylesheet']")
this.elements.count = this.elements.episodecell.length > 0 ? this.elements.episodecell.length : storage.get("active-episodes")
this.templates = {
tabs: "<ul class='mainListTabs'><li><a class='active' href='#episodecell'>All active episodes</a></li><li><a href='#feedcell'>Your podcasts</a></li></ul>",
back: "<svg viewBox='0 0 16 16'><path class='path1' d='M9 2.5v5l5-5v11l-5-5v5l-5.5-5.5z'></path></svg>",
play: "<svg viewBox='0 0 16 16'><path class='path1' d='M3 2l10 6-10 6z'></path></svg>",
forward: "<svg viewBox='0 0 16 16'><path class='path1' d='M8 13.5v-5l-5 5v-11l5 5v-5l5.5 5.5z'></path></svg>"
}
// this.removeStylesheets(this.elements.styles)
// we're on listing
if (document.location.href.indexOf("/podcasts") >= 0){
this.podcastsList()
}
// update dock badge on each screen
ipc.send("update-badge", {
count: this.elements.count
})
this.player()
}
createElements(htmlStr){
let frag = document.createDocumentFragment(),
temp = document.createElement("div")
temp.innerHTML = htmlStr
while (temp.firstChild){
frag.appendChild(temp.firstChild)
}
return frag
}
removeStylesheets(styles){
let i
for (i = 0; i < styles.length; ++i){
let element = styles[i]
element.parentNode.removeChild(element)
}
}
player(){
if (this.elements.coverart){
this.addCoverart()
}
if (this.elements.player){
this.replacePlayerButtons()
}
}
replacePlayerButtons(){
let seekbackbutton = document.querySelector("#seekbackbutton")
let seekforwardbutton = document.querySelector("#seekforwardbutton")
seekbackbutton.innerHTML = this.templates.back
seekforwardbutton.innerHTML = this.templates.forward
this.elements.player.addEventListener("play", () => {
this.elements.coverart.classList.add("playing")
this.elements.shadowart.classList.add("playing")
})
this.elements.player.addEventListener("pause", () => {
this.elements.coverart.classList.remove("playing")
this.elements.shadowart.classList.remove("playing")
})
}
addCoverart(){
// inject shadow art
this.elements.shadowart = document.createElement("img")
this.elements.shadowart.src = this.elements.coverart.src
this.elements.shadowart.className = "shadowart"
this.elements.coverart.parentNode.appendChild(this.elements.shadowart)
// inject background art
let backgroundart = document.createElement("div")
backgroundart.style.backgroundImage = `url(${this.elements.coverart.src})`
backgroundart.className = "backgroundart"
this.elements.coverart.parentNode.appendChild(backgroundart)
}
podcastsList(){
document.body.appendChild(this.createElements(this.templates.tabs))
document.body.classList.add("page_podcasts")
let tabs = document.querySelectorAll(".mainListTabs a")
let i
for (i = 0; i < tabs.length; ++i){
tabs[i].addEventListener("click", (event) => {
event.preventDefault()
event.stopPropagation()
tabs[0].classList.remove("active")
tabs[1].classList.remove("active")
event.toElement.classList.add("active")
// hide all episodes and podcasts
let allcells = document.querySelectorAll(".episodecell, .feedcell")
let ii
for (ii = 0; ii < allcells.length; ++ii){
allcells[ii].classList.remove("visible")
}
// only show episodes or podcast, depending on the tab active
this.showElements(event.toElement.href.split("#")[1])
})
}
this.showElements("episodecell")
// store the active episodes count for other screens that have
// no access to that info
storage.set("active-episodes", this.elements.count);
}
showElements(selector){
let elements = document.querySelectorAll(`.${selector}`)
let i
for (i = 0; i < elements.length; ++i){
elements[i].classList.add("visible")
}
}
}
document.addEventListener("DOMContentLoaded", (event) => new Overcast())