Created
January 29, 2025 02:49
-
-
Save giflw/b8b2e64c1100cec3610897475f979205 to your computer and use it in GitHub Desktop.
YouTube anonymous playlist simple generator
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
<!DOCTYPE html> | |
<body style="font-family: sans-serif;"> | |
<p> | |
<label> | |
Youtube URLs:<br> | |
<textarea id="input" style="box-sizing: content-box; width: 100%; min-height: 8em; line-height: 1.4em; padding: 0.2em"></textarea> | |
</label> | |
</p> | |
<p> | |
<label> | |
<input type="checkbox" id="removeDuplicates" /> Remove duplicates | |
</label> | |
</p> | |
<p> | |
<label> | |
Playlist URL:<br> | |
<input id="output" disabled style="box-sizing: border-box; width: 100%;" /> | |
</label> | |
</p> | |
<script> | |
const INPUT_LINE_HEIGHT = 1.4 // em | |
const INPUT_PADDING = 0.2 // em | |
const $input = document.getElementById('input') | |
const $output = document.getElementById('output') | |
const $removeDuplicates = document.getElementById('removeDuplicates') | |
const ytIdRx = /(?:youtube\.com\/(?:.*[?&]v=)|youtu\.be\/)(?<id>[^"&?\/\s]{11})/gi; | |
const update = () => { | |
let matches = Array.from($input.value.matchAll(ytIdRx)) | |
.map(([_, id]) => id) | |
console.log(matches) | |
if (matches.length === 0) { | |
matches = ['id1', 'id2', '...'] | |
} else if ($removeDuplicates.checked) { | |
matches = matches.filter( | |
(id, i) => matches.indexOf(id) === i | |
) | |
} | |
$output.value = `https://www.youtube.com/watch_videos?video_ids=${matches.join(',')}` | |
// resize input textarea | |
const lineCount = $input.value.match(/^/gm).length | |
$input.style.height = `${lineCount*INPUT_LINE_HEIGHT + 2*INPUT_PADDING}em` | |
} | |
$input.addEventListener('input', update) | |
$removeDuplicates.addEventListener('input', update) | |
update() | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment