Skip to content

Commit e399de5

Browse files
authored
Merge pull request #37 from alextnull/development
Ability to download old courses. Minor edits.
2 parents 1e6b748 + 8223260 commit e399de5

File tree

4 files changed

+143
-45
lines changed

4 files changed

+143
-45
lines changed

src/popup.css

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,38 @@ label > span {
266266
color: var(--psColorsBone);
267267
}
268268

269+
.coursetype {
270+
align-items: center;
271+
}
272+
.coursetype__label {
273+
text-transform: uppercase;
274+
font-weight: var(--psTypeFontWeightBold);
275+
flex-grow: 1;
276+
}
277+
278+
.coursetype {}
279+
.coursetype > section {}
280+
.coursetype > section:not(:last-child) {
281+
border-bottom: 1px solid var(--psColorsBorderHighOnDark);
282+
padding-bottom: var(--psLayoutSpacingSmall);
283+
margin-bottom: var(--psLayoutSpacingSmall);
284+
}
285+
.coursetype select {
286+
width: 70%;
287+
color: var(--psColorsBone);
288+
background: var(--psColorsBackgroundDark3);
289+
padding: var(--psLayoutSpacingXXSmall) var(--psLayoutSpacingSmall);
290+
border-radius: var(--psLayoutSpacingXXSmall);
291+
}
292+
.CourseType__submit {
293+
margin-left: 2%;
294+
padding: var(--psLayoutSpacingXXSmall) var(--psLayoutSpacingMedium);
295+
border: none;
296+
background-color: var(--psColorsBlueBase);
297+
color: var(--psColorsBone);
298+
border-radius: var(--psLayoutSpacingXXSmall);
299+
}
300+
269301
.status {
270302
align-items: center;
271303
}
@@ -336,7 +368,30 @@ label > span {
336368
border-radius: var(--psLayoutSpacingXXSmall);
337369
}
338370

339-
.leading-zero { }
371+
.leadingzero {}
372+
.leadingzero > section {}
373+
.leadingzero > section:not(:last-child) {
374+
border-bottom: 1px solid var(--psColorsBorderHighOnDark);
375+
padding-bottom: var(--psLayoutSpacingSmall);
376+
margin-bottom: var(--psLayoutSpacingSmall);
377+
}
378+
.leadingzero select {
379+
width: 100%;
380+
color: var(--psColorsBone);
381+
background: var(--psColorsBackgroundDark3);
382+
padding: var(--psLayoutSpacingXXSmall) var(--psLayoutSpacingSmall);
383+
border-radius: var(--psLayoutSpacingXXSmall)
384+
}
385+
.leading-zero {
386+
width: 80%;
387+
}
388+
.leading-zero__submit {
389+
padding: var(--psLayoutSpacingXXSmall) var(--psLayoutSpacingMedium);
390+
border: none;
391+
background-color: var(--psColorsBlueBase);
392+
color: var(--psColorsBone);
393+
border-radius: var(--psLayoutSpacingXXSmall);
394+
}
340395
.leading-zero__label { }
341396

342397
.subtitle { }

