Export Posted DVDs

Exports a CSV of the current page of your DVD Tower listing in Swap-a-DVD

  1. // ==UserScript==
  2. // @name Export Posted DVDs
  3. // @namespace Swap-a-DVD
  4. // @version 0.1
  5. // @description Exports a CSV of the current page of your DVD Tower listing in Swap-a-DVD
  6. // @author You
  7. // @match https://www.swapadvd.com/members/posted_dvds.php*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=swapadvd.com
  9. // @grant none
  10. // @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js
  11. // @license FSFAP
  12. // ==/UserScript==
  13. /* eslint-disable */
  14.  
  15. collection_name = 'swapadvd_inventory_page_' + $('select:first option:selected').text()
  16. filename_array = [];
  17. var csvContent = "data:text/csv;charset=utf-8,";
  18.  
  19. $target = $('#frm1').children('table').children('tbody').children().find('.display_dvd_table:first tr');
  20.  
  21. count = $target.length;
  22. console.log(count);
  23. scrape_dvds(count);
  24.  
  25. function scrape_dvds(count){
  26. $(this).find('.dvd_title');
  27. $target.each(function( index ) {
  28. console.log();
  29. title = $(this).find('.dvd_title').text().trim().replace((/ |\,|\t|\r\n|\n|\r/gm),"").replace('&','and');
  30. url = $(this).find('.dvd_title a').attr("href");
  31. posted_raw = $(this).find('.display_dvd_text').text().split('Posted: ')[1].split(' ET')[0];
  32. cover_art = $(this).find('.dvd_image').attr("src");
  33. posted = moment(posted_raw,'L LT');
  34. posted_formatted = posted.format('YYYY-MM-DD hh:mm a');
  35.  
  36. raw_listing = title + "," + url + "," + posted_formatted + "," + cover_art;
  37. if (title !== ''){
  38. filename_array.push(raw_listing);
  39. }
  40. count--;
  41. if (count == 0){
  42. do_export(filename_array);
  43. }
  44. });
  45. }
  46.  
  47. function do_export(fancy){
  48. var csvRows = [];
  49. var csvString = fancy.join("\n");
  50. csvString = csvString + "\n";
  51. var a = document.createElement('a');
  52. a.href = 'data:attachment/csv;charset=utf-8,%EF%BB%BF' + encodeURIComponent(csvString);
  53. a.target = '_blank';
  54. a.download = collection_name+'.csv';
  55.  
  56. document.body.appendChild(a);
  57. a.click();
  58. }