haxwitcher commited on
Commit
5d4bd61
·
verified ·
1 Parent(s): c1c101e

Create widget.js

Browse files
Files changed (1) hide show
  1. widget.js +44 -0
widget.js ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ;(function(){
2
+ const BASE = 'https://huggingface.co/spaces/<tvoj-username>/sales-widget';
3
+ const CONFIG_URL = BASE + '/raw/main/static/config.json';
4
+ const D = 5000, I = 8000;
5
+
6
+ function el(tag, cls){ const e = document.createElement(tag); e.className = cls; return e; }
7
+
8
+ function create(item){
9
+ const w = el('div','notification');
10
+ w.innerHTML = `
11
+ <img class="avatar" src="${item.avatar}" alt="${item.name}">
12
+ <div class="text">
13
+ <b>${item.name}</b> (${item.channel}: ${item.phone}) iz ${item.country}<br>
14
+ naručila je pretplatu za <b>${item.product}</b><br>
15
+ <small>${item.timeAgo}</small>
16
+ </div>`;
17
+ return w;
18
+ }
19
+
20
+ async function start(){
21
+ const res = await fetch(CONFIG_URL);
22
+ const data = await res.json();
23
+ const container = el('div','');
24
+ container.id = 'sales-notification-container';
25
+ document.body.appendChild(container);
26
+
27
+ let i = 0;
28
+ setInterval(() => {
29
+ const note = create(data[i % data.length]);
30
+ container.appendChild(note);
31
+ requestAnimationFrame(()=>note.classList.add('show'));
32
+ setTimeout(()=>{
33
+ note.classList.remove('show');
34
+ setTimeout(()=>note.remove(), 500);
35
+ }, D);
36
+ i++;
37
+ }, I);
38
+ }
39
+
40
+ // ubaci CSS i pokreni
41
+ const l = el('link'); l.rel='stylesheet'; l.href= BASE + '/raw/main/static/widget.css';
42
+ document.head.appendChild(l);
43
+ window.addEventListener('DOMContentLoaded', start);
44
+ })();