调整样式、减少初始设置的通知

This commit is contained in:
woohoo 2022-01-28 01:12:49 +08:00
parent feae11dd78
commit aca31a559b

View File

@ -1,8 +1,8 @@
// ==UserScript== // ==UserScript==
// @lastmodified 202201271811 // @lastmodified 202201280112
// @name Torn翻译 // @name Torn翻译
// @namespace WOOH // @namespace WOOH
// @version 0.3.2 // @version 0.3.3
// @description Torn UI翻译 // @description Torn UI翻译
// @author Woohoo[2687093] Sabrina_Devil[2696209] // @author Woohoo[2687093] Sabrina_Devil[2696209]
// @match https://www.torn.com/* // @match https://www.torn.com/*
@ -23,13 +23,18 @@
if (window.WHTRANS) return; if (window.WHTRANS) return;
window.WHTRANS = true; window.WHTRANS = true;
// 版本 // 版本
const version = '0.3.2'; const version = '0.3.3';
// 修改历史 // 修改历史
const changelist = [ const changelist = [
{ {
todo: true, todo: true,
cont: `翻译baza npc商店、imarket、imarket搜索结果`, cont: `翻译baza npc商店、imarket、imarket搜索结果`,
}, },
{
ver: '0.3.3',
date: '20220128',
cont: `调整样式、减少初始设置的通知`,
},
{ {
ver: '0.3.2', ver: '0.3.2',
date: '20220127', date: '20220127',
@ -3093,7 +3098,7 @@
default_settings.forEach(_default => { default_settings.forEach(_default => {
if (typeof wh_trans_settings[_default.key] !== typeof _default.val) wh_trans_settings[_default.key] = _default.val; if (typeof wh_trans_settings[_default.key] !== typeof _default.val) wh_trans_settings[_default.key] = _default.val;
}); });
saveSettings(); saveSettings(true);
const GS = {}; const GS = {};
@ -3104,47 +3109,9 @@
settingsArr.push({ settingsArr.push({
domType: 'checkbox', domType: 'checkbox',
domId: 'wh-trans-enable', domId: 'wh-trans-enable',
domText: ' 开启翻译<span> (施工中)</span>', domText: ' 开启翻译 <button id="wh-trans-data-update">更新词库</button>',
dictName: 'transEnable', dictName: 'transEnable',
}) })
// 更新词库按钮
settingsArr.push({
domType: 'button',
domId: 'wh-trans-data-update',
domText: '更新翻译词库数据',
clickFunc: function (e) {
e.target.blur();
if (this.intervalID) return;
const url = isDev() ? 'http://192.168.1.7:8080/' : 'https://jjins.github.io/gengxin/';
const popup = window.open(url);
let hsCount = 0;
this.intervalID = window.setInterval(() => {
if (hsCount > 20) {
clearInterval(this.intervalID);
this.intervalID = null;
return;
}
popup.postMessage("connect", '*');
hsCount++;
}, 500);
let connected = false;
if (!this.msgEventCreated) {
window.addEventListener("message", (e) => {
this.msgEventCreated = true;
if (e.data === 'connected') {
connected = true;
clearInterval(this.intervalID);
this.intervalID = null;
return;
}
if (connected) {
// 传回的动态内容
log(e.data);
}
}, false);
}
},
})
// 12月时加入圣诞小镇选项 // 12月时加入圣诞小镇选项
if (new Date().getMonth() === 11) { if (new Date().getMonth() === 11) {
settingsArr.push({ settingsArr.push({
@ -3306,7 +3273,7 @@
} else { } else {
wh_trans_settings.autoStartFinish = false; wh_trans_settings.autoStartFinish = false;
wh_trans_settings.attReload = 6; wh_trans_settings.attReload = 6;
saveSettings(); saveSettings(true);
} }
// 飞花库存 // 飞花库存
settingsArr.push({ settingsArr.push({
@ -3359,8 +3326,8 @@
() => window.location.href = 'https://www.torn.com/crimes.php'); () => window.location.href = 'https://www.torn.com/crimes.php');
return; return;
} }
// const popup_node = popupMsg(`加载中 ${loading_gif_html}<br/>`, '飞贼助手加载');
if (!GS.LOADED) { if (!GS.LOADED) {
notify('正在加载...');
COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js') COFetch('https://cdn.staticfile.org/vue/2.2.2/vue.min.js')
.catch(err => notify(err)) .catch(err => notify(err))
.then(VueJS => { .then(VueJS => {
@ -3396,7 +3363,7 @@
} }
window.eval(GSJS); window.eval(GSJS);
if (isDev()) window.GM_setValue("gsp_showContent", true); if (isDev()) window.GM_setValue("gsp_showContent", true);
notify('飞贼助手已载入'); notify('已载入飞贼助手');
}) })
.catch(err => notify(`PDA API错误。${err}`)); .catch(err => notify(`PDA API错误。${err}`));
}); });
@ -3523,6 +3490,38 @@
// 左侧“中”标签 // 左侧“中”标签
const $zhongNode = initIcon(); const $zhongNode = initIcon();
if ($zhongNode) { if ($zhongNode) {
// 更新词库按钮
$zhongNode.querySelector('#wh-trans-data-update').onclick = function () {
if (this.intervalID) return;
const url = isDev() ? 'http://192.168.1.7:8080/' : 'https://jjins.github.io/gengxin/';
const popup = window.open(url);
let hsCount = 0;
this.intervalID = window.setInterval(() => {
if (hsCount > 20) {
clearInterval(this.intervalID);
this.intervalID = null;
return;
}
popup.postMessage("connect", '*');
hsCount++;
}, 500);
let connected = false;
if (!this.msgEventCreated) {
window.addEventListener("message", (e) => {
this.msgEventCreated = true;
if (e.data === 'connected') {
connected = true;
clearInterval(this.intervalID);
this.intervalID = null;
return;
}
if (connected) {
// 传回的动态内容
log(e.data);
}
}, false);
}
}
// 小窗犯罪按钮 // 小窗犯罪按钮
$zhongNode.querySelector('#wh-quick-crime-btn').onclick = () => { $zhongNode.querySelector('#wh-quick-crime-btn').onclick = () => {
// 弹出小窗口 // 弹出小窗口
@ -3627,13 +3626,33 @@
// 开发详情按钮 // 开发详情按钮
$zhongNode.querySelector('#wh-devInfo').onclick = () => { $zhongNode.querySelector('#wh-devInfo').onclick = () => {
const date = new Date(); const date = new Date();
const insert = `当前页面: ${window.location.href}<br/> let os = '未知';
分辨率: ${window.innerWidth}x${window.innerHeight}<br/> try {
设备类型: ${getDeviceType()}<br/> os = window.navigator.userAgentData.platform || window.navigator.platform
脚本类型: ${getScriptEngine()}<br/> } catch {
时间: ${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}<br/> }
插件版本: ${version}<br/> let browser = window.navigator.appName;
`; try {
browser = window.navigator.userAgentData.brands[0].brand + ' ' + window.navigator.userAgentData.brands[0].version;
} catch {
}
const insert = `<table id="wh-dev-info-tb">
<tr><td>URL</td><td>${window.location.href}</td></tr>
<tr><td>页面尺寸</td><td>${window.innerWidth}x${window.innerHeight}</td></tr>
<tr><td>设备类型</td><td>${getDeviceType().toUpperCase()}</td></tr>
<tr><td>脚本运行方式</td><td>${{'gm':'','raw':'','pda':'TornPDA'}[getScriptEngine()]}</td></tr>
<tr><td>时间</td><td>${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}</td></tr>
<tr><td>插件版本</td><td>${version}</td></tr>
<tr><td>操作系统</td><td>${os}</td></tr>
<tr><td>浏览器</td><td>${browser}</td></tr>
</table>
<style>
#wh-dev-info-tb td{
padding: 2px 4px;
color:white;
}
</style>`;
popupMsg(insert, '开发者详情'); popupMsg(insert, '开发者详情');
}; };
} }
@ -3676,7 +3695,8 @@ padding:16px !important;
display:inline-block; display:inline-block;
background-image:url("https://jjins.github.io/t2i/version.png?${performance.now()}"); background-image:url("https://jjins.github.io/t2i/version.png?${performance.now()}");
height:16px; height:16px;
width: 66px;} width: 66px;
}
#wh-popup{ #wh-popup{
position: fixed; position: fixed;
z-index: 9900034; z-index: 9900034;
@ -3684,20 +3704,21 @@ width: 66px;}
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
background: #808080ba; background: #000000cc;
} }
#wh-popup-container{ #wh-popup-container{
max-width: 600px; max-width: 600px;
margin: 5em auto 0; margin: 5em auto 0;
background: #3c3c3c; background: #d7d7d7;
min-height: 200px; min-height: 120px;
box-shadow: 0 0 13px #b4b4b4 box-shadow: 0 0 5px 1px #898989;
border-radius: 4px;
} }
#wh-popup-title p{ #wh-popup-title p{
background: black; padding: 1em 0;
color: white;
padding: 1em;
font-size: 16px; font-size: 16px;
font-weight: bold;
text-align: center;
} }
#wh-popup-close{ #wh-popup-close{
float: right; float: right;
@ -3708,8 +3729,7 @@ width: 66px;}
border-radius: 3px; border-radius: 3px;
} }
#wh-popup-cont{ #wh-popup-cont{
padding: 1em; padding: 0 1em 1em;
color: white;
max-height: 30em; max-height: 30em;
overflow-y: auto; overflow-y: auto;
} }
@ -8231,9 +8251,9 @@ margin: 0 0 3px;
/* /*
保存脚本的配置 保存脚本的配置
*/ */
function saveSettings() { function saveSettings(not_notify = false) {
// 通知 // 通知
notify('已保存设置', 3) if (!not_notify) notify('已保存设置', 3)
localStorage.setItem('wh_trans_settings', JSON.stringify(wh_trans_settings)); localStorage.setItem('wh_trans_settings', JSON.stringify(wh_trans_settings));
} }
@ -8255,12 +8275,12 @@ margin: 0 0 3px;
popup.id = 'wh-popup'; popup.id = 'wh-popup';
popup.innerHTML = popup.innerHTML =
`<div id="wh-popup-container"> `<div id="wh-popup-container">
<div id="wh-popup-title"><button id="wh-popup-close">x</button><p>${title}</p></div> <div id="wh-popup-title"><!--button id="wh-popup-close">x</button--><p>${title}</p></div>
<div id="wh-popup-cont">${innerHTML}</div> <div id="wh-popup-cont">${innerHTML}</div>
</div>`; </div>`;
document.body.append(popup); document.body.append(popup);
const close_btn = popup.querySelector('#wh-popup-close'); // const close_btn = popup.querySelector('#wh-popup-close');
close_btn.onclick = () => popup.remove(); // close_btn.onclick = () => popup.remove();
const clickFunc = e => { const clickFunc = e => {
e.stopImmediatePropagation(); e.stopImmediatePropagation();
@ -8392,7 +8412,7 @@ margin: 0 0 3px;
* @param callback 通知结束后执行的函数 * @param callback 通知结束后执行的函数
* @returns HTMLElement 通知的node * @returns HTMLElement 通知的node
*/ */
function notify(msg = '', timeout = 3, callback = () => null) { function notify(msg = '', timeout = 3, callback = null) {
const date = new Date(); const date = new Date();
// 通知的唯一id // 通知的唯一id
const uid = `${date.getHours()}${date.getSeconds()}${date.getMilliseconds()}${getRandomInt(1000, 9999)}`; const uid = `${date.getHours()}${date.getSeconds()}${date.getMilliseconds()}${getRandomInt(1000, 9999)}`;
@ -8435,7 +8455,7 @@ margin: 0 0 3px;
const removeNode = () => { const removeNode = () => {
clearInterval(intervalID); clearInterval(intervalID);
new_node.remove(); new_node.remove();
callback(); if (callback !== null) callback();
}; };
new_node.querySelector('.wh-notify-close button').addEventListener('click', removeNode); new_node.querySelector('.wh-notify-close button').addEventListener('click', removeNode);
}; };