Greasy Fork

Random episode chooser

Highlight a random episode in homepage

目前为 2022-05-27 提交的版本。查看 最新版本

// ==UserScript==
// @name  Random episode chooser
// @description Highlight a random episode in homepage
// @match       https://www.tvtime.com/*
// @version     1.1.1
// @run-at      document-end
// @grant       none
// @license     MIT
// @author      Morryx
// @namespace https://greasyfork.org/users/807892
// ==/UserScript==

// Direct link (find a way to save it easily, some share place)

random = function (max = 1, min = 0) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
};

$(function () {
  if ($('#container').hasClass('home')) {
    var $episodes = $('.to-watch-list').first().find('li[id]'),
      random_episode = random($episodes.length - 1),
      $episode = $episodes.eq(random_episode),
      img_selector = '.image-crop img';

    $episodes.find(img_selector).css('opacity', '0.75');
    $episode.css({
      'transform': 'translateY(-20px) scale(1.2)',
      'background-color': '#ffd700',
      'border-radius': '10px',
      'box-shadow': '0 0 10px -5px black'
    })
      .find(img_selector).css('opacity', '1');
    $episode.find('.to-watch-icon').click(function () {
      $t = $(this);
      setInterval(function () {
        if ($t.parent().hasClass('watched'))
          location.reload();
      }, 2500);
    });
  }
});