115 Player Enhancer

115播放器增强

目前為 2019-01-12 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 115 Player Enhancer
  3. // @namespace https://gf.qytechs.cn/scripts/376536-115-player-enhancer/
  4. // @version 0.4
  5. // @description 115播放器增强
  6. // @author zaypen
  7. // @match http*://115.com/*
  8. // @match http*://*/*
  9. // @require https://openuserjs.org/src/libs/sizzle/GM_config.min.js
  10. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
  11. // @require https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // ==/UserScript==
  15.  
  16. /*jslint browser:true*/
  17. /*global GM_config, _, $ */
  18.  
  19. var defaultOpeningDuration = 125;
  20.  
  21. var fieldDefs = {
  22. 'OpeningDuration': {
  23. 'label': 'OP 时长',
  24. 'type': 'unsigned int',
  25. 'default': defaultOpeningDuration
  26. }
  27. };
  28.  
  29. GM_config.init({
  30. id: 'GM_config',
  31. title: '115 Player Enhancer',
  32. fields: fieldDefs
  33. });
  34.  
  35. function appendElement(current, next) {
  36. console.log('add ', next);
  37. return current.insertAdjacentElement('afterend', next);
  38. }
  39.  
  40. function registerHotkey(key, fn) {
  41. document.body.addEventListener('keyup', function(e) {
  42. if (e.key === key) {
  43. fn();
  44. }
  45. });
  46. }
  47.  
  48. function retry(fn, interval, times) {
  49. var ret = fn();
  50. if (!ret && times) {
  51. setTimeout(function () {
  52. retry(fn, interval, times--);
  53. }, interval);
  54. }
  55. }
  56.  
  57. function createButton(onclick, alt) {
  58. var button = document.createElement('a');
  59. button.href = 'javascript:;';
  60. button.className = 'btn-switch';
  61. button.alt = alt;
  62. button.onclick = onclick;
  63. return button;
  64. }
  65.  
  66. function getPlayer() {
  67. return $('#js-video')[0];
  68. }
  69.  
  70. function getNextItem() {
  71. var items = Array.apply(null, document.querySelectorAll('.video-playlist .vpl-container .item-list li'));
  72. var remainingItems = _.dropWhile(items, function (item) {
  73. return item.className !== 'hover';
  74. });
  75. return _.head(_.tail(remainingItems));
  76. }
  77.  
  78. (function() {
  79. 'use strict';
  80.  
  81. function main() {
  82. var video = getPlayer();
  83. var configration = function() {
  84. GM_config.open();
  85. };
  86.  
  87. var playButton = document.querySelector('.operate-bar a[btn="play"]');
  88. var currentButton = playButton;
  89.  
  90. var skipOp = function() {
  91. video.currentTime += GM_config.get('OpeningDuration');
  92. };
  93. var skipOpButton = createButton(skipOp, '跳过OP');
  94. skipOpButton.innerHTML = '<i class="icon-operate iop-playing" style="background-size: 450% 200%;"></i>';
  95. currentButton = appendElement(currentButton, skipOpButton);
  96. registerHotkey('End', skipOp);
  97.  
  98. var nextItem = getNextItem();
  99. var playNext = function() {
  100. window.location.href = nextItem.querySelector('a').href;
  101. };
  102. var nextButton = createButton(playNext, '下一集');
  103. nextButton.innerHTML = '<i class="icon-operate iop-playing" style="background-size: 400% 200%;"></i>';
  104. nextButton.onclick = playNext;
  105. if (nextItem) {
  106. currentButton = appendElement(currentButton, nextButton);
  107. registerHotkey('PageDown', playNext);
  108. }
  109.  
  110. var configButton = createButton(configration, '设置');
  111. configButton.innerHTML = '<i class="icon-operate iop-setting"></i>';
  112. currentButton = appendElement(currentButton, configButton);
  113. return true;
  114. }
  115.  
  116. function inject() {
  117. var video = getPlayer();
  118. if (video) {
  119. video.addEventListener('playing', main, { once: true });
  120. return true;
  121. }
  122. }
  123.  
  124. retry(inject, 500, 10);
  125. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址