1 2(function () { 3 async function fIsDenyNotifications() { 4 // 注åçå¬ç¨åº 5 navigator.serviceWorker.register('/v3/webapp/static/js/firebase-messaging-sw.js'); 6 7 const status = await navigator.permissions.query({name: 'notifications'}); 8 const deny = status.state === 'denied'; 9 if (deny) console.warn('You deny any notifications from us. Sorry to hear that.'); 10 return deny; 11 } 12 function fGetSW() { 13 return navigator.serviceWorker.getRegistration('/v3/webapp/static/js/firebase-messaging-sw.js'); 14 } 15 16 const FIREBASE_ITEM_KEY = 'firebase-instance-id-token-v2', 17 FIREBASE_ITEM_LAST_KEY = 'firebase-instance-id-token-v2-last', 18 FIREBASE_TOKE_ADD_URL = 'https://www.sellersprite.com', 19 HOST = window.location.host, 20 FIREBASE_SERVER = 'https://firebase.sellersprite.com', 21 FIREBASE_PVK = 'BBYhvTqYbQ3nKe0R-0sH30LQcI00pVxwqbSkP8PcpLkTsAKxRk9l-Ngx9okP3u7dLeAsL7pRtDHfs3SfsT_QvMs'; 22 window.FIREBASE_TOPICS = []; 23 window.FIREBASE_TOPIC_MEMBER_LEVEL = null; 24 25 window.addEventListener('load', () => fIsDenyNotifications()); 26 async function fDisplayMessages(payload) { 27 console.log('X: Message received. ', payload); 28 // ä¿è¯æ¶æ¯åªå±ç¤ºä¸æ¬¡ 29 const id = payload['data'] && payload['data']['id'] || ('fb-' + new Date().getTime()); 30 const sent = payload['data'] && payload['data']['sent_timestamp'] || ''; 31 // ...è¿ééè¦è°ç¨å端çä»£ç æç¸åºçä¿¡æ¯æå°åºæ¥todo æ¬æµ®å¼¹çªæç¤º 32 try {window.createBrowsermessage(payload);}catch (e) {}; 33 34 // Customize notification here 35 const title = (payload['notification'] && payload['notification']['title'] 36 || payload['data'] && payload['data']['title'] || 'æ¨ææ°çæ¶æ¯'); 37 let link = payload['data'] && payload['data']['callback_link'] || 'https://www.sellersprite.com/?source=firebase_front'; 38 const options = { 39 body: payload['notification'] && payload['notification']['body'] || '(æ¥èªåå®¶ç²¾çµ) ...', 40 icon: 'https://o.sellersprite.com/assets/images/logo-english%402x.png', 41 data: {link: link} 42 }; 43 44 const sw = await fGetSW(); 45 if (localStorage.getItem(id)) return false; 46 let millis = Math.ceil(Math.random() * 1000); 47 let v = new Date().getTime() + '-' + millis; 48 setTimeout(function () { 49 if (localStorage.getItem(id)) return false; 50 localStorage.setItem(id, v); 51 if (localStorage.getItem(id) !== v) return false; 52 sw.showNotification(title, options); 53 }, millis); 54 } 55 56 function sendTokenToServer(token) { 57 // 仿ªåå§åçç¨æ· 58 if (!window.FIREBASE_TOPICS || window.FIREBASE_TOPICS.length < 1) return false; 59 if (!isTokenSentToServer(token)) { 60 let data = {token: token, topics: window.FIREBASE_TOPICS.join(',')} 61 62 sendPushToken(token) 63 //åå端å卿°è·åçtoken 64 fetch(FIREBASE_SERVER + "/firebase/subscribe", { 65 method: "post", 66 mode: 'cors', 67 headers: {'Content-Type': 'application/json'}, 68 body: JSON.stringify(data) 69 }).then(response => response.json()).then(res => { 70 if (res.code === 'ok') { 71 setTokenSentToServer(token) 72 } 73 }); 74 75 // åæ¶ä¹åç订é ä¸»ä½ 76 if (window.FIREBASE_TOPIC_MEMBER_LEVEL && window.FIREBASE_TOPIC_MEMBER_LEVEL.length > 1 77 && window.FIREBASE_TOPIC_MEMBER_LEVEL !== fGetLastMemberLevel() 78 && fGetLastMemberLevel().length > 1) { 79 fetch(FIREBASE_SERVER + "/firebase/unsubscribe", { 80 method: "post", 81 mode: 'cors', 82 headers: {'Content-Type': 'application/json'}, 83 body: JSON.stringify({token: token, topics: fGetLastMemberLevel()}) 84 }).then(response => response.json()).then(res => { 85 res.code === 'ok' && localStorage.setItem(FIREBASE_ITEM_LAST_KEY, localStorage.getItem(FIREBASE_ITEM_KEY)); 86 }) 87 } 88 } else { 89 console.log("Token already sent to server so won't send it again unless it changes"); 90 } 91 } 92 93 //åå端å卿°è·åçtoken 94 function sendPushToken(token){ 95 let data = {token: token, time: new Date().getTime()} 96 fetch(FIREBASE_TOKE_ADD_URL + "/v2/firebase/add", { 97 method: "post", 98 headers: {'Content-Type': 'application/json'}, 99 body: JSON.stringify(data) 100 }).then(response => response.json()).then(res => { 101 console.log("æ¨étokenæå: " + res) 102 }) 103 } 104 105 function setTokenSentToServer(token) { 106 let val = { 107 tk: token, 108 topics: window.FIREBASE_TOPICS, 109 ml: window.FIREBASE_TOPIC_MEMBER_LEVEL || '', 110 time: new Date().getTime() 111 }, strings = JSON.stringify(val); 112 localStorage.setItem(FIREBASE_ITEM_KEY, strings); 113 let b = JSON.parse(localStorage.getItem(FIREBASE_ITEM_LAST_KEY) || '{}'); 114 if (!b['time'] || !b['ml']) 115 localStorage.setItem(FIREBASE_ITEM_LAST_KEY, strings); 116 } 117 118 function fGetLastMemberLevel() { 119 let t = JSON.parse(localStorage.getItem(FIREBASE_ITEM_LAST_KEY) || '{}'); 120 return t && t['ml'] || ''; 121 } 122 123 function isTokenSentToServer(token) { 124 // tokenæå¤§æææ¶é´=24å°æ¶ï¼å¦å强å¶å·æ° 125 let t = JSON.parse(localStorage.getItem(FIREBASE_ITEM_KEY) || '{}'), 126 tl = JSON.parse(localStorage.getItem(FIREBASE_ITEM_LAST_KEY) || '{}'); 127 return t && t['tk'] && t['ml'] && t['tk'] === token && t['t
127ime'] 128 && t['time'] > new Date().getTime() - 24 * 3600 * 1000; 129 // if (t && t['time'] && t['time'] > new Date().getTime() - 24 * 3600 * 1000) return true; 130 // return t && t['tk'] && t['ml'] && t['tk'] === token && tl && tl['ml'] && t['ml'] === tl['ml']; 131 } 132 133 function fInitInstance() { 134 const client = JSON.parse(sessionStorage.getItem('userInfo') || '{}'); 135 if (!client || !client['memberLevel'] || 'string' != typeof client['memberLevel'] 136 || !client['firebase'] || 'string' != typeof client['firebase'] || client['firebase'].length < 5) { 137 console.log(`FIREBASE messaging not found signin user, ${client}`); 138 return; 139 } 140 // è®¾ç½®ç¨æ·ç»å½ä¿¡æ¯ 141 client['firebase'].split(',').forEach(o => window.FIREBASE_TOPICS.push(o)); 142 let _ml = window.FIREBASE_TOPICS[window.FIREBASE_TOPICS.length - 1]; 143 _ml && _ml.indexOf('ML-') && (window.FIREBASE_TOPIC_MEMBER_LEVEL = _ml); 144 145 const firebaseConfig = { 146 apiKey: "AIzaSyAtxVtJ_lZ0OgiDTfzfZYqwR8VJyneJfds", 147 authDomain: "seller-sprite.firebaseapp.com", 148 databaseURL: "https://seller-sprite.firebaseio.com", 149 projectId: "seller-sprite", 150 storageBucket: "seller-sprite.appspot.com", 151 messagingSenderId: "284356059972", 152 appId: "1:284356059972:web:b4c0649dfc39ef33036d11", 153 measurementId: "G-CN0F80S6GL" 154 }; 155 // Initialize Firebase 156 firebase.initializeApp(firebaseConfig); 157 firebase.analytics(); 158 159 const messaging = firebase.messaging(); 160 messaging.usePublicVapidKey(FIREBASE_PVK); 161 162 messaging.onTokenRefresh(() => { 163 messaging.getToken().then((refreshedToken) => { 164 sendTokenToServer(refreshedToken); 165 }).catch((err) => { 166 console.log('Unable to retrieve refreshed token ', err); 167 }); 168 }); 169 170 messaging.getToken().then((currentToken) => { 171 if (currentToken) { 172 sendTokenToServer(currentToken); 173 } else { 174 messaging.requestPermission().then(() => { 175 return messaging.getToken(); 176 }).then(token => { 177 sendTokenToServer(token) 178 }).catch(err => console.log('An error occurred while retrieving token. ', err)) 179 } 180 181 messaging.onMessage((payload) => { 182 fDisplayMessages(payload); 183 }); 184 }).catch((err) => { 185 console.log('An error occurred while retrieving token. ', err); 186 }); 187 } 188 189 // çå¾ ç¨åºåå§å(3ç§åæ§è¡) 190 setTimeout(fInitInstance, 3000); 191})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.