Crunchyroll Queue Fixer

fixes for crunchyroll queue page. put shows with new episodes at top; always show "no image" icon on shows with no new episodes.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name          Crunchyroll Queue Fixer
// @namespace     http://myanimelist.net/profile/mysticflute
// @description   fixes for crunchyroll queue page. put shows with new episodes at top; always show "no image" icon on shows with no new episodes.
// @match         https://www.crunchyroll.com/home/queue*
// @version       0.6
// @copyright     2013
// ==/UserScript==

(function() {
  // options
  var rearrange = true;
  var fixIcon = true;
  var minPercentage = 70;
  // var noImageUrl = "http://static.ak.crunchyroll.com/i/coming_soon_beta_wide.jpg";
  var noImageUrl = "http://static.ak.crunchyroll.com/i/no_image_beta_wide.jpg";

  // check querystring for "noarrange"
  if (window.location.search.indexOf("?no") > -1) {
    rearrange = false;
  }

  // actual work
  var queued = document.querySelectorAll("#main_content li.queue-item");
  var toMove = [];

  for (var i = 0, len = queued.length; i < len; i++) {
    var item = queued[i];
    var img = item.querySelector("img");
    var progress = item.querySelector(".episode-progress[style]");

    if (!progress) continue;

    var percentage = parseInt(progress.style.width, 10);

    if (fixIcon && img && img.src !== noImageUrl && percentage > minPercentage) {
      img.src = noImageUrl;
      progress.style.backgroundColor = "#ccc";
    }

    var isPlaceholder = (percentage === 0 && (img.src === noImageUrl));

    if (rearrange && !isPlaceholder && percentage < minPercentage && img.src !== noImageUrl) {
      toMove.push(item);
    }
  }

  if (rearrange) {
    toMove.reverse();
    for (var i = 0, len = toMove.length; i < len; i++) {
      var parent = toMove[i].parentNode;
      parent.insertBefore(toMove[i], parent.firstChild);
    }
  }
})();