config.js 8.9 KB

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