option.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. const defaultApiBackend = require('./api.js');
  2. module.exports = (option) => {
  3. const isMobile = /mobile/i.test(window.navigator.userAgent);
  4. // compatibility: some mobile browsers don't suppose autoplay
  5. if (isMobile) {
  6. option.autoplay = false;
  7. }
  8. // default options
  9. const defaultOption = {
  10. element: document.getElementsByClassName('dplayer')[0],
  11. autoplay: false,
  12. theme: '#b7daff',
  13. loop: false,
  14. lang: navigator.language.indexOf('zh') !== -1 ? 'zh' : 'en',
  15. screenshot: false,
  16. hotkey: true,
  17. preload: 'auto',
  18. apiBackend: defaultApiBackend
  19. };
  20. for (let defaultKey in defaultOption) {
  21. if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) {
  22. option[defaultKey] = defaultOption[defaultKey];
  23. }
  24. }
  25. if (option.video && !option.video.hasOwnProperty('type')) {
  26. option.video.type = 'auto';
  27. }
  28. if (option.danmaku && !option.danmaku.hasOwnProperty('user')) {
  29. option.danmaku.user = 'DIYgod';
  30. }
  31. return option;
  32. };