Skip to content

Commit

Permalink
适配v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Shan committed Jun 14, 2024
1 parent 83e8612 commit 6d10253
Show file tree
Hide file tree
Showing 25 changed files with 787 additions and 526 deletions.
2 changes: 2 additions & 0 deletions chainWebpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const chainWebpack = (config) => {
}
config.entry('background').add(path.resolve(__dirname, './src/background/index.js'));
config.entry('contentScripts').add(path.resolve(__dirname, './src/contentScripts/index.js'));
config.entry('offscreen/img2blob').add(path.resolve(__dirname, './src/offscreen/js/img2blob.js'));
config.output.filename('[name].js');

config.plugin('copy').tap((_args) => {
Expand All @@ -83,6 +84,7 @@ const chainWebpack = (config) => {
},
{ from: 'src/Dun-Cookies-Info.json', to: '[name][ext]' },
{ from: 'node_modules/element-ui/lib/theme-chalk/fonts/', to: 'css/fonts/[name][ext]' },
{ from: 'src/offscreen/html', to: 'offscreen' },
],
},
];
Expand Down
88 changes: 56 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ceobe-canteen-browser-extension",
"version": "4.0.5",
"version": "5.0.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand All @@ -15,7 +15,7 @@
"@enraged-dun-cookie-development-team/cookie-fetcher-core": "^0.0.1-alpha.16",
"animate.css": "^4.1.1",
"core-js": "^3.25.1",
"crypto-js": "^4.1.1",
"crypto-js": "^4.2.0",
"element-ui": "^2.15.9",
"fastest-levenshtein": "^1.0.16",
"html2canvas": "^1.4.1",
Expand Down Expand Up @@ -45,7 +45,7 @@
"less": "^4.1.3",
"less-loader": "^8.1.1",
"lint-staged": "^13.0.3",
"postcss": "^8.4.16",
"postcss": "^8.4.31",
"postcss-html": "^1.5.0",
"postcss-less": "6.0.0",
"prettier": "^2.7.1",
Expand Down
16 changes: 12 additions & 4 deletions src/background/CookieHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { WeiboDataSource } from './fetcher/impl/local/WeiboDataSource';
import { NeteaseCloudMusicDataSource } from './fetcher/impl/local/NeteaseCloudMusicDataSource';
import { GameBulletinListDataSource } from './fetcher/impl/local/GameBulletinListDataSource';
import { MonsterSirenDataSource } from './fetcher/impl/local/MonsterSirenDataSource';
import { ArknightsOfficialWebDataSource } from './fetcher/impl/local/ArknightsOfficialWebDataSource';
import { TerraHistoricusDataSource } from './fetcher/impl/local/TerraHistoricusDataSource';
import AvailableDataSourceMeta from '../common/sync/AvailableDataSourceMeta';
import { CookieItem } from '../common/CookieItem';
Expand All @@ -22,6 +21,16 @@ import { registerUrlToAddReferer } from './request_interceptor';
* @type {[string, string][]}
*/
const lastCookiesCache = [];
const lastCookiesCacheStorageKey = 'cache:lastCookies';
PlatformHelper.Storage.getLocalStorage(lastCookiesCacheStorageKey).then((data) => {
if (typeof data === 'string' && data.length > 0) {
const cache = JSON.parse(data);
if (Array.isArray(cache) && cache.length > 0) {
lastCookiesCache.push(...cache);
}
}
});

/**
* 只缓存指定数量的饼用于检测重复
* @type {number}
Expand Down Expand Up @@ -79,6 +88,7 @@ function tryNotice(source, newCookieList) {
lastCookiesCache.shift();
}
}
void PlatformHelper.Storage.saveLocalStorage(lastCookiesCacheStorageKey, JSON.stringify(lastCookiesCache));
}

const LocalCardMap = {};
Expand Down Expand Up @@ -117,12 +127,10 @@ class CookieHandler {
return GameBulletinListDataSource.processData(it.rawContent, sourceId);
case 'arknights-website:monster-siren':
return MonsterSirenDataSource.processData(it.rawContent, sourceId);
case 'arknights-website:official-website':
return ArknightsOfficialWebDataSource.processData(it.rawContent, sourceId);
case 'arknights-website:terra-historicus':
return TerraHistoricusDataSource.processData(it.rawContent, sourceId);
default:
console.warn('未知数据源类型:' + it.dataSourceId.typeId);
console.warn('不支持的数据源类型:' + it.dataSourceId.typeId);
}
}
})
Expand Down
97 changes: 97 additions & 0 deletions src/background/countdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import DebugUtil from '../common/util/DebugUtil';
import CountDown from '../common/sync/CountDownInfo';
import PlatformHelper from '../common/platform/PlatformHelper';
import NotificationUtil from '../common/util/NotificationUtil';
import TimeUtil from '../common/util/TimeUtil';

function countDownDebugLog(...data) {
DebugUtil.debugConsoleOutput(0, 'debug', '%c 倒计时 ', 'color: white; background: #DA70D6', ...data);
}

const countDownThreshold = 5 * 60 * 1000;
let countDownFlag = false;
const countDown = {
sendNoticeList: [],
countDownList: [],
Start() {
CountDown.getCountDownLocalStorage().then((data) => {
data = JSON.parse(data);
if (data) {
this.countDownList = [];
data
.map((x) => x.data)
.forEach((item) => {
this.countDownList.push(item);
const endTime = new Date(item.stopTime).getTime();
const delayTime = endTime - new Date().getTime();
if (delayTime >= countDownThreshold) {
countDownDebugLog(`设置alarm[${item.name}]-指定时间:${new Date(endTime).toLocaleString()}`);
const uniqueName = 'countdown_' + item.name + '|' + Math.random().toFixed(3).substring(2, 5);
PlatformHelper.Alarms.create(uniqueName, { when: endTime });
} else {
countDownDebugLog(`设置setTimeout[${item.name}]-延时:${delayTime}`);
this.sendNoticeList.push(
setTimeout((_) => {
NotificationUtil.SendNotice(
`倒计时完毕`,
`${item.name} 到点了!`,
null,
'countdown_' + new Date().getTime()
);
// 有过通知后从内存中删除计时器数据
CountDown.removeCountDown(item);
}, delayTime)
);
}
});
}
});
},
Change() {
if (countDownFlag) {
return;
}
countDownFlag = true;
countDownDebugLog('清空setTimeout');
this.sendNoticeList.forEach((id) => {
clearTimeout(id);
});
this.sendNoticeList = [];
countDownDebugLog('清空alarms');
// TODO 简单粗暴全清了显然不行
// PlatformHelper.Alarms.clearAll().finally(() => {
// this.Start();
// countDownFlag = false;
// });
},
GetAllCountDown() {
let list = [];
this.countDownList.forEach((item) => {
let value = TimeUtil.calcDiff(new Date(item.stopTime), new Date());
if (value != '') {
list.push({ ...item, timeStr: value, stopTime: TimeUtil.format(item.stopTime, 'yyyy-MM-dd hh:mm:ss') });
}
});
return list;
},
};

function countdownAlarmHandler(alarm) {
if (!alarm || !alarm.name) return;
if (alarm.name.startsWith('countdown_')) {
const countDownName = name.split('|')[0].substring('countdown_'.length);
NotificationUtil.SendNotice(`倒计时完毕`, `${countDownName} 到点了!`, null, 'countdown_' + new Date().getTime());
void CountDown.removeCountDownByName(countDownName);
}
}

// TODO 暂时没有启用倒计时
export function CountDownInit() {
countDown.Start();
PlatformHelper.osIsMac().then((isMac) => {
if (isMac) {
setInterval(() => countDown.Change(), 10 * 60 * 1000);
}
});
PlatformHelper.Alarms.addListener(countdownAlarmHandler);
}
Loading

0 comments on commit 6d10253

Please sign in to comment.