1234567891011121314151617181920212223242526272829303132333435 |
- const defaultApiBackend = require('./api.js');
- module.exports = (option) => {
- const isMobile = /mobile/i.test(window.navigator.userAgent);
- // compatibility: some mobile browsers don't suppose autoplay
- if (isMobile) {
- option.autoplay = false;
- }
- // default options
- const defaultOption = {
- element: document.getElementsByClassName('dplayer')[0],
- autoplay: false,
- theme: '#b7daff',
- loop: false,
- lang: navigator.language.indexOf('zh') !== -1 ? 'zh' : 'en',
- screenshot: false,
- hotkey: true,
- preload: 'auto',
- apiBackend: defaultApiBackend
- };
- for (let defaultKey in defaultOption) {
- if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) {
- option[defaultKey] = defaultOption[defaultKey];
- }
- }
- if (option.video && !option.video.hasOwnProperty('type')) {
- option.video.type = 'auto';
- }
- if (option.danmaku && !option.danmaku.hasOwnProperty('user')) {
- option.danmaku.user = 'DIYgod';
- }
- return option;
- };
|