src/popup.html

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
</head>
77
<body>
88
<main>
9+
<section class="coursetype">
10+
<label class="coursetype__label">
11+
Course Type:
12+
</label>
13+
<select id="CourseType" name="Course Type" class="CourseType__select">
14+
<option value="Latest">Latest</option>
15+
<option value="Old">Old</option>
16+
</select>
17+
<button
18+
id="btnApplyCourseType"
19+
class="CourseType__submit"
20+
>
21+
Apply
22+
</button>
23+
</section>
924
<section class="status">
1025
<label class="status__label">
1126
STATUS:
@@ -49,32 +64,20 @@
4964
</div>
5065
</section>
5166
</section>
52-
<section class="leading-zero">
53-
<input type="hidden" id="isAlwaysLeadingZero" name="Is Always Leading Zero" value="false" />
54-
<label id="label_LeadingZeroText" class="leading-zero__label"> Leading Zero: </label>
55-
<div>
56-
<input
57-
type="radio"
58-
id="btnAlwaysLeadingZero"
59-
name="Always Leading Zero"
60-
class="leading-zero--always-input"
61-
value="true"
62-
/>
63-
<label id="label_leadingZero" class="leading-zero__always-label" for="btnAlwaysLeadingZero">Always</label>
64-
</div>
65-
<div>
66-
<input
67-
type="radio"
68-
id="btnMoreTenLeadingZero"
69-
name="Always Leading Zero"
70-
class="leading-zero__mt10-input"
71-
value="false"
72-
checked
73-
/>
74-
<label id="label_leadingZero" for="btnMoreTenLeadingZero" class="leading-zero__mt10-label">
75-
10 files or more
76-
</label>
77-
</div>
67+
<section class="leadingzero">
68+
<section class="leading-zero">
69+
<label id="label_LeadingZeroText" class="leading-zero__label"> Leading Zero: </label>
70+
<select id="isAlwaysLeadingZero" name="Is Always Leading Zero" class="always-leading-zero__select">
71+
<option value="false">10 files or more</option>
72+
<option value="true">Always</option>
73+
</select>
74+
</section>
75+
<button
76+
id="btnApplyLeadingZero"
77+
class="leading-zero__submit"
78+
>
79+
Apply
80+
</button>
7881
</section>
7982
<section class="subtitle">
8083
<section class="primary-subtitle">
@@ -201,7 +204,7 @@
201204
</section>
202205
</section>
203206
<section class="download">
204-
<button id="btnDwnAll" class="download__all">
207+
<button id="btnDwnAll" class="download__all" title="Download All">
205208
<svg xmlns="http://www.w3.org/2000/svg">
206209
<g>
207210
<path id="svg_1" d="m11.2,16.6c0.4,0.5 1.2,0.5 1.6,0l6,-6.3c0.5,-0.5 0,-1.3 -0.8,-1.3l-4,0c0,0 0.2,-4.6 0,-7c-0.1,-1.1 -0.9,-2 -2,-2c-1.1,0 -1.9,0.9 -2,2c-0.2,2.3 0,7 0,7l-4,0c-0.8,0 -1.3,0.8 -0.8,1.4l6,6.2z"/>
@@ -210,7 +213,7 @@
210213
</g>
211214
</svg>
212215
</button>
213-
<button id="btnDwnCur" class="download__current">
216+
<button id="btnDwnCur" class="download__current" title="Download Current">
214217
<svg
215218
version="1.1"
216219
xml:space="preserve"
@@ -228,7 +231,7 @@
228231
</g>
229232
</svg>
230233
</button>
231-
<button id="btnAddCourse" class="download__add-course">
234+
<button id="btnAddCourse" class="download__add-course" title="Add Course">
232235
<svg
233236
viewBox="0 0 48 48"
234237
xml:space="preserve"
@@ -239,21 +242,20 @@
239242
<path d="M0 0h48v48H0z" fill="none" />
240243
</svg>
241244
</button>
242-
<button id="btnSkip" class="download__skip-video">
245+
<button id="btnSkip" class="download__skip-video" title="Skip">
243246
<svg
244247
viewBox="0 0 24 24"
245248
xml:space="preserve"
246249
xmlns="http://www.w3.org/2000/svg"
247250
xmlns:xlink="http://www.w3.org/1999/xlink"
248251
>
249-
<title />
250252
<path
251253
d="M16,12a1,1,0,0,1-.47.85l-8,5A1,1,0,0,1,7,18a.91.91,0,0,1-.48-.13A1,1,0,0,1,6,17V7a1,1,0,0,1,1.53-.85l8,5A1,1,0,0,1,16,12Z"
252254
/>
253255
<rect height="12" width="2" x="17" y="6" />
254256
</svg>
255257
</button>
256-
<button id="btnStop" class="download__stop">
258+
<button id="btnStop" class="download__stop" title="Stop">
257259
<svg
258260
baseProfile="tiny"
259261
height="24px"

src/popup.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,21 @@ let secondaryLanguage = document.getElementById('SecondaryLanguage')
2727
let btnApplySecondaryLanguage = document.getElementById('btnApplySecondaryLanguage')
2828

2929
let isAlwaysLeadingZero = document.getElementById('isAlwaysLeadingZero')
30-
let btnAlwaysLeadingZero = document.getElementById('btnAlwaysLeadingZero')
31-
let btnMoreTenLeadingZero = document.getElementById('btnMoreTenLeadingZero')
30+
let btnApplyLeadingZero = document.getElementById('btnApplyLeadingZero')
31+
32+
let courseType = document.getElementById('CourseType');
33+
let btnApplyCourseType = document.getElementById('btnApplyCourseType')
34+
35+
chrome.storage.sync.get('courseType', function(data) {
36+
courseType.value = data.courseType !== undefined ? data.courseType : 'Latest'
37+
})
38+
39+
chrome.storage.sync.get('isAlwaysLeadingZero', function(data) {
40+
isAlwaysLeadingZero.value = data.secondaryLanguage !== undefined ? data.isAlwaysLeadingZero : 'false'
41+
})
3242

3343
chrome.storage.sync.get('isAlwaysLeadingZero', function(data) {
34-
isAlwaysLeadingZero.value = data.isAlwaysLeadingZero
44+
isAlwaysLeadingZero.value = data.secondaryLanguage !== undefined ? data.isAlwaysLeadingZero : 'false'
3545
})
3646

