Skip to content

Instantly share code, notes, and snippets.

@cworld1
Last active December 20, 2023 15:50
Show Gist options
  • Save cworld1/face3d9305adc2dfa9dd8234a71b9adc to your computer and use it in GitHub Desktop.
Save cworld1/face3d9305adc2dfa9dd8234a71b9adc to your computer and use it in GitHub Desktop.
prts.wiki 剧情体验优化
// ==UserScript==
// @name prts.wiki 剧情优化
// @namespace Violentmonkey Scripts
// @match https://prts.wiki/w/*
// @grant none
// @version 1.1
// @author CWorld
// @description PRTS theater mode provement
// ==/UserScript==
// verify the script is needed for loading
var theater = document.getElementById('sys_fullscreen');
if (!theater) return;
var theater_clicker = document.getElementById('sys_clicker');
var isSpaceKeyPressed = false;
// add key listener
document.addEventListener('keydown', function(event) {
// L key for log history
if (event.key === 'l') {
document.getElementById('button_playback').click();
}
// A key for all log history
else if (event.key === 'a') {
document.getElementById('button_playback_all').click();
}
// F key for fullscreen
else if (event.key === 'f') {
document.getElementById('button_fullscreen').click();
}
// Space key for playing
else if (event.key === ' ') {
event.preventDefault();
theater_clicker.click();
// Long press for speeding play
if (!isSpaceKeyPressed) {
theater_clicker.dispatchEvent(new Event('mousedown'));
isSpaceKeyPressed = true;
}
}
// ArrowLeft for prev chapter
else if (event.key === 'ArrowLeft') {
var selfLinkElement = document.querySelector('.mw-selflink.selflink');
if (selfLinkElement) {
var linkElement = selfLinkElement.previousElementSibling.previousElementSibling;
if (linkElement) window.open(linkElement.href, '_self');
}
}
// ArrowRight for next chapter
else if (event.key === 'ArrowRight') {
var selfLinkElement = document.querySelector('.mw-selflink.selflink');
if (selfLinkElement) {
var linkElement = selfLinkElement.nextElementSibling.nextElementSibling;
if (linkElement) window.open(linkElement.href, '_self');
}
}
});
// Keyup the space
document.addEventListener('keyup', function(event) {
if (event.key === ' ') {
if (isSpaceKeyPressed) {
theater_clicker.dispatchEvent(new Event('mouseup'));
isSpaceKeyPressed = false;
}
}
});
// Customize style
var styleElement = document.createElement('style');
styleElement.innerHTML = `
.button_style {
top: 18px;
}
/* hide unused button */
#button_report.normal,
#button_reset.right {
transition: opacity 0.3s;
opacity: 0;
}
#button_report.normal:hover,
#button_reset.right:hover {
opacity: 1;
}
/* lower highlight of other buttons */
#button_playback_all.normal,
#button_fullscreen,
.button_style.right {
transition: opacity 0.3s;
opacity: 0.4;
}
#button_playback_all.normal:hover,
#button_fullscreen:hover,
.button_style.right:hover {
opacity: 1;
}
/* change the order of the right button */
.button_style.right {
width: 60px;
}
#button_auto {
right: 80px;
}
#button_reset {
right: 160px;
}
/* move fullscreen mode button to right */
#button_fullscreen.return {
background-image: url(https://static.prts.wiki/assets/scenario/ui/ui_fullscreen.png);
background-size: 30px 30px;
}
.button_style.left:not(.hidden) ~ #button_fullscreen {
left: inherit;
right: 40px;
float: right;
height: 20px;
width: 20px;
top: 23px;
font-size: 9px;
line-height: 2.2;
}
.button_style.left:not(.hidden) ~ #button_fullscreen.return::after {
content: "Esc";
}
#button_playback_all.normal {
left: 80px;
}
#button_report.normal {
left: 130px;
}
#button_reset.right {
right: 160px;
}
/* prove dialog style */
.dialog_style.header {
background-image: linear-gradient(rgba(0, 0, 0, .3) 15%, rgba(0, 0, 0, 0) 50%);
}
.dialog_style.footer {
background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .7) 40%);
}
/* bigger size of log */
.log_style li > em,
.log_style li > span {
font-size: 16px;
}
.log_style li>span {
width: 620px;
}
.dialog_style.footer > div.content {
font-size: 20px;
margin-top: 2px;
}
.log_style li {
padding: 7px 0px;
height: 22px;
}
/* hightlight the selflink */
a.mw-selflink {
background: #a8a8a8;
}
`;
document.body.appendChild(styleElement);
@cworld1
Copy link
Author

cworld1 commented Dec 19, 2023

Need to support extensions of the user script. To install it:
需要支持油猴脚本的拓展。安装:

Install script

@cworld1
Copy link
Author

cworld1 commented Dec 19, 2023

食用方法:

  • L 查看会话历史
  • A 查看全部会话历史
  • Space 继续对话
  • Space 长按加速对话/加载资源
  • F 全屏
  • 左右方向键跳转前/后章

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment