Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


Dump Udemy tabular

22 Apr 2022 »

expand all accordion

document.querySelectorAll('div[data-purpose^=section-panel-]').forEach(e => {
	console.log(e)
	var pt = e.querySelector('div[class^=panel--content-wrapper]').innerText
	console.log(pt.trim().substring(20))
	if (pt.trim() == ''){
		console.log('empty')
		e.querySelectorAll('div').forEach(d => {
			if (d.className.includes('panel--panel-toggler')){
				d.click()
			}
		})
	}
})

fetch all url links

var itemTitles = []
document.querySelectorAll('span[data-purpose="item-title"]').forEach(d => {
	itemTitles.push(d)
})
(function loop(idx){
	if (idx == itemTitles.length) return
	itemTitles[idx].click()
	setTimeout(() => {
		console.log('idx', idx)
		itemTitles[idx].setAttribute('linkto', window.location.href)
		loop(idx+1)
	}, 100)
})(0)

gen html

var mydb = {}
var checkbox = document.querySelectorAll('input[data-purpose="progress-toggle-button"]')
checkbox.forEach(e => {
	var p = e.parentElement.parentElement.parentElement
	if (p.className.includes('popper')){
		p = p.parentElement
	}
	var p0 = e.parentElement
	var linkto = p.querySelector('span[data-purpose=item-title]').getAttribute('linkto')
	console.log(linkto)
	var section = (function searchSection(d){
		console.log(d)
		if (d.getAttribute('data-purpose') && d.getAttribute('data-purpose').startsWith('section-panel-')){
			val = ""
			d.querySelectorAll('div').forEach(f => {
				if (f.className.includes('panel--panel-toggler')){
					val = f.innerText
				}
			})
			return val
		}
		return searchSection(d.parentElement)
	})(e)
	//console.log('section', section)
	section = section.replace("\n", " ")
	if (! mydb[section]) mydb[section] = []
	var lectureCompleted = p0.querySelector('span.udlite-sr-only').innerText
	var completed = lectureCompleted == 'Lecture completed' ? '[X]' : '[ ]'
	//console.log(lectureCompleted)
	console.log('p', p)
	var label = p.querySelector('div[class^=curriculum-item-link]')
	//console.log(label)
	//console.log(label.innerText)
	var lessonInfo = label.innerText.split("\n")
	var dur = lessonInfo[1] ? `(${lessonInfo[1]})` : ''
	mydb[section].push({
		text: `${lessonInfo[0]} ${dur}`,
		completed: completed,
		url: linkto
	})
})

mydb

var html = []
html.push('<style>a {color: blue;}</style>')
html.push('<div style="column-count:3;">')
html.push('<ul>')
for(let k in mydb){
	html.push('<li>')
	html.push(`${k}`)
	html.push('<ul>')
	for (let item of mydb[k]){
		html.push('<li>')
		html.push(`${item.completed} <a href="${item.url}" target="_blank">${item.text}</a>`)
		html.push('</li>')
	}
	html.push('</ul>')
}
html.push('</ul>')
html.push('</div>')
html = html.join("")
//window.open("data:text/html,"+escape(html), "_blank")
console.log("data:text/html,"+escape(html))