1/** 2 * ç±äº MetingJS æä¸ç¹ bug å¯¼è´æ æ³éæ¯ææ¾å¨ï¼æä»¥ææ¹äºä¸ä¸æºç 3 */ 4(function () { 5 class MetingJSElement extends HTMLElement { 6 7 connectedCallback() { 8 if (window.APlayer && window.fetch) { 9 this._init() 10 this._parse() 11 } 12 } 13 14 disconnectedCallback() { 15 if (!this.lock) { 16 this.aplayer.destroy() 17 } 18 } 19 20 _camelize(str) { 21 return str 22 .replace(/^[_.\- ]+/, '') 23 .toLowerCase() 24 .replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase()) 25 } 26 27 _init() { 28 let config = {} 29 for (let i = 0; i < this.attributes.length; i += 1) { 30 config[this._camelize(this.attributes[i].name)] = this.attributes[i].value 31 } 32 let keys = [ 33 'server', 'type', 'id', 'api', 'auth', 34 'auto', 'lock', 35 'name', 'title', 'artist', 'author', 'url', 'cover', 'pic', 'lyric', 'lrc', 36 ] 37 this.meta = {} 38 for (let key of keys) { 39 this.meta[key] = config[key] 40 delete config[key] 41 } 42 this.config = config 43 44 this.api = this.meta.api || window.meting_api || 'https://api.i-meto.com/meting/api?server=:server&type=:type&id=:id&r=:r' 45 if (this.meta.auto) this._parse_link() 46 } 47 48 _parse_link() { 49 let rules = [ 50 ['music.163.com.*song.*id=(\\d+)', 'netease', 'song'], 51 ['music.163.com.*album.*id=(\\d+)', 'netease', 'album'], 52 ['music.163.com.*artist.*id=(\\d+)', 'netease', 'artist'], 53 ['music.163.com.*playlist.*id=(\\d+)', 'netease', 'playlist'], 54 ['music.163.com.*discover/toplist.*id=(\\d+)', 'netease', 'playlist'], 55 ['y.qq.com.*song/(\\w+).html', 'tencent', 'song'], 56 ['y.qq.com.*album/(\\w+).html', 'tencent', 'album'], 57 ['y.qq.com.*singer/(\\w+).html', 'tencent', 'artist'], 58 ['y.qq.com.*playsquare/(\\w+).html', 'tencent', 'playlist'], 59 ['y.qq.com.*playlist/(\\w+).html', 'tencent', 'playlist'], 60 ['xiami.com.*song/(\\w+)', 'xiami', 'song'], 61 ['xiami.com.*album/(\\w+)', 'xiami', 'album'], 62 ['xiami.com.*artist/(\\w+)', 'xiami', 'artist'], 63 ['xiami.com.*collect/(\\w+)', 'xiami', 'playlist'], 64 ] 65 66 for (let rule of rules) { 67 let patt = new RegExp(rule[0]) 68 let res = patt.exec(this.meta.auto) 69 if (res !== null) { 70 this.meta.server = rule[1] 71 this.meta.type = rule[2] 72 this.meta.id = res[1] 73 return 74 } 75 } 76 } 77 78 _parse() { 79 if (this.meta.url) { 80 let result = { 81 name: this.meta.name || this.meta.title || 'Audio name', 82 artist: this.meta.artist || this.meta.author || 'Audio artist', 83 url: this.meta.url, 84 cover: this.meta.cover || this.meta.pic, 85 lrc: this.meta.lrc || this.meta.lyric || '', 86 type: this.meta.type || 'auto', 87 } 88 if (!result.lrc) { 89 this.meta.lrcType = 0 90 } 91 if (this.innerText) { 92 result.lrc = this.innerText 93 this.meta.lrcType = 2 94 } 95 this._loadPlayer([result]) 96 return 97 } 98 99 let url = this.api 100 .replace(':server', this.meta.server) 101 .replace(':type', this.meta.type) 102 .replace(':id', this.meta.id) 103 .replace(':auth', this.meta.auth) 104 .replace(':r', Math.random()) 105 106 fetch(url) 107 .then(res => res.json()) 108 .then(result => this._loadPlayer(result)) 109 } 110 111 _loadPlayer(data) { 112 if (this.children.length > 0) return; 113 114 let defaultOption = { 115 audio: data, 116 mutex: true, 117 lrcType: this.meta.lrcType || 3, 118 storageName: 'metingjs' 119 } 120 121 if (!data.length) return 122 123 let options = { 124 ...defaultOption, 125 ...this.config, 126 } 127 for (let optkey in options) { 128 if (options[optkey] === 'true' || options[optkey] === 'false') { 129 options[optkey] = (options[optkey] === 'true') 130 } 131 } 132 133 let div = document.createElement('div') 134 options.container = div 135 this.appendChild(div) 136 137 this.aplayer = new APlayer(options) 138 } 139 140} 141 142console.log('\n %c MetingJS v2.0.1 %c https://github.com/metowolf/MetingJS \n', 'color: #fadfa3; background: #030307; padding:5px 0;', 'background: #fadfa3; padding:5px 0;') 143 144if (window.customElements && !window.customElements.get('meting-js')) { 145 window.MetingJSElement = MetingJSElement 146 window.customElements.define('meting-js', MetingJSElement) 147} 148})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.