11import * as settings from 'src/utils/settings/index.js' ;
22import wrap from 'src/utils/2.pokemon.js' ;
3- import cleanData from 'src/utils/cleanData.js' ;
43import { noop , scriptVersion } from 'src/utils/1.variables.js' ;
54import style from 'src/utils/style.js' ;
65import { toast } from 'src/utils/2.toasts.js' ;
76import css from 'src/utils/css.js' ;
7+ import Translation from 'src/structures/constants/translation' ;
8+ import eventManager from 'src/utils/eventManager' ;
89import * as changelog from './changelog.js' ;
910
1011wrap ( function patchNotes ( ) {
1112 const setting = settings . register ( {
12- name : 'Disable Patch Notes' ,
13+ name : Translation . Setting ( 'patches' ) ,
1314 key : 'underscript.disable.patches' ,
1415 } ) ;
16+ const installed = settings . register ( {
17+ key : 'underscript.update.installed' ,
18+ type : 'text' ,
19+ hidden : true ,
20+ converter ( ) {
21+ const key = `underscript.update.${ scriptVersion } ` ;
22+ if ( localStorage . getItem ( key ) ) {
23+ localStorage . removeItem ( key ) ;
24+ return scriptVersion ;
25+ }
26+ return undefined ;
27+ } ,
28+ } ) ;
29+
30+ if (
31+ setting . value ( ) ||
32+ ! scriptVersion . includes ( '.' ) ||
33+ installed . value ( ) === scriptVersion
34+ ) return ;
1535
16- cleanData ( 'underscript.update.' , scriptVersion , 'last' , 'checking' , 'debug' ) ;
1736 style . add ( css `
1837 # AlertToast div .uschangelog span : nth-of-type (2 ) {
1938 max-height : 300px ;
@@ -25,19 +44,18 @@ wrap(function patchNotes() {
2544 display : none;
2645 }
2746 ` ) ;
28- if ( setting . value ( ) || ! scriptVersion . includes ( '.' ) ) return ;
29- const versionKey = `underscript.update.${ scriptVersion } ` ;
30- if ( localStorage . getItem ( versionKey ) ) return ;
3147
3248 changelog . get ( scriptVersion , true )
33- . then ( notify )
49+ . then ( ( text ) => eventManager . on ( 'underscript:ready' , ( ) => notify ( text ) ) )
3450 . catch ( noop ) ;
3551
52+ const title = Translation . Toast ( 'patch.notes' ) ;
53+
3654 function notify ( text ) {
37- localStorage . setItem ( versionKey , true ) ;
55+ installed . set ( scriptVersion ) ;
3856 toast ( {
3957 text,
40- title : '[UnderScript] Patch Notes' ,
58+ title : title . translate ( ) ,
4159 footer : `v${ scriptVersion } ` ,
4260 className : 'uschangelog' ,
4361 } ) ;
0 commit comments