CDA.pl Enhancer

Script contains features like auto best quality choose and some hotkeys for CDA.pl website.

当前为 2021-06-18 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name            CDA.pl Enhancer
// @name:pl         Ulepszenia dla odtwarzania filmów na stronie CDA.pl
// @namespace       http://tampermonkey.net/
// @version         0.2.1
// @description     Script contains features like auto best quality choose and some hotkeys for CDA.pl website.
// @description:pl  Skrypt zawiera właściwości takie jak wybór najlepszej jakości filmu oraz kilka skrótów klawiszowych dla strony CDA.pl
// @author          DaveIT
// @match           https://www.cda.pl/video/*
// @grant           none
// ==/UserScript==

/*jshint esversion: 6 */

(function() {
    'use strict';

    let config = {
        bestQualityAutoSet: true,
        bestQualityEnable: true,
        hotkeysEnable: true,
        hotkeys: {
            fullscreen: 'f',
            mute: 'm'
        }
    }

    if(config.bestQualityAutoSet) {
        let buttons = document.querySelectorAll('.quality-btn');

        if(buttons.length > 0) {
            let lastButton = buttons[buttons.length - 1];

            if(lastButton.text == 'Premium') {
                lastButton = buttons[buttons.length - 2];
            }

            if(!lastButton.className.includes('quality-btn-active')) {
                lastButton.click();
            }
        }
    }
    
    if(config.bestQualityEnable) {
        let hdIconElement = document.querySelector('#rightCol > label > div > a > span.hd-ico-elem.hd-elem-pos');
        let hdIconElements = document.querySelectorAll('#podobne_kafle > div > label > div > a > span.hd-ico-elem.hd-elem-pos');

        setHdLinks(hdIconElement);

        for(let element of hdIconElements) {
            setHdLinks(element);
        }
    }

    if(config.hotkeysEnable) {
        document.onkeypress = (e) => {
            switch(e.key) {
                case config.hotkeys.fullscreen:
                    document.querySelector('.pb-fullscreen').click();
                    break;

                case config.hotkeys.mute:
                    document.querySelector('.pb-volume-mute').click();
                    break;
            }
        }
    }

    function setHdLinks(element) {
        let hdVersion = element.innerText;
        let nextVideoPictureElement = element.parentElement;
        let nextVideoTitleElement = element.parentElement.parentElement.children[1].children[1];
        let link = nextVideoPictureElement.href + '?wersja=' + hdVersion;

        nextVideoPictureElement.href = link;
        nextVideoTitleElement.href = link;
    }
})();