Created
August 11, 2021 10:08
-
-
Save JakobTischler/326ff6ad5b34da681957f393e821206c to your computer and use it in GitHub Desktop.
Goes through defined seasons and sets their episodes' status to the wanted status.
This file contains hidden or 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
/** | |
* Delays the script execution for a specified amount of time. Returns a promise that gets resolved after `amount` ms. Must be called in an `async` function with `await`. | |
* @param {Number} amount The length in ms. Default: `1000`. | |
* @returns {Promise} The promise. | |
*/ | |
function sleep(amount = 1000) { | |
return new Promise((resolve) => { | |
setTimeout(resolve, amount); | |
}); | |
} | |
/** | |
* @param {Number} from - Number of start season. Default: `1`. | |
* @param {Number} until - Number of end season (including). Default: `20`. | |
* @param {('watched' | 'acquired' | 'skipped')} status - The desired status. Default: `watched`. | |
* @param {Boolean} [overwrite=false] - If an episode already has a status, `true` will overwrite it. `false` will skip the episode. Default: `false`. | |
* | |
*/ | |
async function setEpisodeStatus(from = 1, until = 20, status = 'watched', overwrite = false) { | |
console.group('Setting episode status', { from, until, status, overwrite }); | |
if (from > until) { | |
[from, until] = [until, from]; | |
} | |
for (let i = from; i <= until; i++) { | |
const header = document.querySelector(`#S${i.toString().padStart(2, '0')}`); | |
if (!header) continue; | |
const section = header.nextElementSibling; | |
if (!section) continue; | |
const tributtons = section.querySelectorAll('.tributton-watch'); | |
if (!tributtons) continue; | |
console.group('Season', i); | |
for (const [epIndex, tributton] of tributtons.entries()) { | |
if (tributton.querySelector) { | |
if (overwrite || !tributton.querySelector('.active')) { | |
const button = tributton.querySelector(`.${status}`); | |
if (button) { | |
if (!button.classList.contains('active')) { | |
button.click(); | |
console.log(`Episode ${epIndex} set to "${status}"`); | |
await sleep(500); | |
} else { | |
console.log(`Episode ${epIndex} is already set to "${status}"`); | |
} | |
} | |
} else { | |
console.log(`Episode`, epIndex); | |
} | |
} | |
} | |
console.groupEnd(); | |
} | |
console.log('ALL DONE'); | |
console.groupEnd(); | |
} | |
// Parameters: | |
// 1 = season from | |
// 2 = season until | |
// 3 = status ('watched' or 'acquired' or 'skipped') | |
// 4 = Overwrites the episode's current value. Default: `false` | |
setEpisodeStatus(1, 7, 'watched'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment