CDA.pl Enhancer

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

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

  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.2.2
  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. hotkeys_enabled: {
  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. }
  48. })
  49.  
  50. let config = {
  51. bestQualityAutoSet: cfg.get('best_quality_auto_set'),
  52. bestQualitySuggestions: cfg.get('best_quality_suggestions'),
  53. hotkeysEnabled: cfg.get('hotkeys_enabled'),
  54. hotkeys: {
  55. fullscreen: cfg.get('fullscreen_hotkey'),
  56. mute: cfg.get('mute_hotkey')
  57. }
  58. }
  59.  
  60. if(config.bestQualityAutoSet) {
  61. let buttons = document.querySelectorAll('.quality-btn');
  62.  
  63. if(buttons.length > 0) {
  64. let lastButton = buttons[buttons.length - 1];
  65.  
  66. if(lastButton.text == 'Premium') {
  67. lastButton = buttons[buttons.length - 2];
  68. }
  69.  
  70. if(!lastButton.className.includes('quality-btn-active')) {
  71. lastButton.click();
  72. }
  73. }
  74. }
  75. if(config.bestQualitySuggestions) {
  76. let hdIconElement = document.querySelector('#rightCol > label > div > a > span.hd-ico-elem.hd-elem-pos');
  77. let hdIconElements = document.querySelectorAll('#podobne_kafle > div > label > div > a > span.hd-ico-elem.hd-elem-pos');
  78.  
  79. setHdLinks(hdIconElement);
  80.  
  81. for(let element of hdIconElements) {
  82. setHdLinks(element);
  83. }
  84. }
  85.  
  86. if(config.hotkeysEnabled) {
  87. document.onkeypress = (e) => {
  88. switch(e.key) {
  89. case config.hotkeys.fullscreen:
  90. document.querySelector('.pb-fullscreen').click();
  91. break;
  92.  
  93. case config.hotkeys.mute:
  94. document.querySelector('.pb-volume-mute').click();
  95. break;
  96. }
  97. }
  98. }
  99.  
  100. function setHdLinks(element) {
  101. let hdVersion = element.innerText;
  102. let nextVideoPictureElement = element.parentElement;
  103. let nextVideoTitleElement = element.parentElement.parentElement.children[1].children[1];
  104. let link = nextVideoPictureElement.href + '?wersja=' + hdVersion;
  105.  
  106. nextVideoPictureElement.href = link;
  107. nextVideoTitleElement.href = link;
  108. }
  109. })();