CDA.pl Enhancer

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

  1. // ==UserScript==
  2. // @name CDA.pl Enhancer
  3. // @name:pl Rozszerzenia dla strony 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.4
  7. // @description Script contains features like video download, auto best quality choose and some hotkeys for CDA.pl website.
  8. // @description:pl Skrypt zawiera rozszerzenia takie, jak pobieranie wideo, wybór najlepszej jakości 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 settings = document.querySelector('.pb-settings-click');
  67. let buttons = document.querySelectorAll('.settings-quality');
  68.  
  69. if(buttons.length > 0) {
  70. let lastButton = buttons[buttons.length - 1].querySelector('a');
  71.  
  72. if(lastButton.text == 'Premium') {
  73. lastButton = buttons[buttons.length - 2].querySelector('a');
  74. }
  75.  
  76. if(!lastButton.className.includes('pb-active')) {
  77. lastButton.click();
  78. settings.click();
  79. }
  80. }
  81. }
  82.  
  83. if(config.bestQualitySuggestions) {
  84. let hdIconElement = document.querySelector('#rightCol > label > div > a > span.hd-ico-elem.hd-elem-pos');
  85. let hdIconElements = document.querySelectorAll('#podobne_kafle > div > label > div > a > span.hd-ico-elem.hd-elem-pos');
  86.  
  87. setHdLinks(hdIconElement);
  88.  
  89. for(let element of hdIconElements) {
  90. setHdLinks(element);
  91. }
  92. }
  93.  
  94. if(config.hotkeysEnabled) {
  95. document.onkeypress = (e) => {
  96. switch(e.key.toLowerCase()) {
  97. case config.hotkeys.fullscreen:
  98. document.querySelector('.pb-fullscreen').click();
  99. break;
  100.  
  101. case config.hotkeys.mute:
  102. document.querySelector('.pb-volume-mute').click();
  103. break;
  104.  
  105. case config.hotkeys.nextVideo:
  106. if(!['text', 'textarea'].includes(document.activeElement.type)) {
  107. document.querySelector('#rightCol > label > div > div > a').click();
  108. }
  109. }
  110. }
  111. }
  112.  
  113. function setHdLinks(element) {
  114. if(element) {
  115. let hdVersion = element.innerText;
  116. let nextVideoPictureElement = element.parentElement;
  117. let nextVideoTitleElement = element.parentElement.parentElement.children[1].children[1];
  118. let link = nextVideoPictureElement.href + '?wersja=' + hdVersion;
  119.  
  120. nextVideoPictureElement.href = link;
  121. nextVideoTitleElement.href = link;
  122. }
  123. }
  124.  
  125. window.onload = function() {
  126. const videoSource = document.querySelector('video').src;
  127. const downloadLink = document.createElement('a');
  128. downloadLink.text = 'Pobierz';
  129. downloadLink.href = videoSource;
  130. downloadLink.target = '_blank';
  131. downloadLink.style = 'color: #E28525';
  132.  
  133. document.querySelector('#naglowek').parentElement.append(downloadLink);
  134. }
  135. })();