Pasha13666 / Play.one

// ==UserScript==
// @name         Play.one
// @namespace    https://github.com/Pasha13666
// @version      0.1
// @description  Play online on shikimori.org
// @author       Pasha13666
// @match        https://shikimori.one/animes/*
// @match        http://shikimori.one/animes/*
// @require      https://code.jquery.com/jquery-3.3.1.slim.min.js
// @grant        none
// @license      MIT
// @copyright    2018, Pasha__kun (https://github.com/Pasha13666)
// ==/UserScript==

var $ = jQuery.noConflict(true);

if (window.jQuery === undefined) {
  window.jQuery = unsafeWindow.jQuery;
}

function start() {
  var url = window.location.pathname.split('/');
  if (url.length != 3 || url[1] != 'animes')
    return;

  var ne = $(".current-episodes").text() - -1;
  var e = $(".watch-online-placeholer");
  var me = - -e.data('total_episodes');
  var loc = location.protocol + "//play.shikimori.org" + location.pathname + "/video_online/" + (ne > me ? 1 : ne);
  var link = $("<a/>", {
    'class': 'b-link_button dark watch-online',
    'href': loc
  }).text('Смотреть онлайн');
  var block = $("<div/>", {
    'class': 'block'
  }).append(link);
  e.append(block);
}

$(document).ready(start);

try {
  $(document).on('page:load turbolinks:load postloader:success', start);
}
catch (e) {
  console.error('Startup failed!', e);
}