3747
chrome.storage.sync.get('secondaryLanguage', function(data) {
@@ -67,12 +77,12 @@ chrome.storage.sync.get('AddedCourseCount', function(data) {
6777
addedCourseCntLabel.innerHTML = data.AddedCourseCount
6878
})
6979

70-
btnAlwaysLeadingZero.onclick = function() {
71-
chrome.storage.sync.set({ isAlwaysLeadingZero: btnAlwaysLeadingZero.value }, undefined)
80+
btnApplyCourseType.onclick = function() {
81+
chrome.storage.sync.set({ courseType: courseType.value }, undefined)
7282
}
7383

74-
btnMoreTenLeadingZero.onclick = function() {
75-
chrome.storage.sync.set({ isAlwaysLeadingZero: btnMoreTenLeadingZero.value }, undefined)
84+
btnApplyLeadingZero.onclick = function() {
85+
chrome.storage.sync.set({ isAlwaysLeadingZero: isAlwaysLeadingZero.value }, undefined)
7686
}
7787

7888
btnApplySecondaryLanguage.onclick = function() {

src/script.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const EXTENSION = 'mp4'
1111
const EXTENSION_SUBS = 'vtt'
1212

1313
const qualities = ['1280x720', '1024x768']
14-
const DEFAULT_QUALITY = qualities[0]
1514

1615
const DOWNLOAD_TIMEOUT = 3000
1716
let DURATION_PERCENT = 10 // percent max 100
@@ -111,7 +110,15 @@ const readAddedCourses = () => readSharedValue('AddedCourses')
111110

112111
const readSecondaryLanguageCode = () => readSharedValue('secondaryLanguage')
113112

114-
const readIsLeadingZeroAlways = () => readSharedValue('isAlwaysLeadingZero')
113+
const readIsLeadingZeroAlways = () => {
114+
let isAlwaysLeadingZero = readSharedValue('isAlwaysLeadingZero')
115+
if (isAlwaysLeadingZero === 'true') {
116+
return true;
117+
}
118+
return false;
119+
}
120+
121+
const readCourseType = () => readSharedValue('courseType')
115122

116123
const log = (message, type = 'STATUS') => console.log(`[${APPNAME}]:[${type}]: ${message}`)
117124

@@ -133,8 +140,26 @@ const replaceQuotesWithSquareBrackets = name => {
133140
return newName
134141
}
135142

136-
const removeInvalidCharacters = name =>
137-
replaceQuotesWithSquareBrackets(name).replace(INVALID_CHARACTERS, '').replace(':', ' -').trim()
143+
const replaceColonsWithHyphen = name => {
144+
let newName = name[0]
145+
for (let i = 1; i < name.length - 1; i++) {
146+
if (name[i - 1] !== ' ' && name[i] === ':' && name[i + 1] !== ' ') {
147+
newName += '-'
148+
}
149+
else {
150+
newName += name[i]
151+
}
152+
}
153+
newName += name[name.length - 1]
154+
newName = newName.replace(':', ' -')
155+
return newName
156+
}
157+
158+
const removeInvalidCharacters = name => {
159+
let clearedName = replaceQuotesWithSquareBrackets(name);
160+
clearedName = replaceColonsWithHyphen(clearedName).replace(INVALID_CHARACTERS, '').trim();
161+
return clearedName
162+
}
138163

139164
const getCurrentVideoId = () => {
140165
const vIdMatch = location.search.match('clipId=?([0-9a-f-]*)')
@@ -145,6 +170,11 @@ const getCurrentVideoId = () => {
145170
// END:UTILITIES
146171
// ====================================================================
147172

173+
const getQuality = async () => {
174+
const courseType = await readCourseType();
175+
return courseType === "Old" ? qualities[1] : qualities[0];
176+
}
177+
148178
const getDirectoryName = (sectionIndex, sectionName, bPadding = false) => {
149179
let padIndex = `${sectionIndex + 1}`
150180
if (bPadding) {
@@ -163,6 +193,7 @@ const getFileName = (videoIndex, videoName, bPadding = false) => {
163193

164194
const getVideoURL = async videoId => {
165195
try {
196+
const quality = await getQuality();
166197
const response = await fetch(viewclipURL, {
167198
method: 'POST',
168199
headers: {
@@ -171,7 +202,7 @@ const getVideoURL = async videoId => {
171202
body: JSON.stringify({
172203
clipId: videoId,
173204
mediaType: EXTENSION,
174-
quality: DEFAULT_QUALITY,
205+
quality: quality,
175206
online: true,
176207
boundedContext: 'course',
177208
versionId: '',

0 commit comments

Comments
 (0)