Skip to content

Commit

Permalink
字幕样式
Browse files Browse the repository at this point in the history
  • Loading branch information
qasax committed Oct 26, 2024
1 parent cfcb176 commit b95c67f
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Subtitle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
body {
margin: 0;
padding: 0;
width: 100%; /* 使内容宽度充满 */
height: 100%; /* 使内容高度充满 */
background: #f0f0f0;
}

.floating-window {
position: fixed;
bottom: 20px;
right: 20px;
background: rgba(0, 0, 0, 0.7);
color: white;
border-radius: 10px;
padding: 20px;
width: 300px;
transition: all 0.3s;
font-family: 'Roboto', sans-serif;
}

.subtitle {
font-size: 1.2em;
text-align: center;
}

.buttons {
display: flex;
justify-content: flex-end;
opacity: 0; /* 默认隐藏按钮 */
transition: opacity 0.3s;
}

.floating-window:hover .buttons {
opacity: 1; /* 鼠标悬停时显示按钮 */
}

button {
background: none;
border: none;
color: white;
cursor: pointer;
margin-left: 10px;
font-size: 1em;
}

button:hover {
text-decoration: underline;
}
60 changes: 60 additions & 0 deletions Subtitle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const outputElement = document.getElementById('subtitle');
const output = { value: '' }; // 创建一个对象来存储输出

Object.defineProperty(output, 'value', {
set: function(newValue) {
outputElement.innerText = newValue; // 更新显示内容
}
});

function fetchOutput() {
window.pywebview.api.get_message().then(function(response) {
output.value = response; // 更新输出
});
}

setInterval(fetchOutput, 1000); // 每秒请求一
const floatingWindow = document.getElementById('floatingWindow');
const buttons = document.getElementById('buttons');

// 鼠标移入悬浮窗时显示按钮
floatingWindow.addEventListener('mouseenter', () => {
buttons.style.opacity = '1';
});

// 鼠标移出悬浮窗时隐藏按钮
floatingWindow.addEventListener('mouseleave', () => {
buttons.style.opacity = '0';
});

// 置顶功能
function topWindow() {
alert('置顶功能尚未实现!');
}

// 关闭功能
function closeWindow() {
floatingWindow.style.display = 'none';
}

// 实现拖动窗口
let isMouseDown = false;
let offset = { x: 0, y: 0 };

document.body.addEventListener('mousedown', (e) => {
isMouseDown = true;
offset.x = e.clientX;
offset.y = e.clientY;
});

document.body.addEventListener('mousemove', (e) => {
if (isMouseDown) {
const x = e.screenX - offset.x;
const y = e.screenY - offset.y;
window.pywebview.api.move_window(x, y);
}
});

document.body.addEventListener('mouseup', () => {
isMouseDown = false;
});

0 comments on commit b95c67f

Please sign in to comment.