Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Программы » Opera на движке Presto (часть 26)

Модерирует : gyra, Maz

Maz (03-12-2019 21:42): Opera на движке Presto (часть 27)  Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

   

Rwd

Advanced Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору


Код:
// ==UserScript==
// @name         Youtube Auto Resolution Selection
// @version      1.4
// @namespace    http://userscripts.org/users/zackton
// @description  Auto selects the resolution (1080p default) for video quality
// @include      *.youtube.com/*
// @include      *.youtube.com/
// @updateURL    http://userscripts.org/scripts/source/167633.meta.js
// @grant        none
// ==/UserScript==
 
// Content inject so Chrome can access HTML5 player
function contentEval(source) {
    if ('function' == typeof source) {
        source = '(' + source + ')();'
    }
    var script = document.createElement('script');
    script.setAttribute("type", "application/javascript");
    script.textContent = source;
    document.body.appendChild(script);
    document.body.removeChild(script);
}
 
contentEval(function(){
 
var YP = new Object();
 
// Quality options from Youtube API
YP.quality_options = ['highres', 'hd1080', 'hd720', 'large', 'medium', 'small', 'default'];
 
 // Playback quality (delete the qualities you don't want. e.g. if you want 720p max, delete the highres and hd1080 lines)
 YP.quality = 'default';
 YP.quality = 'small';
 YP.quality = 'medium';
 YP.quality = 'large';
 YP.quality = 'hd720';
 YP.quality = 'hd1080';
 YP.quality = 'highres';
 
 
// Number of times to check for player before giving up
YP.max_attempts = 20;
 
// Initialize player, and make sure API is ready
YP.init = function() {
            if (document.getElementById('movie_player')) {
            // Normal video player
            this.player = document.getElementById('movie_player');
        }
        else if (document.getElementById('movie_player-flash')) {
            // Channel video player
            this.player = document.getElementById('movie_player-flash');
        }
        else {
            return false;
        }
    
        // Check for HTML5 player
        this.html5 = this.player.getElementsByTagName('video').length ? true : false;
 
        // Make sure player API is ready
        if (typeof this.player.pauseVideo === 'undefined') {
            return false;
        }
    
        // Pause to avoid flicker caused be loading a different quality
        this.player.pauseVideo();
    
        // In Chrome Flash player, player.setQualityLevel() doesn't seem to work unless video has started playing (or is paused)
        // In Firefox HTML5 player, player.getPlayerState() returns -1 even if player is paused
        if (!this.html5 && this.player.getPlayerState() < 1) {
            return false;
        }
    
        // Everything is good to go
        return true;
    };
    
    // Set video quality to YP.quality or highest available
    YP.setQuality = function() {
        // Get available quality levels
        var levels = this.player.getAvailableQualityLevels();
        // Set playback quality
        if (levels.indexOf(this.quality) >= 0) {
            this.player.setPlaybackQuality(this.quality);
        }
        else {
            this.player.setPlaybackQuality(levels[0]);
        }
        // Play video
        this.player.playVideo();
    }
    
    // Start execution
    YP.start = function(attempts) {
        // Initialize self (look for player)
        if (this.init()) {
            this.setQuality();
            return true;
        }
        // Give up (page has no player)
        if (attempts > this.max_attempts) {
            return false;
        }
        // Try again until initialize sucessful (maybe page still loading)
        setTimeout(function() {
            YP.start(++attempts);
        }, 200);
    }
    
    // Main
    YP.start(0);
    
});

 

Код:
// ==UserScript==
// @name        YouTube prevent autoplay
// @version     1
// @author      Bladru
// @include     https://*.youtube.com/*
// @include     https://*.youtube-nocookie.com/*
// @include     https://*.youtubeeducation.com/*
// ==/UserScript==
 
/* https://developers.google.com/youtube/js_api_reference */
 
(function(){
if (window.top != window.self)
    return;
 
window.prevent_autoplay = {};
window.prevent_autoplay.factory = function (player, index){
    var name = "callback_" + index;
    var fullname = "prevent_autoplay." + name;
    
    window.prevent_autoplay[name] = function (state){
        /* Unfortunately the player object isn't passed to the callback. */
        if (state === 1 || state === 5){    /* not sure about 5 */
            player.removeEventListener("onStateChange", fullname);
            player.pauseVideo();
            // player.stopVideo();
        }
    }
    
    return fullname;
}
 
var players = [];
 
function index_players(){
    /* #c4-player - channel page player */
    var matches = document.querySelectorAll("#movie_player, #c4-player");
    
    /* You can do without the callbacks until you meet a playlist. */
    for (var i = 0; i < matches.length; i++){
        var player = matches[i];
        
        if (players.indexOf(player) === -1 && player.getPlayerState){
            players.push(player);
            
            var state = player.getPlayerState();
            if (state === 1 || state === 5){
                player.pauseVideo();
                // player.stopVideo();
            } else {
                /* These aren't browser events, but a bunch of callbacks registered by name. It might be impossible to use () and [] in those names due to Adobe Flash restrictions. */
                player.addEventListener("onStateChange", prevent_autoplay.factory(player, players.indexOf(player)));
            }
        }
    }
}
 
var old_onYouTubePlayerReady = window.onYouTubePlayerReady;
 
/* called by YouTube */
window.onYouTubePlayerReady = function (){
    index_players();
    if (typeof old_onYouTubePlayerReady === "function")
        old_onYouTubePlayerReady.apply(this, arguments);
}
 
index_players();    /* in case we've missed onYouTubePlayerReady() */
 
})();
 

Всего записей: 623 | Зарегистр. 11-11-2016 | Отправлено: 13:43 09-11-2017
   

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Программы » Opera на движке Presto (часть 26)
Maz (03-12-2019 21:42): Opera на движке Presto (часть 27)


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru