Last active
March 11, 2024 23:51
-
-
Save jamesarmenta/8bbef9fe86574e0865cf992f074545be to your computer and use it in GitHub Desktop.
Dreaming Spanish Utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("DS USERSCRIPT IS RUNNING!"); | |
window.ds_download = () => { | |
document.querySelector('div.ds-video-options').children[0].children[0].click(); | |
setTimeout(() => { | |
const dropdown = document.querySelector('.ds-form-dropdown__item.dropdown-item'); | |
if (!dropdown.innerText.includes('Remove')) { | |
dropdown.click(); | |
} console.log('Foobar: Clicked to add to playlist!'); | |
}, 1000); | |
setTimeout(() => { | |
document.querySelector('iframe').contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}', '*'); | |
console.log('Foobar: Video paused!'); | |
}, 1000); | |
document.querySelector('.content-area').style.backgroundColor = 'yellow'; | |
document.querySelector('.ds-watch-page__video-downloads').children[0].click(); | |
setInterval(() => { | |
if (!document.querySelector('.Toastify__progress-bar')) { | |
document.querySelector('.content-area').style.backgroundColor = 'green'; | |
console.log('Foobar: Done!'); | |
document.title = 'DONE'; | |
} else { | |
document.querySelector('.content-area').style.backgroundColor = 'yellow'; | |
document.title = 'Downloading...'; | |
} | |
}, 1000); | |
} | |
const getId = (href) => { | |
const id = href.split('id=')[1]; | |
return id; | |
}; | |
const getTokenFromLocalStorage = () => { | |
const token = localStorage.getItem('token'); | |
return token; | |
}; | |
const markAsWatched = (id) => { | |
fetch("https://www.dreamingspanish.com/.netlify/functions/updatePlaylist", { | |
"headers": { | |
"accept": "*/*", | |
"accept-language": "en-US,en;q=0.9", | |
"authorization": "Bearer "+getTokenFromLocalStorage(), | |
"content-type": "text/plain;charset=UTF-8", | |
"sec-ch-ua": "\"Not A(Brand\";v=\"99\", \"Google Chrome\";v=\"121\", \"Chromium\";v=\"121\"", | |
"sec-ch-ua-mobile": "?0", | |
"sec-ch-ua-platform": "\"macOS\"", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin" | |
}, | |
"referrer": "https://www.dreamingspanish.com/library/videos", | |
"referrerPolicy": "strict-origin-when-cross-origin", | |
"body": `{"action":"delete","videoId":"${id}"}`, | |
"method": "POST", | |
"mode": "cors", | |
"credentials": "include" | |
}); | |
}; | |
window.ds_removeWatchedFromPlaylist = () => { | |
document.querySelectorAll('.ds-video-thumbnail__watched').forEach((el, idx) => { | |
const id = getId(el.parentElement.parentElement.parentElement.href); | |
const titleElement = el.parentElement.parentElement.querySelector('.ds-video-card__title'); | |
const name = titleElement.innerText; | |
setTimeout(() => { | |
// add text-decoration: line-through to titleElement | |
titleElement.style.textDecoration = 'line-through'; | |
console.log('Marking as watched...', name); | |
markAsWatched(id); | |
}, 1000 * idx); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment