This commit is contained in:
Liwanyi 2022-10-09 17:56:16 +08:00
parent dd411a65fc
commit c010c488d6
33 changed files with 441 additions and 83 deletions

View File

@ -1,6 +1,6 @@
{
"name": "wuhu-torn-helper",
"version": "0.5.3",
"version": "0.5.4",
"description": "芜湖助手",
"dependencies": {},
"scripts": {

File diff suppressed because one or more lines are too long

View File

@ -33,7 +33,7 @@ export default class WuhuBase extends Provider {
window.WHTRANS = true;
}
public toString() {
return `[${ JSON.stringify(this) }]`;
}
// public toString() {
// return `[${ JSON.stringify(this) }]`;
// }
}

View File

@ -5,16 +5,15 @@ import TravelItem from "./action/TravelItem";
import Global from "./Global";
import Log from "./Log";
import WuhuConfig from "./WuhuConfig";
import * as CSS_JSON from "../static/json/css.json"
import COMMON_CSS from "../static/css/common.css";
export default class WuHuTornHelper extends WuhuBase {
init() {
Log.info('WuHuTornHelper初始化');
WuhuBase.glob = Global.getInstance() as Global;
WuhuBase.glob = Global.getInstance();
let glob = WuHuTornHelper.glob;
glob.fStock = TravelItem.getInstance();
Log.info('fStock: ', glob.fStock)
// 请求通知权限
if (window.Notification) {
@ -43,6 +42,9 @@ export default class WuHuTornHelper extends WuhuBase {
// 阻止获取新闻横幅
return new Response('{}');
}
if (url.includes('google')) {
return new Response('{}');
}
const res = await ori_fetch(url, init);
// mini profile 翻译
if (url.includes('profiles.php?step=getUserNameContextMenu') && WuhuConfig.get('transEnable')) {
@ -54,7 +56,7 @@ export default class WuHuTornHelper extends WuhuBase {
return clone;
};
CommonUtils.addStyle(CSS_JSON.css.replace('{{}}', performance.now().toString()));
CommonUtils.addStyle(COMMON_CSS.replace('{{}}', performance.now().toString()));
// 测试用
if ('Ok' !== localStorage['WHTEST']) {

View File

@ -2,7 +2,6 @@ import doQuickFly from "../func/module/doQuickFly";
import loadGS from "../func/module/loadGS";
import adHelper from "../func/module/adHelper";
import safeKeeper from "../func/module/safeKeeper";
import mdParse from "../func/utils/MarkdownParser";
import updateTransDict from "../func/translate/updateTransDict";
import landedRedirect from "../func/module/landedRedirect";
import initMiniProf from "../func/utils/initMiniProf";
@ -27,6 +26,7 @@ import DEV_DETAILS_HTML from "../static/html/zhong/setting/dev_details.html";
import QUICK_FLY_CSS from "../static/css/quick_fly.css";
import QUICK_LINK_CSS from "../static/css/quick_link.css";
import BuyBeerHelper from "./action/BuyBeerHelper";
import MDUtils from "./utils/MDUtils";
export default class ZhongIcon extends WuhuBase {
public static ZhongNode: MyHTMLElement = null;
@ -719,7 +719,7 @@ export default class ZhongIcon extends WuhuBase {
let update = await CommonUtils.COFetch('https://gitlab.com/JJins/wuhu-torn-helper/-/raw/dev/CHANGELOG.md?' + Date.now());
progressBar.style.width = '60%';
progressText.innerText = '解析中……';
let md = mdParse(update);
let md = MDUtils.getInstance().parse(update);
popup.append(md);
progressBar.style.width = '100%';
progressText.innerText = '加载完成';
@ -765,10 +765,9 @@ export default class ZhongIcon extends WuhuBase {
clickFunc: async function () {
Log.info('测试开始');
let helper = BuyBeerHelper.getInstance();
helper.start();
Log.info('is_running', helper.is_running());
helper.skip_today();
Log.info(ZhongIcon.getPool());
Log.info('is_running', BuyBeerHelper.getInstance().is_running());
Log.info('测试结束');
},

View File

@ -3,9 +3,9 @@ import WuhuConfig from "../WuhuConfig";
import Log from "../Log";
import InfoUtils from "../utils/InfoUtils";
import Alert from "../utils/Alert";
import audioPlay from "../../func/utils/audioPlay";
import MathUtils from "../utils/MathUtils";
import NOTIFY_HTML from "../../static/html/buyBeer/notify.html";
import CommonUtils from "../utils/CommonUtils";
export default class BuyBeerHelper extends WuhuBase implements BeerMonitorLoop {
@ -35,6 +35,7 @@ export default class BuyBeerHelper extends WuhuBase implements BeerMonitorLoop {
const now = [dt.getUTCFullYear(), dt.getUTCMonth(), dt.getUTCDate()];
const ignore_date = WuhuConfig.get('_15_alarm_ignore') || '{}';
if (JSON.stringify(now) === JSON.stringify(ignore_date)) return;
Log.info('不提醒状态', now, ignore_date);
// 正常提醒
let m = 14 - (dt.getMinutes() % 15);
let s = 60 - dt.getSeconds();
@ -59,6 +60,7 @@ export default class BuyBeerHelper extends WuhuBase implements BeerMonitorLoop {
notify.close();
}
});
let audioPlay = CommonUtils.getInstance().audioPlay;
window.setTimeout(audioPlay, 800);
window.setTimeout(audioPlay, 800 * 2);
window.setTimeout(audioPlay, 800 * 3);
@ -94,7 +96,7 @@ export default class BuyBeerHelper extends WuhuBase implements BeerMonitorLoop {
// 通知
const notify = new Alert(`明早8点前将不再提醒 <button id="wh-rd-btn-${ MathUtils.getInstance().getRandomInt(0, 100) }">取消</button>`);
// 通知中的取消按钮
notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => WuhuConfig.set('_15_alarm_ignore', undefined));
notify.getElement().querySelector('.wh-notify-msg button').addEventListener('click', () => WuhuConfig.set('_15_alarm_ignore', undefined, true));
}
}

View File

@ -17,7 +17,7 @@ export default class TravelItem extends WuhuBase {
if (!WindowActiveState.getInstance().get()) return;
Log.info('fetching https://yata.yt/api/v1/travel/export/');
const res = await CommonUtils.COFetch('https://yata.yt/api/v1/travel/export/');
Log.info('fetch returned');
Log.info('fetch returned: ', res);
this.obj = JSON.parse(res);
}, 30 * 1000);
}
@ -37,9 +37,10 @@ export default class TravelItem extends WuhuBase {
} else {
const popup = new Popup("请稍后 " + CommonUtils.loading_gif_html(), '飞花库存');
let table = `<table><tr><th colspan="2">目的地 - 更新时间</th><th colspan="3">库存</th></tr>`;
const dest = FILTER;
const dest = FILTER.default;
const now = new Date();
const res = await this.get();
Log.info({ res })
if (!res.stocks) return;
dest.forEach(el => {
const update = (now.getTime() - new Date(res.stocks[el.name]['update'] * 1000).getTime()) / 1000 | 0

View File

@ -4,10 +4,24 @@
export default class Provider {
private static instance;
private static readonly pool = {};
constructor() {
}
static getInstance<T extends typeof Provider>(this: T): InstanceType<T> {
return this.instance ||= new this();
public static getInstance<T extends typeof Provider>(this: T): InstanceType<T> {
// return this.instance ||= new this();
if (!this.instance) {
this.instance = new this();
Provider.pool[this.name] = this.instance;
}
return this.instance;
}
public static getPool() {
return {
pool: Provider.pool,
// Json: JSON.stringify(Provider.pool)
}
}
}

View File

@ -177,4 +177,18 @@ export default class CommonUtils extends WuhuBase {
static loading_gif_html(): string {
return LOADING_IMG_HTML;
}
/**
*
* @param {string} url URL
* @returns {undefined}
*/
public audioPlay(url: string = 'https://www.torn.com/js/chat/sounds/Warble_1.mp3') {
const audio = new Audio(url);
audio.addEventListener("canplaythrough", () => {
audio.play()
.catch(err => Log.error(err))
.then();
});
}
}

View File

@ -0,0 +1,59 @@
import WuhuBase from "../WuhuBase";
export default class MDUtils extends WuhuBase {
/**
* Markdown
* @param {String} from
* @param {Number} max_line 500
* @returns {HTMLDivElement}
*/
public parse(from: string, max_line?: number): HTMLElement {
max_line = max_line || 500;
const base = document.createElement('div');
let lines = from.split('\n');
if (lines.length > max_line) {
lines = lines.slice(0, max_line);
lines.push("...");
}
let prev = '';
let child_cont;
lines.forEach(line => {
if (line.trim() === '') return;
let node;
let spl = line.split(' ');
let md_flag = spl[0];
switch (md_flag) {
// 标题
case '#':
case '##':
case '###':
if (prev === 'li') {
child_cont = null;
}
prev = 'h' + (md_flag.length + 1);
node = document.createElement(prev);
node.innerText = line.slice(md_flag.length + 1);
base.append(node);
return;
// 列表
case '-':
if (prev !== 'li') {
child_cont = document.createElement('ul');
if (!base.contains(child_cont)) base.append(child_cont);
}
prev = 'li';
node = document.createElement(prev);
node.innerText = line.slice(2);
child_cont.append(node);
return;
}
prev = 'p';
node = document.createElement(prev);
node.innerText = line.trim();
base.append(node);
})
return base;
}
}

View File

@ -1,8 +1,8 @@
import popupMsg from "../utils/@deprecated/popupMsg";
import Popup from "../../class/utils/Popup";
// 传单助手
export default function adHelper() {
let popup = popupMsg('', '传单助手');
let popup = new Popup('', '传单助手').getElement();
document.querySelector('#chatRoot').classList.remove('wh-hide');
let info = document.createElement('p');
let ad_input = document.createElement('textarea');

View File

@ -1,7 +1,7 @@
import elementReady from "../utils/elementReady";
import toThousands from "../utils/toThousands";
import log from "../utils/@deprecated/log";
import CommonUtils from "../../class/utils/CommonUtils";
import Log from "../../class/Log";
export default function cityFinder(): void {
CommonUtils.addStyle(`
@ -67,10 +67,10 @@ display:inline-block;
CommonUtils.COFetch('https://jjins.github.io/item_price_raw.json')
.then(r => items = JSON.parse(r))
.catch(err => {
log.info(err)
Log.error(err);
items = undefined
});
elementReady('div.leaflet-marker-pane').then(elem => {
CommonUtils.elementReady('div.leaflet-marker-pane').then(elem => {
document.querySelector('#map').classList.add('wh-city-finds');
document.querySelector('.content-wrapper').prepend(base);
// 发现的物品id与map img node

View File

@ -5,6 +5,7 @@ import Alert from "../../class/utils/Alert";
import ActionButtonUtils from "../../class/utils/ActionButtonUtils";
import WuhuConfig from "../../class/WuhuConfig";
import FetchUtils from "../../class/utils/FetchUtils";
import DEPO_CSS from "../../static/css/depo.css";
export default function depoHelper() {
let actionButtonUtils: ActionButtonUtils = ActionButtonUtils.getInstance();
@ -48,13 +49,7 @@ export default function depoHelper() {
// 存钱框浮动
if (WuhuConfig.get('floatDepo') && channel) {
document.body.classList.add('wh-depo-helper');
CommonUtils.addStyle(`.wh-depo-helper div#funds div.deposit,
.wh-depo-helper div#armoury-donate div.cash{position: fixed !important;
top: 150px;
right: 12px;
box-shadow: 0 0 8px 1px #00000091;
background: #f2f2f2;
z-index: 999999;}`);
CommonUtils.addStyle(DEPO_CSS);
CommonUtils.elementReady(selector[channel]).then(node => {
const close_btn = document.createElement('button');
close_btn.addEventListener('click', () => {

View File

@ -1,6 +1,5 @@
import getWhSettingObj from "../utils/getWhSettingObj";
import setWhSetting from "../utils/setWhSetting";
import popupMsg from "../utils/@deprecated/popupMsg";
import WuhuConfig from "../../class/WuhuConfig";
import Popup from "../../class/utils/Popup";
// 落地转跳设置
export default function landedRedirect() {
@ -14,7 +13,7 @@ export default function landedRedirect() {
p.innerHTML = '飞机落地后转跳的页面,关闭功能请置空:';
input.placeholder = 'URL';
input.value = getWhSettingObj()['landedRedirect'] || '';
input.value = WuhuConfig.get('landedRedirect') || '';
input.style.display = 'block';
input.style.textAlign = 'left';
input.style.width = '100%';
@ -25,11 +24,11 @@ export default function landedRedirect() {
buttonFct.innerHTML = '填入帮派金库金库';
buttonTest.innerHTML = '测试链接';
buttonSave.addEventListener('click', () => setWhSetting('landedRedirect', input.value));
buttonSave.addEventListener('click', () => WuhuConfig.set('landedRedirect', input.value, true));
buttonCmp.addEventListener('click', () => input.value = 'https://www.torn.com/companies.php#/option=funds');
buttonFct.addEventListener('click', () => input.value = 'https://www.torn.com/factions.php?step=your#/tab=armoury');
buttonTest.addEventListener('click', () => window.open(input.value));
let node = popupMsg('', '落地转跳');
let node = new Popup('', '落地转跳').getElement();
node.append(p, input, buttonSave, br, buttonCmp, buttonFct, buttonTest);
}

View File

@ -1,4 +1,4 @@
import getWhSettingObj from "../utils/getWhSettingObj";
import getWhSettingObj from "../utils/@deprecated/getWhSettingObj";
import log from "../utils/@deprecated/log";
import toThousands from "../utils/toThousands";
import Log from "../../class/Log";

View File

@ -1,4 +1,4 @@
import audioPlay from "../audioPlay";
import audioPlay from "./audioPlay";
import MathUtils from "../../../class/utils/MathUtils";
import Alert from "../../../class/utils/Alert";
import InfoUtils from "../../../class/utils/InfoUtils";

View File

@ -1,5 +1,5 @@
import UserScriptEngine from "../../../enum/UserScriptEngine";
import getScriptEngine from "../getScriptEngine";
import getScriptEngine from "./getScriptEngine";
import Log from "../../../class/Log";
/**

View File

@ -0,0 +1,6 @@
/**
* @deprecated
*/
export default function Compare2Object(obj1, obj2) {
return JSON.stringify(obj1) === JSON.stringify(obj2)
}

View File

@ -3,6 +3,7 @@
* @param {String} from
* @param {Number} max_line 500
* @returns {HTMLDivElement}
* @deprecated
*/
export default function mdParse(from: string, max_line?: number): HTMLElement {
max_line = max_line || 500;

View File

@ -1,7 +1,7 @@
import addStyle from "./@deprecated/addStyle";
import WuhuBase from "../../class/WuhuBase";
import MathUtils from "../../class/utils/MathUtils";
import WindowActiveState from "../../class/action/WindowActiveState";
import addStyle from "./addStyle";
import WuhuBase from "../../../class/WuhuBase";
import MathUtils from "../../../class/utils/MathUtils";
import WindowActiveState from "../../../class/action/WindowActiveState";
/**
*
@ -13,6 +13,7 @@ import WindowActiveState from "../../class/action/WindowActiveState";
* @param {string} [options.sysNotifyTag] -
* @param {function} [options.sysNotifyClick] -
* @return {HTMLElement}
* @deprecated
*/
export default function WHNotify(msg: string, options: WHNotifyOpt = {}): MyHTMLElement {
let { notifies } = WuhuBase.glob;

View File

@ -1,9 +1,10 @@
import Log from "../../class/Log";
import Log from "../../../class/Log";
/**
*
* @param {string} url URL
* @returns {undefined}
* @deprecated
*/
export default function audioPlay(url: string = 'https://www.torn.com/js/chat/sounds/Warble_1.mp3') {
const audio = new Audio(url);

View File

@ -1,5 +1,5 @@
import UserScriptEngine from "../../enum/UserScriptEngine";
import WuhuBase from "../../class/WuhuBase";
import UserScriptEngine from "../../../enum/UserScriptEngine";
import WuhuBase from "../../../class/WuhuBase";
/**
* @deprecated

View File

@ -1,5 +1,5 @@
import elementReady from "../elementReady";
import log from "./log";
import CommonUtils from "../../../class/utils/CommonUtils";
import Log from "../../../class/Log";
/**
* @deprecated
@ -12,10 +12,9 @@ export default async function getSidebarData() {
if (sessionKeys.length < 2) {
// dom获取
let sidebar_menu_list = document.querySelectorAll('#sidebar a span[class*="linkName___"]');
log.info({ sidebar_menu_list })
Log.info({ sidebar_menu_list })
if (sidebar_menu_list.length === 0) {
// TODO 当前根据侧边栏等待 sessionData
await elementReady('#sidebar a span[class*="linkName___"]');
await CommonUtils.elementReady('#sidebar a span[class*="linkName___"]');
sidebar_menu_list = document.querySelectorAll('#sidebar a span[class*="linkName___"]');
}
sidebar_menu_list.forEach(node => ret[node.innerHTML.trim().toLowerCase().replaceAll(' ', '_')] = true);
@ -33,9 +32,9 @@ export default async function getSidebarData() {
}
}
}
log.info({ ret, sidebar_id, sessionKeys })
Log.info({ ret, sidebar_id, sessionKeys })
if (Object.keys(ret).length === 0) {
log.error('无法获取数据,建议刷新重试');
Log.error('无法获取数据,建议刷新重试');
}
return ret;
}

View File

@ -1,4 +1,4 @@
import getWhSettingObj from "../getWhSettingObj";
import getWhSettingObj from "./getWhSettingObj";
/**
* @deprecated

View File

@ -1,5 +1,5 @@
import getWhSettingObj from "./getWhSettingObj";
import Alert from "../../class/utils/Alert";
import Alert from "../../../class/utils/Alert";
/**
* @deprecated

View File

@ -1,3 +0,0 @@
export default function (obj1, obj2) {
return JSON.stringify(obj1) === JSON.stringify(obj2)
}

270
src/static/css/common.css Normal file
View File

@ -0,0 +1,270 @@
.wh-hide {
display: none;
}
#wh-trans-icon {
user-select: none;
display: inline-block;
position: fixed;
top: 5px;
left: 5px;
z-index: 100010;
border-radius: 4px;
max-width: 220px;
box-shadow: 0 0 3px 1px #8484848f;
}
div#effectiveness-wrap {
overflow-y: hidden;
}
@media screen and (max-width: 600px) {
#wh-trans-icon {
top: 0;
left: 112px;
}
/* 冰蛙公司效率表 */
div#effectiveness-wrap {
margin-left: -76px;
margin-right: -76px;
}
}
#wh-trans-icon select {
width: 110px;
}
#wh-trans-icon a {
text-decoration: none;
color: #006599;
background: none;
}
#wh-trans-icon:not(.wh-icon-expanded):hover {
background: #f8f8f8;
}
#wh-trans-icon button {
margin: 0;
padding: 0;
border: 0;
cursor: pointer;
}
#wh-inittimer {
margin-top: 6px;
color: #b0b0b0;
}
#wh-gSettings div {
margin: 4px 0;
}
#wh-trans-icon .wh-container {
margin: 0;
padding: 0 16px 16px;
border: 0;
}
#wh-trans-icon-btn {
height: 16px;
width: 16px;
background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M160 144a32 32 0 0 0-32 32V864a32 32 0 0 0 32 32h688a32 32 0 0 0 32-32V176a32 32 0 0 0-32-32H160z m0-64h688a96 96 0 0 1 96 96V864a96 96 0 0 1-96 96H160a96 96 0 0 1-96-96V176a96 96 0 0 1 96-96z"/><path d="M482.176 262.272h59.616v94.4h196v239.072h-196v184.416h-59.616v-184.416H286.72v-239.04h195.456V262.24z m-137.504 277.152h137.504v-126.4H344.64v126.4z m197.12 0h138.048v-126.4H541.76v126.4z"/></svg>') no-repeat center;
padding: 16px !important;
}
#wh-trans-icon .wh-container {
display: none;
}
#wh-trans-icon.wh-icon-expanded .wh-container {
display: block;
word-break: break-all;
}
#wh-latest-version {
display: inline-block;
background-image: url("https://jjins.github.io/t2i/version.png?{{}}");
height: 16px;
width: 66px;
}
/** 弹出窗口 **/
#wh-popup {
position: fixed;
z-index: 200000;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #00000090;
color: #333;
}
div#wh-popup::after {
content: '点击空白处关闭';
display: block;
color: #ffffffdb;
text-align: center;
font-size: 14px;
line-height: 22px;
}
#wh-popup-container {
max-width: 568px;
margin: 5em auto 0;
background: #d7d7d7;
min-height: 120px;
box-shadow: 0 0 5px 1px #898989;
border-radius: 4px;
}
#wh-popup-title p {
padding: 1em 0;
font-size: 16px;
font-weight: bold;
text-align: center;
}
/** 弹出窗口的内容 **/
#wh-popup-cont {
padding: 0 1em 1em;
max-height: 30em;
overflow-y: auto;
font-size: 14px;
line-height: 16px;
}
#wh-popup-cont .gSetting > div {
display: inline-block;
width: 47%;
margin: 2px 0;
}
#wh-popup-cont .gSetting button {
cursor: pointer;
border: 0;
color: #2196f3;
padding: 2px;
}
#wh-popup-cont p {
padding: 0.25em 0;
}
#wh-popup-cont a {
color: red;
text-decoration: none;
}
#wh-popup-cont li {
margin: 4px 0;
}
#wh-popup-cont h4 {
margin: 0;
padding: 0.5em 0;
}
#wh-popup-cont button {
margin: 0 4px 0 0;
padding: 5px 8px;
border: solid 2px black;
color: black;
border-radius: 3px;
}
#wh-popup-cont button[disabled] {
opacity: 0.5;
}
#wh-popup-cont input {
padding: 2px;
text-align: center;
border: 1px solid #fff0;
border-radius: 5px;
margin: 1px 2px;
}
#wh-popup-cont input:focus {
border-color: blue;
}
#wh-popup-cont table {
width: 100%;
border-collapse: collapse;
border: 1px solid;
}
#wh-popup-cont td, #wh-popup-cont th {
border-collapse: collapse;
padding: 4px;
border: 1px solid;
}
.wh-display-none {
display: none !important;
}
#wh-gym-info-cont {
background-color: #363636;
color: white;
padding: 8px;
font-size: 15px;
border-radius: 4px;
text-shadow: 0 0 2px black;
background-image: linear-gradient(90deg, transparent 50%, rgba(0, 0, 0, .07) 0);
background-size: 4px;
line-height: 20px;
}
#wh-gym-info-cont button {
cursor: pointer;
}
#wh-notify {
display: inline-block;
position: fixed;
top: 0;
left: calc(50% - 180px);
width: 360px;
z-index: 9999990;
color: #333;
}
#wh-notify a {
color: red;
text-decoration: none;
}
#wh-notify .wh-notify-item { /*height: 50px;*/
background: rgb(239 249 255 / 90%);
border-radius: 2px;
margin: 0.5em 0 0 0;
box-shadow: 0 0 5px 0px #959595;
}
#wh-notify .wh-notify-item:hover {
background: rgb(239 249 255 / 98%);
}
#wh-notify .wh-notify-item .wh-notify-bar {
height: 2px;
background: #2196f3;
}
#wh-notify .wh-notify-item .wh-notify-close {
float: right;
padding: 0;
width: 16px;
height: 16px;
background: url('data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%201024%201024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M923%20571H130.7c-27.6%200-50-22.4-50-50s22.4-50%2050-50H923c27.6%200%2050%2022.4%2050%2050s-22.4%2050-50%2050z%22%20fill%3D%22%232196f3%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E') no-repeat center;
background-size: 100%;
margin: 6px 6px 0 0;
cursor: pointer;
}
#wh-notify .wh-notify-item .wh-notify-msg {
padding: 12px;
}

9
src/static/css/depo.css Normal file
View File

@ -0,0 +1,9 @@
.wh-depo-helper div#funds div.deposit,
.wh-depo-helper div#armoury-donate div.cash {
position: fixed !important;
top: 150px;
right: 12px;
box-shadow: 0 0 8px 1px #00000091;
background: #f2f2f2;
z-index: 999999;
}