config.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. const langs = [
  2. { title: 'English', path: '/home', matchPath: /^\/(home|ecosystem|support)/ },
  3. { title: '简体中文', path: '/zh-Hans/', matchPath: /^\/zh-Hans/ },
  4. ];
  5. docute.init({
  6. landing: 'landing.html',
  7. title: 'DPlayer',
  8. repo: 'DIYgod/DPlayer',
  9. twitter: 'DIYgod',
  10. 'edit-link': 'https://github.com/MoePlayer/DPlayer/tree/master/docs',
  11. nav: {
  12. default: [
  13. {
  14. title: 'Home', path: '/home'
  15. },
  16. {
  17. title: 'Ecosystem', path: '/ecosystem'
  18. },
  19. {
  20. title: 'Support DPlayer', path: '/support'
  21. },
  22. {
  23. title: 'Languages', type: 'dropdown', items: langs
  24. }
  25. ],
  26. 'zh-Hans': [
  27. {
  28. title: '首页', path: '/zh-Hans/'
  29. },
  30. {
  31. title: '生态', path: '/zh-Hans/ecosystem'
  32. },
  33. {
  34. title: '支持 DPlayer', path: '/zh-Hans/support'
  35. },
  36. {
  37. title: '选择语言', type: 'dropdown', items: langs
  38. }
  39. ],
  40. },
  41. plugins: [
  42. docsearch({
  43. apiKey: '46a8ba306e368972c1d75feb581fb430',
  44. indexName: 'dplayer',
  45. tags: ['english', 'zh-Hans'],
  46. url: 'http://dplayer.js.org'
  47. }),
  48. evanyou(),
  49. player()
  50. ]
  51. });
  52. function player () {
  53. return function (context) {
  54. context.event.on('landing:updated', function () {
  55. console.log('landing:updated');
  56. clearPlayer();
  57. dplayer1();
  58. });
  59. context.event.on('content:updated', function () {
  60. console.log('content:updated');
  61. clearPlayer();
  62. for (let i = 0; i < document.querySelectorAll('.load').length; i++) {
  63. document.querySelectorAll('.load')[i].addEventListener('click', function () {
  64. window[this.parentElement.id] && window[this.parentElement.id]();
  65. });
  66. }
  67. });
  68. };
  69. }
  70. function clearPlayer () {
  71. for (let i = 0; i < 10; i++) {
  72. if (window['dp' + (i + 1)]) {
  73. window['dp' + (i + 1)].destroy();
  74. }
  75. }
  76. }
  77. function dplayer1 () {
  78. window.dp1 = new DPlayer({
  79. container: document.getElementById('dplayer1'),
  80. video: {
  81. url: 'https://api.dogecloud.com/player/get.mp4?vcode=5ac682e6f8231991&userId=17&ext=.mp4',
  82. pic: 'https://cn-east-17-dplayer-86110920.oss.dogecdn.com/hikarunara.png',
  83. thumbnails: 'https://cn-east-17-dplayer-86110920.oss.dogecdn.com/hikarunara_thumbnails.jpg'
  84. },
  85. danmaku: {
  86. id: '9E2E3368B56CDBB4',
  87. api: 'https://api.prprpr.me/dplayer/'
  88. }
  89. });
  90. }
  91. function dplayer2 () {
  92. window.dp2 = new DPlayer({
  93. container: document.getElementById('dplayer2'),
  94. video: {
  95. url: 'https://api.dogecloud.com/player/get.mp4?vcode=5ac682e6f8231991&userId=17&ext=.mp4',
  96. pic: 'https://cn-east-17-dplayer-86110920.oss.dogecdn.com/hikarunara.png',
  97. thumbnails: 'https://cn-east-17-dplayer-86110920.oss.dogecdn.com/hikarunara_thumbnails.jpg'
  98. },
  99. danmaku: {
  100. id: '9E2E3368B56CDBB4',
  101. api: 'https://api.prprpr.me/dplayer/'
  102. }
  103. });
  104. }
  105. function dplayer3 () {
  106. window.dp3 = new DPlayer({
  107. container: document.getElementById('dplayer3'),
  108. autoplay: false,
  109. theme: '#FADFA3',
  110. loop: true,
  111. lang: 'zh-cn',
  112. hotkey: true,
  113. preload: 'auto',
  114. logo: 'https://cn-east-17-dplayer-86110920.oss.dogecdn.com/DPlayer.png',
  115. volume: 0.7,
  116. mutex: true,
  117. video: {
  118. url: 'https://api.dogecloud.com/player/get.mp4?vcode=5ac682e6f8231991&userId=17&ext=.mp4',
  119. pic: 'https://cn-east-17-dplayer-86110920.oss.dogecdn.com/hikarunara.png',
  120. thumbnails: 'https://cn-east-17-dplayer-86110920.oss.dogecdn.com/hikarunara_thumbnails.jpg',
  121. type: 'auto'
  122. },
  123. danmaku: {
  124. id: '9E2E3368B56CDBB4',
  125. api: 'https://api.prprpr.me/dplayer/',
  126. token: 'tokendemo',
  127. maximum: 1000,
  128. addition: ['https://api.prprpr.me/dplayer/v3/bilibili?aid=4157142'],
  129. user: 'DIYgod',
  130. bottom: '15%',
  131. unlimited: true
  132. },
  133. contextmenu: [
  134. {
  135. text: 'custom1',
  136. link: 'https://github.com/DIYgod/DPlayer'
  137. },
  138. {
  139. text: 'custom2',
  140. click: (player) => {
  141. console.log(player);
  142. }
  143. }
  144. ],
  145. highlight: [
  146. {
  147. time: 20,
  148. text: '这是第 20 秒'
  149. },
  150. {
  151. time: 120,
  152. text: '这是 2 分钟'
  153. }
  154. ]
  155. });
  156. }
  157. function dplayer4 () {
  158. window.dp4 = new DPlayer({
  159. container: document.getElementById('dplayer4'),
  160. video: {
  161. quality: [{
  162. name: 'HD',
  163. url: 'https://api.dogecloud.com/player/get.m3u8?vcode=5ac682e6f8231991&userId=17&ext=.m3u8',
  164. type: 'hls'
  165. }, {
  166. name: 'SD',
  167. url: 'https://api.dogecloud.com/player/get.mp4?vcode=5ac682e6f8231991&userId=17&ext=.mp4',
  168. type: 'normal'
  169. }],
  170. defaultQuality: 0,
  171. pic: 'https://cn-east-17-dplayer-86110920.oss.dogecdn.com/hikarunara.png',
  172. thumbnails: 'https://cn-east-17-dplayer-86110920.oss.dogecdn.com/hikarunara_thumbnails.jpg'
  173. }
  174. });
  175. }
  176. function dplayer5 () {
  177. window.dp5 = new DPlayer({
  178. container: document.getElementById('dplayer5'),
  179. video: {
  180. url: 'https://api.dogecloud.com/player/get.m3u8?vcode=5ac682e6f8231991&userId=17&ext=.m3u8',
  181. type: 'hls'
  182. }
  183. });
  184. }
  185. function dplayer6 () {
  186. // window.dp6 = new DPlayer({
  187. // container: document.getElementById('dplayer6'),
  188. // video: {
  189. // url: 'https://moeplayer.b0.upaiyun.com/dplayer/dash/hikarunara.mpd',
  190. // type: 'dash'
  191. // }
  192. // });
  193. }
  194. function dplayer7 () {
  195. window.dp7 = new DPlayer({
  196. container: document.getElementById('dplayer7'),
  197. video: {
  198. url: 'https://api.dogecloud.com/player/get.flv?vcode=5ac682e6f8231991&userId=17&ext=.flv',
  199. type: 'flv'
  200. }
  201. });
  202. }
  203. function dplayer8 () {
  204. window.dp8 = new DPlayer({
  205. container: document.getElementById('dplayer8'),
  206. video: {
  207. url: 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent',
  208. type: 'webtorrent'
  209. }
  210. });
  211. }
  212. function dplayer9 () {
  213. window.dp9 = new DPlayer({
  214. container: document.getElementById('dplayer9'),
  215. live: true,
  216. danmaku: true,
  217. apiBackend: {
  218. read: function (endpoint, callback) {
  219. console.log('Pretend to connect WebSocket');
  220. callback();
  221. },
  222. send: function (endpoint, danmakuData, callback) {
  223. console.log('Pretend to send danamku via WebSocket', danmakuData);
  224. callback();
  225. }
  226. },
  227. video: {
  228. url: 'https://api.dogecloud.com/player/get.m3u8?vcode=5ac682e6f8231991&userId=17&ext=.m3u8',
  229. type: 'hls'
  230. }
  231. });
  232. }
  233. function dplayer10 () {
  234. loadScript('https://cdn.jsdelivr.net/npm/pearplayer', function () {
  235. window.dp10 = new DPlayer({
  236. container: document.getElementById('dplayer10'),
  237. video: {
  238. url: 'https://qq.webrtc.win/tv/Pear-Demo-Yosemite_National_Park.mp4',
  239. type: 'pearplayer',
  240. customType: {
  241. 'pearplayer': function (video, player) {
  242. new PearPlayer(video, {
  243. src: video.src,
  244. autoplay: player.options.autoplay
  245. });
  246. }
  247. }
  248. }
  249. });
  250. });
  251. }
  252. function loadScript (src, callback) {
  253. let s,
  254. r,
  255. t;
  256. r = false;
  257. s = document.createElement('script');
  258. s.type = 'text/javascript';
  259. s.src = src;
  260. s.onload = s.onreadystatechange = function () {
  261. // console.log( this.readyState ); //uncomment this line to see which ready states are called.
  262. if (!r && (!this.readyState || this.readyState == 'complete'))
  263. {
  264. r = true;
  265. callback();
  266. }
  267. };
  268. t = document.getElementsByTagName('script')[0];
  269. t.parentNode.insertBefore(s, t);
  270. }