mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 14:41:20 -08:00
添加手机白名单
This commit is contained in:
1 parent
ae8a916118
commit
df9fab27eb
7 files changed
+103
-14
No files matched your search
@@ -70,13 +70,13 @@ let i18nMap = {
|
||||
};
|
||||
|
||||
export default class I18n {
|
||||
constructor({ option }) {
|
||||
this.option = option;
|
||||
constructor(art) {
|
||||
this.art = art;
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.language = i18nMap[this.option.lang.toLowerCase()] || {};
|
||||
this.language = i18nMap[this.art.option.lang.toLowerCase()] || {};
|
||||
}
|
||||
|
||||
get(key) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import merge from 'deepmerge';
|
||||
import * as utils from './utils';
|
||||
import scheme from './scheme';
|
||||
import config from './config';
|
||||
import Whitelist from './whitelist';
|
||||
import Template from './template';
|
||||
import I18n from './i18n';
|
||||
import Player from './player';
|
||||
@@ -37,6 +38,10 @@ class Artplayer extends Emitter {
|
||||
return '__VERSION__';
|
||||
}
|
||||
|
||||
static get env() {
|
||||
return '__ENV__';
|
||||
}
|
||||
|
||||
static get config() {
|
||||
return config;
|
||||
}
|
||||
@@ -76,6 +81,7 @@ class Artplayer extends Emitter {
|
||||
controls: [],
|
||||
highlight: [],
|
||||
plugins: [],
|
||||
whitelist: [],
|
||||
thumbnails: {
|
||||
url: '',
|
||||
number: 60,
|
||||
@@ -115,6 +121,7 @@ class Artplayer extends Emitter {
|
||||
utils.errorHandle(false, 'Cannot mount multiple instances on the same dom element');
|
||||
}
|
||||
|
||||
this.whitelist = new Whitelist(this);
|
||||
this.template = new Template(this);
|
||||
this.storage = new Storage(this);
|
||||
this.i18n = new I18n(this);
|
||||
|
||||
@@ -35,6 +35,12 @@ export default {
|
||||
fullscreen: 'boolean',
|
||||
fullscreenWeb: 'boolean',
|
||||
plugins: {
|
||||
type: 'array',
|
||||
child: {
|
||||
type: 'string|function|regexp',
|
||||
},
|
||||
},
|
||||
whitelist: {
|
||||
type: 'array',
|
||||
child: {
|
||||
type: 'function',
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import optionValidator from 'option-validator';
|
||||
|
||||
export default class Whitelist {
|
||||
constructor(art) {
|
||||
const { whitelist } = art.option;
|
||||
const { userAgent } = window.navigator;
|
||||
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);
|
||||
this.state =
|
||||
!isMobile ||
|
||||
whitelist.some(item => {
|
||||
const type = optionValidator.kindOf(item);
|
||||
let result = false;
|
||||
switch (type) {
|
||||
case 'string':
|
||||
result = userAgent.indexOf(item) > -1;
|
||||
break;
|
||||
case 'function':
|
||||
result = item(userAgent);
|
||||
break;
|
||||
case 'regexp':
|
||||
result = item.test(userAgent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user