config.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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://moeplayer.b0.upaiyun.com/dplayer/hikarunara.png',
  83. thumbnails: 'https://moeplayer.b0.upaiyun.com/dplayer/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. screenshot: true,
  95. video: {
  96. url: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.mp4',
  97. pic: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.png',
  98. thumbnails: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara_thumbnails.jpg'
  99. },
  100. subtitle: {
  101. url: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.vtt'
  102. },
  103. danmaku: {
  104. id: '9E2E3368B56CDBB4',
  105. api: 'https://api.prprpr.me/dplayer/'
  106. }
  107. });
  108. }
  109. function dplayer3 () {
  110. window.dp3 = new DPlayer({
  111. container: document.getElementById('dplayer3'),
  112. autoplay: false,
  113. theme: '#FADFA3',
  114. loop: true,
  115. lang: 'zh-cn',
  116. screenshot: true,
  117. hotkey: true,
  118. preload: 'auto',
  119. logo: 'https://moeplayer.b0.upaiyun.com/dplayer/DPlayer.png',
  120. volume: 0.7,
  121. mutex: true,
  122. video: {
  123. url: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.mp4',
  124. pic: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.png',
  125. thumbnails: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara_thumbnails.jpg',
  126. type: 'auto'
  127. },
  128. subtitle: {
  129. url: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.vtt',
  130. type: 'webvtt',
  131. fontSize: '25px',
  132. bottom: '10%',
  133. color: '#b7daff'
  134. },
  135. danmaku: {
  136. id: '9E2E3368B56CDBB4',
  137. api: 'https://api.prprpr.me/dplayer/',
  138. token: 'tokendemo',
  139. maximum: 1000,
  140. addition: ['https://api.prprpr.me/dplayer/v3/bilibili?aid=4157142'],
  141. user: 'DIYgod',
  142. bottom: '15%',
  143. unlimited: true
  144. },
  145. contextmenu: [
  146. {
  147. text: 'custom1',
  148. link: 'https://github.com/DIYgod/DPlayer'
  149. },
  150. {
  151. text: 'custom2',
  152. click: (player) => {
  153. console.log(player);
  154. }
  155. }
  156. ],
  157. highlight: [
  158. {
  159. time: 20,
  160. text: '这是第 20 秒'
  161. },
  162. {
  163. time: 120,
  164. text: '这是 2 分钟'
  165. }
  166. ]
  167. });
  168. }
  169. function dplayer4 () {
  170. window.dp4 = new DPlayer({
  171. container: document.getElementById('dplayer4'),
  172. video: {
  173. quality: [{
  174. name: 'HD',
  175. url: 'https://moeplayer.b0.upaiyun.com/dplayer/hls/hikarunara.m3u8',
  176. type: 'hls'
  177. }, {
  178. name: 'SD',
  179. url: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.mp4',
  180. type: 'normal'
  181. }],
  182. defaultQuality: 0,
  183. pic: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.png',
  184. thumbnails: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara_thumbnails.jpg'
  185. }
  186. });
  187. }
  188. function dplayer5 () {
  189. window.dp5 = new DPlayer({
  190. container: document.getElementById('dplayer5'),
  191. video: {
  192. url: 'https://moeplayer.b0.upaiyun.com/dplayer/hls/hikarunara.m3u8',
  193. type: 'hls'
  194. }
  195. });
  196. }
  197. function dplayer6 () {
  198. window.dp6 = new DPlayer({
  199. container: document.getElementById('dplayer6'),
  200. video: {
  201. url: 'https://moeplayer.b0.upaiyun.com/dplayer/dash/hikarunara.mpd',
  202. type: 'dash'
  203. }
  204. });
  205. }
  206. function dplayer7 () {
  207. window.dp7 = new DPlayer({
  208. container: document.getElementById('dplayer7'),
  209. video: {
  210. url: 'https://moeplayer.b0.upaiyun.com/dplayer/hikarunara.flv',
  211. type: 'flv'
  212. }
  213. });
  214. }
  215. function dplayer8 () {
  216. window.dp8 = new DPlayer({
  217. container: document.getElementById('dplayer8'),
  218. video: {
  219. 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',
  220. type: 'webtorrent'
  221. }
  222. });
  223. }
  224. function dplayer9 () {
  225. window.dp9 = new DPlayer({
  226. container: document.getElementById('dplayer9'),
  227. live: true,
  228. danmaku: true,
  229. apiBackend: {
  230. read: function (endpoint, callback) {
  231. console.log('Pretend to connect WebSocket');
  232. callback();
  233. },
  234. send: function (endpoint, danmakuData, callback) {
  235. console.log('Pretend to send danamku via WebSocket', danmakuData);
  236. callback();
  237. }
  238. },
  239. video: {
  240. url: 'https://moeplayer.b0.upaiyun.com/dplayer/hls/hikarunara.m3u8',
  241. type: 'hls'
  242. }
  243. });
  244. }
  245. function dplayer10 () {
  246. loadScript('https://cdn.jsdelivr.net/npm/pearplayer', function () {
  247. window.dp10 = new DPlayer({
  248. container: document.getElementById('dplayer10'),
  249. video: {
  250. url: 'https://qq.webrtc.win/tv/Pear-Demo-Yosemite_National_Park.mp4',
  251. type: 'pearplayer',
  252. customType: {
  253. 'pearplayer': function (video, player) {
  254. new PearPlayer(video, {
  255. src: video.src,
  256. autoplay: player.options.autoplay
  257. });
  258. }
  259. }
  260. }
  261. });
  262. });
  263. }
  264. function loadScript (src, callback) {
  265. let s,
  266. r,
  267. t;
  268. r = false;
  269. s = document.createElement('script');
  270. s.type = 'text/javascript';
  271. s.src = src;
  272. s.onload = s.onreadystatechange = function () {
  273. // console.log( this.readyState ); //uncomment this line to see which ready states are called.
  274. if (!r && (!this.readyState || this.readyState == 'complete'))
  275. {
  276. r = true;
  277. callback();
  278. }
  279. };
  280. t = document.getElementsByTagName('script')[0];
  281. t.parentNode.insertBefore(s, t);
  282. }