CDA.pl Enhancer

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

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

  1. // ==UserScript==
  2. // @name CDA.pl Enhancer
  3. // @name:pl Ulepszenia dla odtwarzania filmów na stronie CDA.pl
  4. // @require https://greasyfork.org/scripts/395037-monkeyconfig-modern/code/MonkeyConfig%20Modern.js?version=764968
  5. // @namespace http://tampermonkey.net/
  6. // @version 0.3.3.1
  7. // @description Script contains features like auto best quality choose and some hotkeys for CDA.pl website.
  8. // @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
  9. // @author DaveIT
  10. // @icon http://free-images.ct8.pl/greasyfork/cda-enhancer.ico
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @grant GM_addStyle
  14. // @grant GM_registerMenuCommand
  15. // @match https://www.cda.pl/video/*
  16. // ==/UserScript==
  17.  
  18. /*jshint esversion: 6 */
  19.  
  20. (function() {
  21. 'use strict';
  22.  
  23. let cfg = new MonkeyConfig({
  24. title: 'CDA.pl Enhancer Configuration',
  25. menuCommand: true,
  26. params: {
  27. best_quality_auto_set: {
  28. type: 'checkbox',
  29. default: true
  30. },
  31. best_quality_suggestions: {
  32. type: 'checkbox',
  33. default: true
  34. },
  35. enable_hotkeys: {
  36. type: 'checkbox',
  37. default: true
  38. },
  39. mute_hotkey: {
  40. type: 'text',
  41. default: 'm'
  42. },
  43. fullscreen_hotkey: {
  44. type: 'text',
  45. default: 'f'
  46. },
  47. next_video_hotkey: {
  48. type: 'text',
  49. default: 'n'
  50. }
  51. }
  52. })
  53.  
  54. let config = {
  55. bestQualityAutoSet: cfg.get('best_quality_auto_set'),
  56. bestQualitySuggestions: cfg.get('best_quality_suggestions'),
  57. hotkeysEnabled: cfg.get('enable_hotkeys'),
  58. hotkeys: {
  59. fullscreen: cfg.get('fullscreen_hotkey'),
  60. mute: cfg.get('mute_hotkey'),
  61. nextVideo: cfg.get('next_video_hotkey')
  62. }
  63. }
  64.  
  65. if(config.bestQualityAutoSet) {
  66. let buttons = document.querySelectorAll('.quality-btn');
  67.  
  68. if(buttons.length > 0) {
  69. let lastButton = buttons[buttons.length - 1];
  70.  
  71. if(lastButton.text == 'Premium') {
  72. lastButton = buttons[buttons.length - 2];
  73. }
  74.  
  75. if(!lastButton.className.includes('quality-btn-active')) {
  76. lastButton.click();
  77. }
  78. }
  79. }
  80.  
  81. if(config.bestQualitySuggestions) {
  82. let hdIconElement = document.querySelector('#rightCol > label > div > a > span.hd-ico-elem.hd-elem-pos');
  83. let hdIconElements = document.querySelectorAll('#podobne_kafle > div > label > div > a > span.hd-ico-elem.hd-elem-pos');
  84.  
  85. setHdLinks(hdIconElement);
  86.  
  87. for(let element of hdIconElements) {
  88. setHdLinks(element);
  89. }
  90. }
  91.  
  92. if(config.hotkeysEnabled) {
  93. document.onkeypress = (e) => {
  94. switch(e.key) {
  95. case config.hotkeys.fullscreen:
  96. document.querySelector('.pb-fullscreen').click();
  97. break;
  98.  
  99. case config.hotkeys.mute:
  100. document.querySelector('.pb-volume-mute').click();
  101. break;
  102.  
  103. case config.hotkeys.nextVideo:
  104. if(['text', 'textarea'].includes(document.activeElement.type)) {
  105. document.querySelector('#rightCol > label > div > div > a').click();
  106. }
  107. }
  108. }
  109. }
  110.  
  111. function setHdLinks(element) {
  112. if(element) {
  113. let hdVersion = element.innerText;
  114. let nextVideoPictureElement = element.parentElement;
  115. let nextVideoTitleElement = element.parentElement.parentElement.children[1].children[1];
  116. let link = nextVideoPictureElement.href + '?wersja=' + hdVersion;
  117.  
  118. nextVideoPictureElement.href = link;
  119. nextVideoTitleElement.href = link;
  120. }
  121. }
  122. })();