video.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const PROXY_URL = '/proxy/vid/'
  2. let player = document.getElementById('video-player')
  3. let qntext = document.getElementById('quality-text')
  4. let autonext = document.getElementById('autonext-check')
  5. let playerSource = document.getElementById('video-source')
  6. function switch_qn (qn) {
  7. currentTime = player.currentTime
  8. paused = player.paused
  9. playerSource.src = PROXY_URL + srcinfo[qn]['durl'][0]['url']
  10. player.load()
  11. player.currentTime = currentTime
  12. if (!paused) player.play()
  13. let desc = '未知画质'
  14. for (const qf of srcinfo[qn]['support_formats']) {
  15. if (qf['quality'] == qn) {
  16. desc = qf['new_description']
  17. break
  18. }
  19. }
  20. qntext.innerText = desc
  21. mdui.snackbar({ message: `已切换至${desc}` })
  22. }
  23. player.onended = function (e) {
  24. if (localStorage.getItem('autonext') != 'yes')
  25. return
  26. recums = document.querySelectorAll('.mdui-card-actions > a')
  27. if (recums.length == 0) {
  28. mdui.snackbar({ 'message': '没有更多视频可以播放啦' })
  29. } else {
  30. mdui.snackbar({ 'message': '三秒后将跳转到下一个视频' })
  31. setTimeout(function () {
  32. localStorage.setItem('autonext-play', 'yes')
  33. window.location = recums[0].href
  34. }, 3000)
  35. }
  36. }
  37. window.addEventListener('load', function() {
  38. qn = Number(localStorage.getItem('quality'))
  39. if (!(qn in srcinfo)) {
  40. realqn = 0
  41. for (let availqn of Object.keys(srcinfo)) {
  42. if (availqn > qn)
  43. break
  44. realqn = availqn
  45. }
  46. qn = realqn ? realqn : Object.keys(srcinfo)[0]
  47. }
  48. console.log(qn)
  49. playerSource.src = PROXY_URL + srcinfo[qn]['durl'][0]['url']
  50. player.load()
  51. let desc = '未知画质'
  52. for (const qf of srcinfo[qn]['support_formats']) {
  53. if (qf['quality'] == qn) {
  54. desc = qf['new_description']
  55. break
  56. }
  57. }
  58. qntext.innerText = desc
  59. if (localStorage.getItem('autonext') == 'yes') {
  60. autonext.checked = true
  61. if (localStorage.getItem('autonext-play') == 'yes') {
  62. localStorage.setItem('autonext-play', 'no')
  63. player.play()
  64. }
  65. }
  66. }, false)