77 < meta http-equiv ="X-UA-Compatible " content ="ie=edge " />
88 < title > New Tab</ title >
99 < link rel ="icon " type ="image/png " sizes ="48x48 " href ="icon48.png ">
10- <!-- < script type="text/javascript" src="./newtabnotes.js"></script> -- >
10+ < script type ="text/javascript " src ="./newtabnotes.js "> </ script >
1111 <!-- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Bitter:400,700&display=swap" /> -->
1212</ head >
1313
4141 </ main >
4242</ body >
4343
44- < script >
45- var timeoutId ;
46- const notes = document . getElementById ( "notes" ) ;
47- document . addEventListener ( "keyup" , logKey ) ;
48-
49- const browser_type = getBrowser ( ) ;
50- if ( browser_type === "Chrome" ) {
51- var browser_obj = chrome ;
52- } else {
53- var browser_obj = browser ;
54- }
55-
56- browser_obj . tabs . onActivated . addListener ( tabOpen ) ;
57- browser_obj . windows . onFocusChanged . addListener ( tabOpen ) ;
58-
59- function logKey ( e ) {
60- clearTimeout ( timeoutId ) ;
61- timeoutId = setTimeout ( function ( ) {
62- saveToDB ( ) ;
63- } , 10 ) ;
64- }
65-
66- function getBrowser ( ) {
67- if ( typeof chrome !== "undefined" ) {
68- if ( typeof browser !== "undefined" ) {
69- return "Firefox" ;
70- } else {
71- return "Chrome" ;
72- }
73- } else {
74- return "Edge" ;
75- }
76- }
77-
78- function saveToDB ( ) {
79- data = {
80- tab_note : document . querySelector ( "#notes" ) . value
81- } ;
82- if ( browser_type === "Chrome" ) {
83- chrome . storage . sync . set ( data , function ( ) { } ) ;
84- } else {
85- browser_obj . storage . sync . set ( data ) ;
86- }
87- }
88-
89- function tabOpen ( tab ) {
90- if ( browser_type === "Chrome" ) {
91- chrome . storage . sync . get ( [ "tab_note" ] , function ( result ) {
92- if ( typeof result . tab_note !== "undefined" ) {
93- document . querySelector ( "#notes" ) . value = result . tab_note ;
94- }
95- } ) ;
96- } else {
97- browser_obj . storage . sync . get ( [ "tab_note" ] ) . then ( result => {
98- if ( typeof result . tab_note !== "undefined" ) {
99- document . querySelector ( "#notes" ) . value = result . tab_note ;
100- }
101- } ) ;
102- }
103- }
104-
105- window . addEventListener ( "load" , ( ) => {
106- tabOpen ( ) ;
107- } ) ;
108-
109- </ script >
110-
11144</ html >
0 commit comments