bcrawlink

Provides links to the raw media files for previews on bandcamp to get around preview listen limits. Also allows you to easily download the previews. >:)

  1. // ==UserScript==
  2. // @name bcrawlink
  3. // @description Provides links to the raw media files for previews on bandcamp to get around preview listen limits. Also allows you to easily download the previews. >:)
  4. // @license MIT License
  5. // @namespace com.bandcamp.benburrill.evil
  6. // @include *
  7. // @version 4
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // BTW, we run this on all sites because some bandcamp pages are not actually on bandcamp.org
  12.  
  13. function on_doc_ready(func) {
  14. if (document.readyState === "complete") {
  15. func(null);
  16. } else {
  17. document.addEventListener("DOMContentLoaded", func);
  18. }
  19. }
  20.  
  21. on_doc_ready(function() {
  22. window.TralbumData && TralbumData.trackinfo.forEach(function (track, index) {
  23. // I've only seen the mp3 type, but if there happen to be more, we want to
  24. // make links for all of them.
  25. track.file && Object.keys(track.file).forEach(function (media_type) {
  26. var cls = "raw-link-" + media_type;
  27. var base = "(tr,div)[rel=\"tracknum=" + (index + 1) + "\"]";
  28. var pref_child = "td.title-col";
  29.  
  30. // If possible, use the child pref_child instead of base.
  31. if ($(base).has(pref_child).length) base += ">" + pref_child;
  32.  
  33. $(base + ":not(:has(a." + cls + "))").each(function () {
  34. $(this).append("<a class=\"" + cls + "\" href=\"" + track.file[media_type] + "\" target=\"_blank\">\n " + media_type + "\n </a>");
  35. });
  36. });
  37. });
  38. });