AO Auto choose player

Add to anime-odcinki.pl's players auto choose player in order of players

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 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        AO Auto choose player
// author       Wiktor Radecki
// @namespace   AnimeOdcinki
// @include     http://anime-odcinki.pl/*
// @version     3
// @grant       none
// @description Add to anime-odcinki.pl's players auto choose player in order of players
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==

// Należy wyedytowac liste z odtwarzaczmi... jest sprawdzane po tej liscie czy jest taki player
// jesli jest to wybiera go i przelacza.
// Bierze pirwszy na liscie, wiec trzeba wpisac w kolejnosci w jakiej chce sie wybierac otwarzacze.
var players = ['VK Player', 'Google Player', 'Tune Player', 'MP4Upload Player'];

var done = false;

$(document).ready(choosePlayer);

function filterByNonNext(array) {
  var divs = [];
  for(var i = 0; i < array.length; i++){
    var div = array[i];
    if(contains(div.innerHTML,'&lt;&lt;') 
       || contains(div.innerHTML, '&gt;&gt;')
       || contains(div.innerHTML, '<<') 
       || contains(div.innerHTML, '>>'))
      continue;
    divs.push(div);
  }
  return divs;
}

function contains(text, search){
  return text.indexOf(search) > -1;
}

function choosePlayer(){
var playerDiv = $('#video-player-control');
if (playerDiv.length) {
  var divs = filterByNonNext(playerDiv.children());
  for (var i = 0; !done && i < players.length; i++) {
    var player = players[i];
    for (var j = 0; j < divs.length && !done; j++) {
      var div = divs[j];
      if(contains(div.innerHTML,player)){
        done = true;
        if(div !== divs[0]){
          div.click(); 
        }
      }
    }
  }
}

}