From 7d400311d6d585ec19f77b42478589c26fedb81c Mon Sep 17 00:00:00 2001 From: Meekdai Date: Fri, 20 Oct 2023 15:13:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.html | 10 +-- docs/{styles.css => player.css} | 0 docs/player.js | 57 ++++++------ docs/siriwave.js | 148 -------------------------------- 4 files changed, 32 insertions(+), 183 deletions(-) rename docs/{styles.css => player.css} (100%) delete mode 100644 docs/siriwave.js diff --git a/docs/index.html b/docs/index.html index d75b081..63bc5f9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,10 +5,10 @@ Gmemp - + + -
0:00
@@ -16,7 +16,6 @@
-
@@ -31,25 +30,22 @@
-
-
-
- + diff --git a/docs/styles.css b/docs/player.css similarity index 100% rename from docs/styles.css rename to docs/player.css diff --git a/docs/player.js b/docs/player.js index 873fcd5..28c38f9 100644 --- a/docs/player.js +++ b/docs/player.js @@ -5,6 +5,33 @@ elms.forEach(function(elm) { window[elm] = document.getElementById(elm); }); +let player; +let playNum=0; +let media="https://cdn.jsdelivr.net/gh/Meekdai/Gmemp@main/media/" +let requestJson="https://cdn.jsdelivr.net/gh/Meekdai/Gmemp@main/docs/memp.json" +// let requestJson="https://music.meekdai.com/memp.json" + +let request=new XMLHttpRequest(); +request.open("GET",requestJson); +request.responseType='text'; +request.send(); +request.onload=function(){ + jsonData=JSON.parse(request.response); + console.log(jsonData); + + if(window.location.hash!=''){ + try{ + playNum=parseInt(window.location.hash.slice(1)); + } + catch{ + playNum=jsonData.length-1 //默认最近添加的 + } + } + else{playNum=jsonData.length-1} //默认最近添加的 + + player = new Player(jsonData); +} + /** * Player class containing the state of our playlist and where we are in it. * Includes all methods for playing, skipping, updating the display, etc. @@ -17,7 +44,6 @@ let Player = function(playlist) { // Display the title of the first track. track.innerHTML = playlist[this.index].title; document.querySelector("body").style.backgroundImage = "url('" +media+ encodeURI(playlist[this.index].pic) + "')"; - console.log("url(" +media+ encodeURI(playlist[this.index].pic) + ")"); post.innerHTML = playlist[this.index].article; // Setup the playlist display. @@ -280,33 +306,6 @@ Player.prototype = { } }; -let player; -let playNum=0; -let media="https://cdn.jsdelivr.net/gh/Meekdai/Gmemp@main/media/" -// let requestJson="https://cdn.jsdelivr.net/gh/Meekdai/Gmemp@main/memp.json" -let requestJson="https://music.meekdai.com/memp.json" - -let request=new XMLHttpRequest(); -request.open("GET",requestJson); -request.responseType='text'; -request.send(); -request.onload=function(){ - jsonData=JSON.parse(request.response); - console.log(jsonData); - - if(window.location.hash!=''){ - try{ - playNum=parseInt(window.location.hash.slice(1)); - } - catch{ - playNum=jsonData.length-1 //默认最近添加的 - } - } - else{playNum=jsonData.length-1} //默认最近添加的 - - player = new Player(jsonData); -} - // Bind our player controls. playBtn.addEventListener('click', function() { player.play(); @@ -403,3 +402,5 @@ function draw() { x += barWidth + 1; } } + +console.log("\n %c Gmemp v1.0 %c https://github.com/Meekdai/Gmemp \n", "color: #fff; background-image: linear-gradient(90deg, rgb(47, 172, 178) 0%, rgb(45, 190, 96) 100%); padding:5px 1px;", "background-image: linear-gradient(90deg, rgb(45, 190, 96) 0%, rgb(255, 255, 255) 100%); padding:5px 0;"); diff --git a/docs/siriwave.js b/docs/siriwave.js deleted file mode 100644 index 7a691f8..0000000 --- a/docs/siriwave.js +++ /dev/null @@ -1,148 +0,0 @@ -/* Modified from https://github.com/CaffeinaLab/SiriWaveJS */ - -(function() { - -function SiriWave(opt) { - opt = opt || {}; - - this.phase = 0; - this.run = false; - - // UI vars - - this.ratio = opt.ratio || window.devicePixelRatio || 1; - - this.width = this.ratio * (opt.width || 320); - this.width_2 = this.width / 2; - this.width_4 = this.width / 4; - - this.height = this.ratio * (opt.height || 100); - this.height_2 = this.height / 2; - - this.MAX = (this.height_2) - 4; - - // Constructor opt - - this.amplitude = opt.amplitude || 1; - this.speed = opt.speed || 0.2; - this.frequency = opt.frequency || 6; - this.color = (function hex2rgb(hex){ - var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; - hex = hex.replace(shorthandRegex, function(m,r,g,b) { return r + r + g + g + b + b; }); - var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); - return result ? - parseInt(result[1],16).toString()+','+parseInt(result[2], 16).toString()+','+parseInt(result[3], 16).toString() - : null; - })(opt.color || '#fff') || '255,255,255'; - - // Canvas - - this.canvas = document.createElement('canvas'); - this.canvas.width = this.width; - this.canvas.height = this.height; - if (opt.cover) { - this.canvas.style.width = this.canvas.style.height = '100%'; - } else { - this.canvas.style.width = (this.width / this.ratio) + 'px'; - this.canvas.style.height = (this.height / this.ratio) + 'px'; - }; - - this.container = opt.container || document.body; - this.container.appendChild(this.canvas); - - this.ctx = this.canvas.getContext('2d'); - - // Start - - if (opt.autostart) { - this.start(); - } -} - -SiriWave.prototype._GATF_cache = {}; -SiriWave.prototype._globAttFunc = function(x) { - if (SiriWave.prototype._GATF_cache[x] == null) { - SiriWave.prototype._GATF_cache[x] = Math.pow(4/(4+Math.pow(x,4)), 4); - } - return SiriWave.prototype._GATF_cache[x]; -}; - -SiriWave.prototype._xpos = function(i) { - return this.width_2 + i * this.width_4; -}; - -SiriWave.prototype._ypos = function(i, attenuation) { - var att = (this.MAX * this.amplitude) / attenuation; - return this.height_2 + this._globAttFunc(i) * att * Math.sin(this.frequency * i - this.phase); -}; - -SiriWave.prototype._drawLine = function(attenuation, color, width){ - this.ctx.moveTo(0,0); - this.ctx.beginPath(); - this.ctx.strokeStyle = color; - this.ctx.lineWidth = width || 1; - - var i = -2; - while ((i += 0.01) <= 2) { - var y = this._ypos(i, attenuation); - if (Math.abs(i) >= 1.90) y = this.height_2; - this.ctx.lineTo(this._xpos(i), y); - } - - this.ctx.stroke(); -}; - -SiriWave.prototype._clear = function() { - this.ctx.globalCompositeOperation = 'destination-out'; - this.ctx.fillRect(0, 0, this.width, this.height); - this.ctx.globalCompositeOperation = 'source-over'; -}; - -SiriWave.prototype._draw = function() { - if (this.run === false) return; - - this.phase = (this.phase + Math.PI*this.speed) % (2*Math.PI); - - this._clear(); - this._drawLine(-2, 'rgba(' + this.color + ',0.1)'); - this._drawLine(-6, 'rgba(' + this.color + ',0.2)'); - this._drawLine(4, 'rgba(' + this.color + ',0.4)'); - this._drawLine(2, 'rgba(' + this.color + ',0.6)'); - this._drawLine(1, 'rgba(' + this.color + ',1)', 1.5); - - if (window.requestAnimationFrame) { - requestAnimationFrame(this._draw.bind(this)); - return; - }; - setTimeout(this._draw.bind(this), 20); -}; - -/* API */ - -SiriWave.prototype.start = function() { - this.phase = 0; - this.run = true; - this._draw(); -}; - -SiriWave.prototype.stop = function() { - this.phase = 0; - this.run = false; -}; - -SiriWave.prototype.setSpeed = function(v) { - this.speed = v; -}; - -SiriWave.prototype.setNoise = SiriWave.prototype.setAmplitude = function(v) { - this.amplitude = Math.max(Math.min(v, 1), 0); -}; - - -if (typeof define === 'function' && define.amd) { - define(function(){ return SiriWave; }); - return; -}; -window.SiriWave = SiriWave; - -})(); \ No newline at end of file