BCPop

Filter bandcamp user collections by popularity

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        BCPop
// @author      theinternetftw
// @namespace   theinternetftw.com
// @description Filter bandcamp user collections by popularity
// @license     GPL version 2 or any later version; http://www.gnu.org/licenses/gpl-2.0.txt
// @include     https://bandcamp.com/*
// @version     1.0
// @grant       none
// ==/UserScript==

var defaultThreshold = 0;
var rangeLimit = 1000;

var visUpdateInterval = 100; // ms
var ajaxUpdateInterval = 2500; // ms, for bc's lazy loading

var isPopular = function($item) {
  if (threshold === 0)
    return true;
  if (!$item.has('.collected-by-header').length)
    return false;
  var collectors = $item.find('.collected-by-header').find('a').text().trim().split(' ')[0];
  return parseInt(collectors) >= threshold;
};

var updateVis = function() {
  $('.collection-item-container').has('.collection-item-fav-track').each(function() {
    var $item = $(this);
    isPopular($item) ? $item.show() : $item.hide();
  });
};

var updateControls = function() {
  $('#bcpop-threshold').text('BCPop: ' + threshold);
};

var threshold = defaultThreshold;
var everTouchedControls = false;
var shouldUpdateVis = false;

if ($('.fan-banner').length) {
  
  var input = document.createElement('input');
  input.type = 'range';
  input.max = rangeLimit;
  input.value = threshold;
  
  input.addEventListener('input', function(e) {
    everTouchedControls = true;
    shouldUpdateVis = true;
    threshold = e.target.value;
    updateControls();
  });
  
  var span = document.createElement('span');
  span.id = 'bcpop-threshold';
  span.style.fontSize = '8pt';
  
  var div = document.createElement('div');
  div.style.position = 'fixed';
  div.style.backgroundColor = 'white';
  div.style.bottom = 0;
  
  div.appendChild(input);
  div.appendChild(span);
  document.body.appendChild(div);
  
  // don't spam DOM updates
  setInterval(function() {
    if (shouldUpdateVis) {
      shouldUpdateVis = false;
      updateVis();
    }
  }, visUpdateInterval);
  
  // encorage bc to load more songs if you've touched the controls on this page
  setInterval(function() {
    everTouchedControls && $(window).scroll();
  }, ajaxUpdateInterval);
  
  var observer = new MutationObserver(function(mutation) {
    shouldUpdateVis = true;
  });
  observer.observe(document.body, {childList:true, subtree:true});

  updateControls();
  updateVis();
}