Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. document.body.onload = function() {
  2. var URL_Playlist = new URL(location.href);
  3. var source_playlist_id = URL_Playlist.searchParams.get('list');
  4. var keyword_list = [];
  5. if (source_playlist_id) {
  6. if (!URL_Playlist.searchParams.get('disable_polymer')) {
  7. location.search += '&disable_polymer=1';
  8. }
  9. var session_token = document.getElementById('pl-video-list').getAttribute('data-like-xsrf-token');
  10. var input = document.createElement('input');
  11. input.id = 'file-input';
  12. input.type = 'file';
  13. input.accept = 'text/plain';
  14. if (!document.getElementById('file-input') && source_playlist_id && session_token) {
  15. document.getElementById('gh-banner').appendChild(input);
  16. console.log('Ready!!!');
  17. document.querySelector('#file-input').addEventListener('change', function(e) {
  18. // list of selected files
  19. var all_files = this.files;
  20. if (all_files.length == 0) {
  21. alert('Error : No file selected');
  22. return;
  23. }
  24. // first file selected by user
  25. var file = all_files[0];
  26. // files types allowed
  27. // we are reading text file in this example
  28. var allowed_types = ['text/plain'];
  29. if (allowed_types.indexOf(file.type) == -1) {
  30. alert('Error : Incorrect file type');
  31. return;
  32. }
  33. // Max 2 MB allowed
  34. var max_size_allowed = 2 * 1024 * 1024
  35. if (file.size > max_size_allowed) {
  36. alert('Error : Exceeded size 2MB');
  37. return;
  38. }
  39. // file validation is successful
  40. // we will now read the file
  41. const reader = new FileReader();
  42. reader.onload = function fileReadCompleted() {
  43. // when the reader is done, the content is in reader.result.
  44. keyword_list = reader.result.split('\n');
  45. if (!keyword_list.length) {
  46. alert('Keywords not found!');
  47. return false;
  48. }
  49. for (var i = 0, length = keyword_list.length; i < length; i++) {
  50. if (keyword_list[i] && keyword_list[i].trim().length) {
  51. let key = keyword_list[i].trim();
  52. var data = encodeURI('source_playlist_id=' + source_playlist_id + '&n=' + key + '&p=public&session_token=' + session_token);
  53. var xhttp = new XMLHttpRequest();
  54. xhttp.onreadystatechange = function() {
  55. if (this.readyState == 4 && this.status == 200) {
  56. console.log(this.responseText);
  57. }
  58. };
  59. xhttp.open('POST', 'https://www.youtube.com/playlist_ajax?action_create_playlist=1', true);
  60. xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  61. xhttp.send(data);
  62. }
  63. }
  64. };
  65. reader.readAsText(this.files[0]);
  66. this.value = null;
  67. });
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement