CDA.pl Enhancer

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

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

  1. // ==UserScript==
  2. // @name CDA.pl Enhancer
  3. // @name:pl Ulepszenia dla odtwarzania filmów na stronie CDA.pl
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.2.1
  6. // @description Script contains features like auto best quality choose and some hotkeys for CDA.pl website.
  7. // @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
  8. // @author DaveIT
  9. // @match https://www.cda.pl/video/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /*jshint esversion: 6 */
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. let config = {
  19. bestQualityAutoSet: true,
  20. bestQualityEnable: true,
  21. hotkeysEnable: true,
  22. hotkeys: {
  23. fullscreen: 'f',
  24. mute: 'm'
  25. }
  26. }
  27.  
  28. if(config.bestQualityAutoSet) {
  29. let buttons = document.querySelectorAll('.quality-btn');
  30.  
  31. if(buttons.length > 0) {
  32. let lastButton = buttons[buttons.length - 1];
  33.  
  34. if(lastButton.text == 'Premium') {
  35. lastButton = buttons[buttons.length - 2];
  36. }
  37.  
  38. if(!lastButton.className.includes('quality-btn-active')) {
  39. lastButton.click();
  40. }
  41. }
  42. }
  43. if(config.bestQualityEnable) {
  44. let hdIconElement = document.querySelector('#rightCol > label > div > a > span.hd-ico-elem.hd-elem-pos');
  45. let hdIconElements = document.querySelectorAll('#podobne_kafle > div > label > div > a > span.hd-ico-elem.hd-elem-pos');
  46.  
  47. setHdLinks(hdIconElement);
  48.  
  49. for(let element of hdIconElements) {
  50. setHdLinks(element);
  51. }
  52. }
  53.  
  54. if(config.hotkeysEnable) {
  55. document.onkeypress = (e) => {
  56. switch(e.key) {
  57. case config.hotkeys.fullscreen:
  58. document.querySelector('.pb-fullscreen').click();
  59. break;
  60.  
  61. case config.hotkeys.mute:
  62. document.querySelector('.pb-volume-mute').click();
  63. break;
  64. }
  65. }
  66. }
  67.  
  68. function setHdLinks(element) {
  69. let hdVersion = element.innerText;
  70. let nextVideoPictureElement = element.parentElement;
  71. let nextVideoTitleElement = element.parentElement.parentElement.children[1].children[1];
  72. let link = nextVideoPictureElement.href + '?wersja=' + hdVersion;
  73.  
  74. nextVideoPictureElement.href = link;
  75. nextVideoTitleElement.href = link;
  76. }
  77. })();