This commit is contained in:
Liwanyi 2022-09-13 18:10:23 +08:00
parent 5534776e77
commit 28fac2d8c5
13 changed files with 2953 additions and 3032 deletions

6
global.d.ts vendored
View File

@ -1,5 +1,11 @@
declare interface String { declare interface String {
contains(keywords: RegExp | string): boolean; contains(keywords: RegExp | string): boolean;
/* 翻译 */
// 时分秒转换
replaceHMS(): string;
// 数词转换 a an some
numWordTrans(): string;
} }
declare interface Window { declare interface Window {

View File

@ -0,0 +1,21 @@
import {titleLinksDict} from "../../dictionary/translation";
// 页标题右侧按钮
export default function contentTitleLinksTrans() {
const $links_default = document.querySelectorAll('div.content-title span:nth-child(2)');
const $links = $links_default.length === 0
? document.querySelectorAll('div[class^="topSection"] span[class*="Title"]')
: $links_default;
$links.forEach(e => {
if (titleLinksDict[e.innerText.trim()]) {
e.innerText = titleLinksDict[e.innerText.trim()];
} else if (e.id === 'events') {
if (titleLinksDict[e.innerText.trim().split(' ')[0]])
e.innerText = e.innerText.trim()
.replace(
e.innerText.trim().split(' ')[0],
titleLinksDict[e.innerText.trim().split(' ')[0]]
);
}
});
}

View File

@ -0,0 +1,8 @@
import {titleLinksDict} from "../../dictionary/translation";
export default function contentTitleLinksTransReact(dom = document.querySelectorAll('div[class^="linksContainer___"] span[class^="linkTitle___"]')) {
dom.forEach(e => {
const links_trans = titleLinksDict[e.innerText.trim()];
if (links_trans) e.innerText = links_trans;
});
}

View File

@ -0,0 +1,32 @@
/**
* ob
* @deprecated TODO
*/
import log from "../utils/log";
export default function initOB(dom: Document | Element = document, opt = {}, func = () => {
}, dev = false, once = false) {
//let count = -1;
if (dev) {
const mo = new MutationObserver((mutation) => {
//count++;
log.info(mutation)
mo.disconnect();
func();
if (!once) {
mo.observe(dom, opt)
}
});
func();
mo.observe(dom, opt);
} else {
//count++;
const mo = new MutationObserver(() => {
mo.disconnect();
func();
if (!once) mo.observe(dom, opt)
});
func();
mo.observe(dom, opt)
}
}

View File

@ -0,0 +1,39 @@
import {itemEffectDict, itemNameDict, itemPageDict, itemTypeDict} from "../../dictionary/translation";
// 展开物品详情
export default function showItemInfoTrans(dom: HTMLElement = document.querySelector('.show-item-info')) {
if (dom) {
const $item_info = dom.querySelector('span.info-msg');
if ($item_info) {
// tt插件
const is_tt_modified = !!$item_info.querySelector('.tt-modified');
if (is_tt_modified) {
console.warn(is_tt_modified)
}
// 物品名
const $item_name = $item_info.querySelector('span.bold');
// 去除物品名的the
const the_removed = $item_name.innerText.trim().slice(4);
// 物品的类别
const $item_type = $item_name.nextSibling;
// 绿字 物品效果
const $item_effect = $item_info.querySelector('div.item-effect');
if (itemNameDict[the_removed]) {
$item_name.innerText = `${itemNameDict[the_removed]}(${the_removed})`;
}
if (itemTypeDict[$item_type.nodeValue.trim()]) {
$item_type.nodeValue = itemTypeDict[$item_type.nodeValue.trim()];
}
if ($item_effect && itemEffectDict[$item_effect.innerText.trim()]) {
$item_effect.innerText = itemEffectDict[$item_effect.innerText.trim()];
}
}
// 下方的表格
const $info_table_title = dom.querySelectorAll('div.title');
$info_table_title.forEach((e) => {
if (itemPageDict[e.innerText.trim()]) {
e.innerText = itemPageDict[e.innerText.trim()];
}
});
}
}

View File

@ -0,0 +1,12 @@
import {cityDict, titleDict} from "../../dictionary/translation";
/**
*
*/
export default function titleTrans() {
let node = $('h4#skip-to-content');
const $title = node.length === 0 ? $('h4[class^="title"]') : node;
const title = titleDict[$title.text().trim()] || cityDict[$title.text().trim()];
if (title && $title.css('display') !== 'none')
$title.after($title.clone().text(title)).css('display', 'none');
}

View File

@ -0,0 +1,8 @@
import {titleDict} from "../../dictionary/translation";
export default function titleTransReact(dom = document.querySelectorAll('h4[class^="title___"]')) {
dom.forEach(e => {
const title_trans = titleDict[e.innerText.trim()];
if (title_trans) e.innerText = title_trans;
});
}

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,8 @@ import WindowActiveState from "./func/utils/WindowActiveState";
import addStyle from "./func/utils/addStyle"; import addStyle from "./func/utils/addStyle";
// 初始化方法,获取必要全局参数 // 初始化方法,获取必要全局参数
export default function init(glob: Global) { export default function init(): Global {
let glob: Global = {};
glob.window = window; glob.window = window;
window.WHPARAMS = glob; window.WHPARAMS = glob;
let UWCopy = null; let UWCopy = null;
@ -40,7 +41,7 @@ export default function init(glob: Global) {
Notification.requestPermission().then(); Notification.requestPermission().then();
} }
// 扩展String正则方法 // 扩展正则方法
String.prototype.contains = function (keywords) { String.prototype.contains = function (keywords) {
let that: string = this; let that: string = this;
if ('string' === typeof keywords) { if ('string' === typeof keywords) {
@ -82,6 +83,8 @@ export default function init(glob: Global) {
// 抢啤酒 // 抢啤酒
glob.beer = BuyBeer(); glob.beer = BuyBeer();
// 当前的弹出窗口
glob.popup_node = null; glob.popup_node = null;
// 当窗口关闭时关闭所有还存在的通知 // 当窗口关闭时关闭所有还存在的通知
@ -100,6 +103,8 @@ export default function init(glob: Global) {
// 记录当前窗口唯一id // 记录当前窗口唯一id
glob.isWindowActive = WindowActiveState(); glob.isWindowActive = WindowActiveState();
glob.href = window.location.href;
addStyle(` addStyle(`
.wh-hide{display:none;} .wh-hide{display:none;}
#wh-trans-icon{ #wh-trans-icon{
@ -247,4 +252,5 @@ cursor:pointer;
} }
`); `);
return glob;
} }

View File

@ -2,8 +2,12 @@ import Device from "../enum/Device";
import {BeerMonitorLoop} from "../func/utils/BuyBeer"; import {BeerMonitorLoop} from "../func/utils/BuyBeer";
export default interface Global { export default interface Global {
href?: string;
$zhongNode?: MyHTMLElement;
isWindowActive?(): boolean; isWindowActive?(): boolean;
popup_node?: Element;
popup_node?: MyHTMLElement;
beer?: BeerMonitorLoop; beer?: BeerMonitorLoop;
notifies?: NotifyWrapper; notifies?: NotifyWrapper;
priceWatcher?: { status: boolean }; priceWatcher?: { status: boolean };
@ -16,5 +20,5 @@ export default interface Global {
version?: string; version?: string;
window?: Window; window?: Window;
UWCopy?: Window & typeof globalThis; UWCopy?: Window & typeof globalThis;
startTimestamp: number; // startTimestamp: number;
} }

View File

@ -1,8 +1,23 @@
import userscript from "./userscript"; import userscript from "./userscript";
import Global from "./interface/GlobalVars"; import zhongIcon from "./zhongIcon";
import init from "./init";
import getWhSettingObj from "./func/utils/getWhSettingObj";
import translateMain from "./func/translate/translateMain";
const glob: Global = { (function main() {
startTimestamp: -1, let started = new Date().getTime();
};
userscript(glob); if (document.title.toLowerCase().includes('just a moment')) return;
let glob = init();
zhongIcon(glob);
if (getWhSettingObj()['transEnable']) translateMain(glob.href);
userscript();
let runTime = new Date().getTime() - started;
glob.$zhongNode.initTimer.innerHTML = `助手加载时间 ${runTime}ms`;
})
();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff