From 2371a8691d1eb44d1b59ae7294f9d15b05d6b2a7 Mon Sep 17 00:00:00 2001 From: Wx-2025 <351320169@qq.com> Date: Tue, 5 Aug 2025 07:10:28 +0800 Subject: [PATCH] Add files via upload --- utils/auth.js | 194 +++++++++++++++++++++++++++++++++++++++++- utils/settings.js | 2 +- utils/tagProcessor.js | 22 ++++- 3 files changed, 215 insertions(+), 3 deletions(-) diff --git a/utils/auth.js b/utils/auth.js index 566e818..e703ed4 100644 --- a/utils/auth.js +++ b/utils/auth.js @@ -1 +1,193 @@ -const _0x4776e2=_0x4d2e;(function(_0x4f91f6,_0x4e7f7f){const _0x463c60=_0x4d2e,_0x2a02b6=_0x4f91f6();while(!![]){try{const _0x4353b1=parseInt(_0x463c60(0x19a))/0x1+-parseInt(_0x463c60(0x16b))/0x2*(-parseInt(_0x463c60(0x192))/0x3)+-parseInt(_0x463c60(0x177))/0x4+parseInt(_0x463c60(0x194))/0x5*(-parseInt(_0x463c60(0x16e))/0x6)+parseInt(_0x463c60(0x18a))/0x7+-parseInt(_0x463c60(0x16d))/0x8*(-parseInt(_0x463c60(0x184))/0x9)+-parseInt(_0x463c60(0x18e))/0xa*(parseInt(_0x463c60(0x180))/0xb);if(_0x4353b1===_0x4e7f7f)break;else _0x2a02b6['push'](_0x2a02b6['shift']());}catch(_0x209b78){_0x2a02b6['push'](_0x2a02b6['shift']());}}}(_0x3bdf,0x24b0d));import{extension_settings}from'/scripts/extensions.js';import{saveSettings,extensionName}from'./settings.js';import{updateUI}from'../ui/state.js';export const pluginAuthStatus={'authorized':![],'expired':![]};function _0x3bdf(){const _0x39b370=['286wqWPLD','seed','当前授权有效期至:\x20','[Amily2号]\x20检测到授权过期,已清理本地存储。','315tiygVM','plugin_auth_code','\x0a\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20','slideUp','','removeItem','643475vBcOVS','plugin_activated','enabled','getItem','33910orReGg','.plugin-features','expiryDate','log','48801hhOhAW','\x20对应第','90xxkyrH','expired','true','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20','setItem','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20授权有效期至:\x20','85268VjWfTG','-AMILY_','join','\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20是否在有效期内:\x20','length','天\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20有效期至:\x20','getDate','天内将自动登录。','激活失败','getFullYear','push','success','ABCDEFGHJKLMNPQRSTUVWXYZ23456789','ceil','30SQHRvq','授权激活成功!','27640loeDga','28824nwvPJj','toLocaleDateString','authorized','charCodeAt','[Amily2号]\x20密码匹配:\x20','abs','plugin_valid_until','toISOString','\x0a\x20\x20\x20\x20\x20\x20\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20授权有效期:\x20','868800GXOAhV','#auth_panel','charAt','validityDays','[Amily2号]\x20密码有效期为:\x20','setDate','error','slideDown','授权码无效'];_0x3bdf=function(){return _0x39b370;};return _0x3bdf();}const PASSWORD_VALIDITY_DAYS=0x7,AUTH_CONFIG={'expiryDate':new Date('2025-12-31'),'validityDays':PASSWORD_VALIDITY_DAYS};console[_0x4776e2(0x191)](_0x4776e2(0x17b)+PASSWORD_VALIDITY_DAYS+'天');function generateDynamicPassword(_0x3f749a=new Date()){const _0x1dfe87=_0x4776e2,_0x17af26={'a':0x41c64e6d,'c':0x3039,'m':0x7fffffff};function _0x364e47(_0x104c98){const _0x14ba44=_0x4d2e;let _0x54b8a1=0x0;for(let _0x24f53e=0x0;_0x24f53e<_0x104c98[_0x14ba44(0x161)];_0x24f53e++){_0x54b8a1=(_0x54b8a1<<0x5)-_0x54b8a1+_0x104c98[_0x14ba44(0x171)](_0x24f53e),_0x54b8a1|=0x0;}return _0x54b8a1>>>0x0;}const _0x4556d5=_0x3f749a['getMonth']()+0x1,_0x20ce2e=_0x3f749a[_0x1dfe87(0x163)](),_0x6cad8d=_0x3f749a[_0x1dfe87(0x166)](),_0x87cca6=_0x4556d5+'-'+_0x20ce2e+_0x1dfe87(0x19b)+_0x6cad8d,_0x1fb883='SD'+_0x364e47(_0x87cca6),_0x67caae='V'+_0x364e47(_0x1fb883);function _0x3bad79(_0x268f62){return function(){const _0x46ba40=_0x4d2e;return _0x268f62[_0x46ba40(0x181)]=(_0x268f62['a']*_0x268f62['seed']+_0x268f62['c'])%_0x268f62['m'],_0x268f62[_0x46ba40(0x181)];};}const _0x3a178b=_0x364e47(_0x67caae)%_0x17af26['m'],_0x32221d=_0x3bad79({..._0x17af26,'seed':_0x3a178b}),_0x1ef156=_0x1dfe87(0x169),_0x272b58=[];for(let _0xbbf556=0x0;_0xbbf556<0x3;_0xbbf556++){let _0x5c7054='';for(let _0x1212bd=0x0;_0x1212bd<0x4;_0x1212bd++){const _0x35c1fa=Math[_0x1dfe87(0x173)](_0x32221d());_0x5c7054+=_0x1ef156[_0x1dfe87(0x179)](_0x35c1fa%_0x1ef156['length']);}_0x272b58[_0x1dfe87(0x167)](_0x5c7054);}return _0x272b58[_0x1dfe87(0x15f)]('-');}export function getPasswordForDate(_0xf8bf2e=new Date()){return generateDynamicPassword(_0xf8bf2e);}export function checkAuthorization(){const _0x3b0cf3=_0x4776e2,_0x396cfb=new Date();pluginAuthStatus[_0x3b0cf3(0x195)]=_0x396cfb>AUTH_CONFIG[_0x3b0cf3(0x190)];pluginAuthStatus[_0x3b0cf3(0x195)]&&(localStorage[_0x3b0cf3(0x189)](_0x3b0cf3(0x18b)),localStorage[_0x3b0cf3(0x189)](_0x3b0cf3(0x185)),localStorage['removeItem'](_0x3b0cf3(0x174)),console[_0x3b0cf3(0x191)](_0x3b0cf3(0x183)));const _0x187894=localStorage[_0x3b0cf3(0x18d)]('plugin_activated')===_0x3b0cf3(0x196),_0x4556b3=localStorage['getItem'](_0x3b0cf3(0x185)),_0x2abb19=localStorage['getItem'](_0x3b0cf3(0x174));let _0x190d9b=![];if(_0x2abb19){const _0x4f7394=new Date(_0x2abb19);_0x190d9b=_0x396cfb<=_0x4f7394,console[_0x3b0cf3(0x191)]('[Amily2号]\x20授权有效期检查:\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20当前时间:\x20'+_0x396cfb[_0x3b0cf3(0x175)]()+_0x3b0cf3(0x199)+_0x4f7394[_0x3b0cf3(0x175)]()+_0x3b0cf3(0x160)+_0x190d9b);}let _0x5aecd2=![];if(_0x4556b3){const _0x413a5c=new Date();for(let _0x27fdb2=0x0;_0x27fdb2AUTH_CONFIG[_0x2d3b0c(0x190)])return toastr['error']('授权已过期',_0x2d3b0c(0x165)),![];const _0x24cb4f=new Date();return _0x24cb4f['setDate'](_0x2bdecb[_0x2d3b0c(0x163)]()+AUTH_CONFIG[_0x2d3b0c(0x17a)]),localStorage[_0x2d3b0c(0x198)](_0x2d3b0c(0x174),_0x24cb4f[_0x2d3b0c(0x175)]()),localStorage[_0x2d3b0c(0x198)](_0x2d3b0c(0x185),_0x56658b),localStorage[_0x2d3b0c(0x198)](_0x2d3b0c(0x18b),'true'),localStorage[_0x2d3b0c(0x198)]('plugin_auto_login',_0x2d3b0c(0x196)),toastr[_0x2d3b0c(0x168)](_0x2d3b0c(0x16c)+AUTH_CONFIG[_0x2d3b0c(0x17a)]+_0x2d3b0c(0x164),'Amily2号启用'),pluginAuthStatus[_0x2d3b0c(0x170)]=!![],$(_0x2d3b0c(0x178))[_0x2d3b0c(0x187)](0x190,function(){const _0x24e4d4=_0x2d3b0c;$(_0x24e4d4(0x18f))[_0x24e4d4(0x17e)](0x190),updateUI();}),extension_settings[extensionName][_0x2d3b0c(0x18c)]=!![],saveSettings(),!![];}function _0x4d2e(_0x39dfe6,_0x776eef){const _0x3bdf3b=_0x3bdf();return _0x4d2e=function(_0x4d2e04,_0x4f4401){_0x4d2e04=_0x4d2e04-0x15f;let _0x557345=_0x3bdf3b[_0x4d2e04];return _0x557345;},_0x4d2e(_0x39dfe6,_0x776eef);}export function displayExpiryInfo(){const _0x46563c=_0x4776e2,_0x4ef84b=new Date(),_0x1ae174=Math[_0x46563c(0x16a)]((AUTH_CONFIG[_0x46563c(0x190)]-_0x4ef84b)/(0x3e8*0x3c*0x3c*0x18)),_0x34b271=localStorage['getItem']('plugin_valid_until');if(pluginAuthStatus[_0x46563c(0x195)])return'\x20授权已过期';else{let _0x2788b2='';if(_0x34b271){const _0x418f74=new Date(_0x34b271);_0x2788b2=_0x46563c(0x182)+_0x418f74[_0x46563c(0x16f)]()+_0x46563c(0x188);}return _0x46563c(0x176)+_0x1ae174+_0x46563c(0x162)+AUTH_CONFIG['expiryDate'][_0x46563c(0x16f)]()+_0x46563c(0x197)+_0x2788b2+_0x46563c(0x186);}} +import { extension_settings } from "/scripts/extensions.js"; +import { saveSettings, extensionName } from "./settings.js"; +import { updateUI } from "../ui/state.js"; + + +export const pluginAuthStatus = { + authorized: false, + expired: false, +}; + +const PASSWORD_VALIDITY_DAYS = 7; + +const AUTH_CONFIG = { + expiryDate: new Date("2025-12-31"), + validityDays: PASSWORD_VALIDITY_DAYS, +}; + + +console.log(`[Amily2号] 密码有效期为: ${PASSWORD_VALIDITY_DAYS}天`); + + +function generateDynamicPassword(date = new Date()) { + const seed = { a: 1103515245, c: 12345, m: 2147483647 }; + + function customHash(input) { + let hash = 0; + for (let i = 0; i < input.length; i++) { + hash = (hash << 5) - hash + input.charCodeAt(i); + hash |= 0; + } + return hash >>> 0; + } + + const month = date.getMonth() + 1; + const day = date.getDate(); + const year = date.getFullYear(); + const baseInput = `${month}-${day}-AMILY_${year}`; + const str1 = `SD${customHash(baseInput)}`; + const str2 = `V${customHash(str1)}`; + + function lcgRandom(params) { + return function () { + params.seed = (params.a*params.seed + params.c) % params.m; + return params.seed; + }; + } + + const combinedSeed = customHash(str2) % seed.m; + const randFunc = lcgRandom({ ...seed, seed: combinedSeed }); + const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; + const segments = []; + for (let segIdx = 0; segIdx < 3; segIdx++) { + let segment = ""; + for (let i = 0; i < 4; i++) { + const randValue = Math.abs(randFunc()); + segment += chars.charAt(randValue % chars.length); + } + segments.push(segment); + } + return segments.join("-"); +} + + +export function getPasswordForDate(date = new Date()) { + return generateDynamicPassword(date); +} + + +export function checkAuthorization() { + const now = new Date(); + pluginAuthStatus.expired = now > AUTH_CONFIG.expiryDate; + + if (pluginAuthStatus.expired) { + localStorage.removeItem("plugin_activated"); + localStorage.removeItem("plugin_auth_code"); + localStorage.removeItem("plugin_valid_until"); + console.log("[Amily2号] 检测到授权过期,已清理本地存储。"); + } + + const activated = localStorage.getItem("plugin_activated") === "true"; + const savedAuthCode = localStorage.getItem("plugin_auth_code"); + const validUntil = localStorage.getItem("plugin_valid_until"); + + let withinValidityPeriod = false; + if (validUntil) { + const validUntilDate = new Date(validUntil); + withinValidityPeriod = now <= validUntilDate; + console.log(`[Amily2号] 授权有效期检查: + 当前时间: ${now.toISOString()} + 授权有效期至: ${validUntilDate.toISOString()} + 是否在有效期内: ${withinValidityPeriod}`); + } + + let passwordMatches = false; + if (savedAuthCode) { + const today = new Date(); + for (let i = 0; i < AUTH_CONFIG.validityDays; i++) { + const checkDate = new Date(); + checkDate.setDate(today.getDate() - i); + const passwordForDay = getPasswordForDate(checkDate); + if (savedAuthCode === passwordForDay) { + passwordMatches = true; + console.log(`[Amily2号] 密码匹配: ${savedAuthCode} 对应第${i + 1}天前`); + break; + } + } + } + + pluginAuthStatus.authorized = + activated && + !pluginAuthStatus.expired && + passwordMatches && + withinValidityPeriod; + + return pluginAuthStatus.authorized; +} + + +export async function activatePluginAuthorization(authCode) { + let isValidCode = false; + const today = new Date(); + + for (let i = 0; i < AUTH_CONFIG.validityDays; i++) { + const checkDate = new Date(); + checkDate.setDate(today.getDate() - i); + const passwordForDay = getPasswordForDate(checkDate); + if (authCode === passwordForDay) { + isValidCode = true; + break; + } + } + + if (!isValidCode) { + toastr.error("授权码无效", "激活失败"); + return false; + } + + const now = new Date(); + if (now > AUTH_CONFIG.expiryDate) { + toastr.error("授权已过期", "激活失败"); + return false; + } + + const validUntil = new Date(); + validUntil.setDate(now.getDate() + AUTH_CONFIG.validityDays); + localStorage.setItem("plugin_valid_until", validUntil.toISOString()); + localStorage.setItem("plugin_auth_code", authCode); + localStorage.setItem("plugin_activated", "true"); + localStorage.setItem("plugin_auto_login", "true"); + + toastr.success( + `授权激活成功!${AUTH_CONFIG.validityDays}天内将自动登录。`, + "Amily2号启用", + ); + pluginAuthStatus.authorized = true; + + $("#auth_panel").slideUp(400, function () { + $(".plugin-features").slideDown(400); + updateUI(); + }); + + extension_settings[extensionName].enabled = true; + saveSettings(); + + return true; +} + + +export function displayExpiryInfo() { + const now = new Date(); + const daysLeft = Math.ceil( + (AUTH_CONFIG.expiryDate - now) / (1000* 60 *60* 24), + ); + const validUntil = localStorage.getItem("plugin_valid_until"); + + if (pluginAuthStatus.expired) { + return '
授权已过期
'; + } else { + let validUntilHtml = ""; + if (validUntil) { + const validUntilDate = new Date(validUntil); + validUntilHtml = `当前授权有效期至: ${validUntilDate.toLocaleDateString()}`; + } + + return ` +
+ 授权有效期: ${daysLeft}天 + 有效期至: ${AUTH_CONFIG.expiryDate.toLocaleDateString()} + ${validUntilHtml} +
+ `; + } +} diff --git a/utils/settings.js b/utils/settings.js index ea61c92..3e42a77 100644 --- a/utils/settings.js +++ b/utils/settings.js @@ -3,7 +3,7 @@ import { saveSettingsDebounced } from "/script.js"; import { pluginAuthStatus } from "./auth.js"; export const extensionName = "ST-Amily2-Chat-Optimisation"; -export const pluginVersion = "1.2.5"; +export const pluginVersion = "1.2.4"; export const defaultSettings = { diff --git a/utils/tagProcessor.js b/utils/tagProcessor.js index 05a1a9c..b7b2e16 100644 --- a/utils/tagProcessor.js +++ b/utils/tagProcessor.js @@ -1 +1,21 @@ -(function(_0x422e0a,_0x3fabbd){const _0x2d5d90=_0x4741,_0x23afee=_0x422e0a();while(!![]){try{const _0x524359=parseInt(_0x2d5d90(0x1c8))/0x1*(-parseInt(_0x2d5d90(0x1c4))/0x2)+-parseInt(_0x2d5d90(0x1c3))/0x3+-parseInt(_0x2d5d90(0x1ca))/0x4*(-parseInt(_0x2d5d90(0x1c2))/0x5)+-parseInt(_0x2d5d90(0x1c7))/0x6+parseInt(_0x2d5d90(0x1c5))/0x7*(-parseInt(_0x2d5d90(0x1be))/0x8)+-parseInt(_0x2d5d90(0x1c6))/0x9*(-parseInt(_0x2d5d90(0x1bf))/0xa)+parseInt(_0x2d5d90(0x1c9))/0xb;if(_0x524359===_0x3fabbd)break;else _0x23afee['push'](_0x23afee['shift']());}catch(_0x53bf82){_0x23afee['push'](_0x23afee['shift']());}}}(_0x574a,0x81e0c));function extractContentByTag(_0x3e4dbd,_0x387b0e){const _0x379c0d=_0x4741,_0x40a687=new RegExp('<'+_0x387b0e+'[^>]*>([\x5cs\x5cS]*?)<\x5c/'+_0x387b0e+'>'),_0x19d3e1=_0x3e4dbd[_0x379c0d(0x1c1)](_0x40a687);return _0x19d3e1?_0x19d3e1[0x1]:null;}function _0x4741(_0x160eaf,_0x223d84){const _0x574a8e=_0x574a();return _0x4741=function(_0x4741c8,_0x168897){_0x4741c8=_0x4741c8-0x1bd;let _0x431c3a=_0x574a8e[_0x4741c8];return _0x431c3a;},_0x4741(_0x160eaf,_0x223d84);}function extractFullTagBlock(_0x40277f,_0x38900f){const _0x240389=_0x4741,_0x212931=new RegExp('(<'+_0x38900f+'[^>]*>[\x5cs\x5cS]*?<\x5c/'+_0x38900f+'>)'),_0x2a4a67=_0x40277f[_0x240389(0x1c1)](_0x212931);return _0x2a4a67?_0x2a4a67[0x0]:null;}function replaceContentByTag(_0xd5ed6c,_0x3cbd88,_0x289306){const _0x56c37f=_0x4741,_0x22357d=new RegExp('(<'+_0x3cbd88+_0x56c37f(0x1cb)+_0x3cbd88+'>)'),_0xca7d85=_0xd5ed6c['match'](_0x22357d);if(_0xca7d85){const _0x4df9e1=_0xd5ed6c[_0x56c37f(0x1c0)](0x0,_0xca7d85['index']),_0x1c73f1=_0xd5ed6c[_0x56c37f(0x1c0)](_0xca7d85['index']+_0xca7d85[0x0][_0x56c37f(0x1bd)]);return _0x4df9e1+_0xca7d85[0x1]+_0x289306+_0xca7d85[0x3]+_0x1c73f1;}return _0xd5ed6c;}function _0x574a(){const _0x56ae36=['match','590355KzLtRH','535983ZNapyX','2doeGJM','469Jqbdvc','15813NXAxpH','2133750klwmNR','1010564oNanUZ','23121241bDTIQx','12snbror','[^>]*>)([\x5cs\x5cS]*?)(<\x5c/','length','64592JtlTsS','920tSbgLd','substring'];_0x574a=function(){return _0x56ae36;};return _0x574a();}export{extractContentByTag,replaceContentByTag,extractFullTagBlock}; +function extractContentByTag(xmlString, tagName) { + const regex = new RegExp(`<${tagName}[^>]*>([\\s\\S]*?)<\\/${tagName}>`); + const match = xmlString.match(regex); + return match ? match[1] : null; +} + +function extractFullTagBlock(xmlString, tagName) { + const regex = new RegExp(`(<${tagName}[^>]*>[\\s\\S]*?<\\/${tagName}>)`); + const match = xmlString.match(regex); + return match ? match[0] : null; +} + +function replaceContentByTag(xmlString, tagName, newContent) { + const regex = new RegExp(`(<${tagName}[^>]*>)[\\s\\S]*?(<\\/${tagName}>)`); + if (regex.test(xmlString)) { + return xmlString.replace(regex, `$1${newContent}$2`); + } + return xmlString; +} + +export { extractContentByTag, replaceContentByTag, extractFullTagBlock };