Разработан веб-сервер и расширение для браузеров на базе Chromium
This commit is contained in:
1
server/static/scripts/color-thief.umd.js
Normal file
1
server/static/scripts/color-thief.umd.js
Normal file
File diff suppressed because one or more lines are too long
41
server/static/scripts/main.js
Normal file
41
server/static/scripts/main.js
Normal file
@ -0,0 +1,41 @@
|
||||
const colorThief = new ColorThief();
|
||||
const musicElement = document.querySelector('#music');
|
||||
const progressBarElement = musicElement.querySelector('#music > .progress-bar');
|
||||
const titleElement = progressBarElement.querySelector('#music > .progress-bar > .data > .title');
|
||||
const artistsElement = progressBarElement.querySelector('#music > .progress-bar > .data > .artists');
|
||||
const coverElement = progressBarElement.querySelector('#music > .progress-bar > .cover');
|
||||
|
||||
const handlers = {
|
||||
'target': (attributes) => {
|
||||
const target = document.getElementById(attributes.id);
|
||||
target.style.setProperty('--progress-size', `${attributes.progress}`);
|
||||
},
|
||||
'music': (attributes) => {
|
||||
titleElement.textContent = attributes.title;
|
||||
artistsElement.textContent = attributes.artists;
|
||||
musicElement.style.setProperty('--progress-size', `${(1 - attributes.progress) * 100}%`);
|
||||
const url = new URL(location);
|
||||
url.pathname = '/image';
|
||||
const urlSearchParams = new URLSearchParams();
|
||||
urlSearchParams.set('src', attributes.image);
|
||||
url.search = urlSearchParams.toString();
|
||||
coverElement.src = url;
|
||||
const colors = colorThief.getPalette(coverElement, 2);
|
||||
progressBarElement.style.setProperty('--primary-color', `rgb(${colors[0][0]}, ${colors[0][1]}, ${colors[0][2]})`);
|
||||
progressBarElement.style.setProperty('--secondary-color', `rgb(${colors[1][0]}, ${colors[1][1]}, ${colors[1][2]})`);
|
||||
musicElement.classList.remove('hidden');
|
||||
},
|
||||
};
|
||||
|
||||
const connectWebSocket = () => {
|
||||
const ws = new WebSocket('ws://localhost:8000/ws/v1/overlay');
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
handlers[data.type](data.attributes);
|
||||
};
|
||||
|
||||
ws.onclose = () => connectWebSocket();
|
||||
};
|
||||
|
||||
connectWebSocket();
|
130
server/static/styles/main.css
Normal file
130
server/static/styles/main.css
Normal file
@ -0,0 +1,130 @@
|
||||
@property --primary-color {
|
||||
syntax: '<color>';
|
||||
initial-value: white;
|
||||
inherits: false;
|
||||
}
|
||||
|
||||
@property --secondary-color {
|
||||
syntax: '<color>';
|
||||
initial-value: white;
|
||||
inherits: false;
|
||||
}
|
||||
|
||||
:root {
|
||||
--text-shadow: 0 0 12px rgba(0, 0, 0, 0.4);
|
||||
--box-shadow: 0 .5rem .75rem .375rem rgba(0, 0, 0, .15), 0 .25rem .25rem rgba(0, 0, 0, .3);
|
||||
}
|
||||
|
||||
* {
|
||||
font-family: 'Exo 2', sans-serif;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
html {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
#root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#root > * {
|
||||
width: 30rem;
|
||||
}
|
||||
|
||||
#root > *:not(:first-child) {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
#root > *.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#root > * > .title {
|
||||
margin-bottom: .5rem;
|
||||
color: white;
|
||||
text-shadow: var(--text-shadow);
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
#music {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
--progress: 100%;
|
||||
}
|
||||
|
||||
#music > .progress-bar {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: .5rem;
|
||||
padding: 1rem;
|
||||
width: 28rem;
|
||||
background-image: linear-gradient(225deg, var(--primary-color), var(--secondary-color));
|
||||
box-shadow: var(--box-shadow);
|
||||
border-radius: .5rem;
|
||||
overflow: hidden;
|
||||
transition:
|
||||
opacity .4s,
|
||||
--primary-color 1s,
|
||||
--secondary-color 1s;
|
||||
--progress-size: inherit;
|
||||
--progress-color: inherit;
|
||||
}
|
||||
|
||||
#music > .progress-bar::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: var(--progress-size);
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
background-color: rgba(0, 0, 0, .3);
|
||||
transition:
|
||||
right 1s,
|
||||
background-color 4s;
|
||||
}
|
||||
|
||||
#music > .progress-bar > .data {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-left: 1rem;
|
||||
overflow-x: hidden;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
#music > .progress-bar > .data > .title,
|
||||
#music > .progress-bar > .data > .artists {
|
||||
color: white;
|
||||
white-space: nowrap;
|
||||
overflow-x: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
#music > .progress-bar > .data > .title {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
#music > .progress-bar > .data > .artists {
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
#music > .progress-bar > .cover {
|
||||
flex-shrink: 0;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
object-fit: cover;
|
||||
z-index: 1;
|
||||
}
|
Reference in New Issue
Block a user