-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |