@@ -7,105 +7,85 @@ import { getAnalytics } from "firebase/analytics";
77import { getPerformance } from "firebase/performance" ;
88
99const initializeFirebase = ( ) => {
10- const firebaseConfig = {
11- apiKey : "AIzaSyANVvapu0ihi1cM8ZzuXTkwjx9lM_J1RyQ" ,
12- authDomain : "rw-api-code-d0779.firebaseapp.com" ,
13- projectId : "rw-api-code-d0779" ,
14- storageBucket : "rw-api-code-d0779.appspot.com" ,
15- messagingSenderId : "363611843335" ,
16- appId : "1:363611843335:web:f15aef7ab427f52b4033a2" ,
17- measurementId : "G-XJH5TKP5VL" ,
18- } ;
19-
20- // Initialize Firebase
21- const app = initializeApp ( firebaseConfig ) ;
22- const analytics = getAnalytics ( app ) ;
23- const perf = getPerformance ( app ) ;
24-
25- return "Firebase initialized successfully" ;
10+ const firebaseConfig = {
11+ apiKey : "AIzaSyANVvapu0ihi1cM8ZzuXTkwjx9lM_J1RyQ" ,
12+ authDomain : "rw-api-code-d0779.firebaseapp.com" ,
13+ projectId : "rw-api-code-d0779" ,
14+ storageBucket : "rw-api-code-d0779.appspot.com" ,
15+ messagingSenderId : "363611843335" ,
16+ appId : "1:363611843335:web:f15aef7ab427f52b4033a2" ,
17+ measurementId : "G-XJH5TKP5VL" ,
18+ } ;
19+
20+ // Initialize Firebase
21+ const app = initializeApp ( firebaseConfig ) ;
22+ const analytics = getAnalytics ( app ) ;
23+ const perf = getPerformance ( app ) ;
24+
25+ return "Firebase initialized successfully" ;
2626} ;
2727
2828( async function ( ) {
29- try {
30- const result = await initializeFirebase ( ) ;
31- console . log ( result ) ;
32- } catch ( error ) {
33- console . error ( error ) ;
34- }
29+ try {
30+ const result = await initializeFirebase ( ) ;
31+ console . log ( result ) ;
32+ } catch ( error ) {
33+ console . error ( error ) ;
34+ }
3535} ) ( ) ;
3636
3737function wait ( timeout ) {
38- return new Promise ( ( resolve ) => setTimeout ( resolve , timeout ) ) ;
38+ return new Promise ( ( resolve ) => setTimeout ( resolve , timeout ) ) ;
3939}
4040
4141async function requestClipboardPermission ( ) {
42- try {
43- await navigator . permissions . query ( { name : "clipboard-write" } ) ;
44- } catch ( error ) {
45- console . error ( error ) ;
46- }
42+ try {
43+ await navigator . permissions . query ( { name : "clipboard-write" } ) ;
44+ } catch ( error ) {
45+ console . error ( error ) ;
46+ }
4747}
4848
4949async function init ( ) {
50- try {
51- await wait ( 1000 ) ;
52-
53- // console.log("timeout");
54-
55- const copyBtnList = document . getElementsByClassName ( "copy" ) ;
56- // console.log(copyBtnList);
57- // console.log(copyBtnList.length);
58-
59- for ( let i = 0 ; i < copyBtnList . length ; i ++ ) {
60- const btn = copyBtnList [ i ] ;
61- btn . addEventListener ( "touchend" , async ( ) => {
62- // 请求剪贴板权限
63- await requestClipboardPermission ( ) ;
64- const parentDiv = btn . parentNode ;
65- const codeElem = parentDiv . querySelector ( "code" ) ;
66- const spans = [ ...codeElem . querySelectorAll ( "span" ) ] ;
67- const textToCopy = [
68- ...new Set ( spans . map ( ( span ) => span . textContent ) ) ,
69- ] . join ( "" ) ;
70- // console.log(textToCopy);
71-
72- try {
73- await navigator . clipboard . writeText ( textToCopy ) ;
74- // console.log("Text copied to clipboard");
75- } catch ( error ) {
76- const textarea = document . createElement ( "textarea" ) ;
77- textarea . value = textToCopy ;
78- document . body . appendChild ( textarea ) ;
79- textarea . select ( ) ;
80- document . execCommand ( "copy" ) ;
81- document . body . removeChild ( textarea ) ;
82- // console.log("Text copied to clipboard");
83- }
84- } ) ;
85- }
86- } catch ( error ) {
87- console . error ( error ) ;
88- }
50+ try {
51+ await wait ( 1000 ) ;
52+
53+ // console.log("timeout");
54+
55+ const copyBtnList = document . getElementsByClassName ( "copy" ) ;
56+ // console.log(copyBtnList);
57+ // console.log(copyBtnList.length);
58+
59+ for ( let i = 0 ; i < copyBtnList . length ; i ++ ) {
60+ const btn = copyBtnList [ i ] ;
61+ btn . addEventListener ( "touchend" , async ( ) => {
62+ // 请求剪贴板权限
63+ await requestClipboardPermission ( ) ;
64+ const parentDiv = btn . parentNode ;
65+ const codeElem = parentDiv . querySelector ( "code" ) ;
66+ const spans = [ ...codeElem . querySelectorAll ( "span" ) ] ;
67+ const textToCopy = [
68+ ...new Set ( spans . map ( ( span ) => span . textContent ) ) ,
69+ ] . join ( "" ) ;
70+ // console.log(textToCopy);
71+
72+ try {
73+ await navigator . clipboard . writeText ( textToCopy ) ;
74+ // console.log("Text copied to clipboard");
75+ } catch ( error ) {
76+ const textarea = document . createElement ( "textarea" ) ;
77+ textarea . value = textToCopy ;
78+ document . body . appendChild ( textarea ) ;
79+ textarea . select ( ) ;
80+ document . execCommand ( "copy" ) ;
81+ document . body . removeChild ( textarea ) ;
82+ // console.log("Text copied to clipboard");
83+ }
84+ } ) ;
85+ }
86+ } catch ( error ) {
87+ console . error ( error ) ;
88+ }
8989}
90-
91- setTimeout ( ( ) => {
92- const notFoundDiv = document . querySelector ( ".NotFound" ) ;
93- // 添加404图片
94- const img = document . createElement ( "img" ) ;
95- img . src =
96- "https://img.quankexia.com/kelongwo/wp-content/uploads/2021/07/2021072708045950.png" ;
97- img . alt = "404 Error" ;
98- notFoundDiv . insertBefore ( img , notFoundDiv . firstChild ) ;
99-
100- // 将PAGE NOT FOUND改为无法找到该页面
101- notFoundDiv . querySelector ( ".title" ) . textContent = "无法找到该页面" ;
102-
103- // 将But if you don't change your direction, and if you keep looking, you may end up where you are heading.改为无法找到该页面
104- notFoundDiv . querySelector ( ".quote" ) . textContent = "无法找到该页面" ;
105-
106- // 将 Take me home 按钮文字替换为返回首页
107- notFoundDiv . querySelector ( ".link" ) . textContent = "返回首页" ;
108- } , 200 ) ;
109-
11090init ( ) ;
11191export default DefaultTheme ;
0 commit comments