Nitorita

JPopSuki Script

Apr 17th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. /* global $, jQuery */
  2. // ==UserScript==
  3. // @name JPopSuki Folder Name Formatter
  4. // @author Nitori
  5. // @description Automatically formats and copies to clipboard the appropriate folder name
  6. // @include *jpopsuki.eu/torrents.php?id=*
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  8. // @version 1.0
  9. // ==/UserScript==
  10. //-----------------------------------------------------------
  11. this.$ = this.jQuery = jQuery.noConflict(true); // Avoid duplicate jQuery conflict
  12. //-----------------------------------------------------------
  13. function copyToClipboard (str) {
  14. var el = document.createElement('textarea');
  15. el.value = str;
  16. el.setAttribute('readonly', '');
  17. el.style = {position: 'absolute', left: '-9999px'};
  18. document.body.appendChild(el);
  19. el.select();
  20. document.execCommand('copy');
  21. document.body.removeChild(el);
  22. }
  23.  
  24. $(function() {
  25. //-----------------------------------------------------------
  26. // Artist Name
  27. var artistName = $(".thin h2").text();
  28. artistName = artistName.substr(artistName.indexOf(' ')+1);
  29. artistName = artistName.substr(0, artistName.indexOf(' -'));
  30.  
  31. // Album Name
  32. var origName;
  33. if ($(".thin > h3").text().indexOf("-") > 0) {
  34. origName = $(".thin > h3").text();
  35. origName = origName.substr(origName.indexOf('-')+2).slice(0, -1);
  36. } else {
  37. origName = $(".thin h2").text();
  38. origName = origName.substr(origName.indexOf('-')+2);
  39. origName = origName.substr(0, origName.indexOf(' ['));
  40. }
  41.  
  42. // Release Date
  43. var rlsDate = $(".thin h2").text();
  44. rlsDate = rlsDate.substr(rlsDate.indexOf(' [')+1);
  45.  
  46. // Replace original title with fixed title
  47. var artistURL = $(".thin h2 a").attr("href"); // Fetch the artist URL before replacing the line
  48. $(".thin h2").html('<a href="'+ artistURL + '">' + artistName + '</a> - ' + origName + ' ' + rlsDate);
  49. $(".thin > h3").hide(); // Might as well hide the original title
  50.  
  51. // Automatically copy formatted folder name to clipboard on download
  52. $(".group_torrent a").click(function() {
  53. var folderName = artistName + " - " + origName + " " + rlsDate;
  54.  
  55. // Check what format it is from a list of known formats, and append to name
  56. var fileFormat = $(this).parent().parent().children("a").text();
  57. if (fileFormat.indexOf("MP3") > 0 && fileFormat.indexOf("320") > 0) {
  58. folderName += " [MP3]";
  59. } else if (fileFormat.indexOf("MP3") > 0 && fileFormat.indexOf("V0") > 0) {
  60. folderName += " [MP3 V0]";
  61. } else if (fileFormat.indexOf("FLAC") > 0) {
  62. folderName += " [FLAC]";
  63. } else if (fileFormat.indexOf("AAC") > 0 && fileFormat.indexOf("320") > 0) {
  64. folderName += " [AAC 320]";
  65. } else if (fileFormat.indexOf("AAC") > 0 && fileFormat.indexOf("256") > 0) {
  66. folderName += " [AAC 256]";
  67. }
  68.  
  69. // Copy it to the clipboard
  70. console.log(folderName);
  71. copyToClipboard(folderName);
  72. });
  73. //-----------------------------------------------------------
  74. })
Advertisement
Add Comment
Please, Sign In to add comment