Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- document.body.onload = function() {
- var URL_Playlist = new URL(location.href);
- var source_playlist_id = URL_Playlist.searchParams.get('list');
- var keyword_list = [];
- if (source_playlist_id) {
- if (!URL_Playlist.searchParams.get('disable_polymer')) {
- location.search += '&disable_polymer=1';
- }
- var session_token = document.getElementById('pl-video-list').getAttribute('data-like-xsrf-token');
- var input = document.createElement('input');
- input.id = 'file-input';
- input.type = 'file';
- input.accept = 'text/plain';
- if (!document.getElementById('file-input') && source_playlist_id && session_token) {
- document.getElementById('gh-banner').appendChild(input);
- console.log('Ready!!!');
- document.querySelector('#file-input').addEventListener('change', function(e) {
- // list of selected files
- var all_files = this.files;
- if (all_files.length == 0) {
- alert('Error : No file selected');
- return;
- }
- // first file selected by user
- var file = all_files[0];
- // files types allowed
- // we are reading text file in this example
- var allowed_types = ['text/plain'];
- if (allowed_types.indexOf(file.type) == -1) {
- alert('Error : Incorrect file type');
- return;
- }
- // Max 2 MB allowed
- var max_size_allowed = 2 * 1024 * 1024
- if (file.size > max_size_allowed) {
- alert('Error : Exceeded size 2MB');
- return;
- }
- // file validation is successful
- // we will now read the file
- const reader = new FileReader();
- reader.onload = function fileReadCompleted() {
- // when the reader is done, the content is in reader.result.
- keyword_list = reader.result.split('\n');
- if (!keyword_list.length) {
- alert('Keywords not found!');
- return false;
- }
- for (var i = 0, length = keyword_list.length; i < length; i++) {
- if (keyword_list[i] && keyword_list[i].trim().length) {
- let key = keyword_list[i].trim();
- var data = encodeURI('source_playlist_id=' + source_playlist_id + '&n=' + key + '&p=public&session_token=' + session_token);
- var xhttp = new XMLHttpRequest();
- xhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- console.log(this.responseText);
- }
- };
- xhttp.open('POST', 'https://www.youtube.com/playlist_ajax?action_create_playlist=1', true);
- xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
- xhttp.send(data);
- }
- }
- };
- reader.readAsText(this.files[0]);
- this.value = null;
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement