1+ document . addEventListener ( "DOMContentLoaded" , function ( ) {
2+ // Check if widget was closed before
3+ const closedUntil = localStorage . getItem ( "feedbackWidgetClosedUntil" ) ;
4+ if ( closedUntil && new Date ( ) . getTime ( ) < parseInt ( closedUntil , 10 ) ) {
5+ return ; // Don't show widget if closed and timer not expired
6+ }
7+
8+ const container = document . createElement ( "div" ) ;
9+ container . style . position = "fixed" ;
10+ container . style . bottom = "20px" ;
11+ container . style . right = "20px" ;
12+ container . style . background = "#fff" ;
13+ container . style . border = "1px solid #ddd" ;
14+ container . style . padding = "10px 15px" ;
15+ container . style . borderRadius = "8px" ;
16+ container . style . boxShadow = "0 2px 6px rgba(0,0,0,0.15)" ;
17+ container . style . zIndex = 9999 ;
18+ container . style . fontFamily = '"Poppins", "Roboto", Arial, Helvetica, sans-serif' ;
19+ container . style . textAlign = "center" ;
20+ container . style . width = "250px" ;
21+
22+ // Close button
23+ const closeBtn = document . createElement ( "button" ) ;
24+ closeBtn . innerText = "×" ;
25+ closeBtn . style . position = "absolute" ;
26+ closeBtn . style . top = "-2px" ; // push close button slightly above the container edge
27+ closeBtn . style . right = "-2px" ; // push close button slightly outside right edge
28+ closeBtn . style . border = "none" ;
29+ closeBtn . style . background = "transparent" ;
30+ closeBtn . style . fontSize = "24px" ;
31+ closeBtn . style . cursor = "pointer" ;
32+ closeBtn . style . color = "#999" ;
33+ closeBtn . style . fontWeight = "bold" ;
34+ closeBtn . style . lineHeight = "1" ;
35+ closeBtn . style . padding = "0" ;
36+ closeBtn . style . width = "30px" ;
37+ closeBtn . style . height = "30px" ;
38+
39+ closeBtn . addEventListener ( "click" , ( ) => {
40+ container . style . display = "none" ;
41+ // Hide for 4 hours
42+ const fourHoursFromNow = new Date ( ) . getTime ( ) + 4 * 60 * 60 * 1000 ;
43+ localStorage . setItem ( "feedbackWidgetClosedUntil" , fourHoursFromNow . toString ( ) ) ;
44+ } ) ;
45+
46+ container . appendChild ( closeBtn ) ;
47+
48+ const title = document . createElement ( "div" ) ;
49+ title . innerText = "Do you like Percona docs?" ;
50+ title . style . marginBottom = "8px" ;
51+ title . style . fontSize = "14px" ;
52+ title . style . fontWeight = "bold" ;
53+ title . style . color = "#0E5FB5" ;
54+ title . style . fontFamily = '"Poppins", "Roboto", Arial, Helvetica, sans-serif' ;
55+ container . appendChild ( title ) ;
56+
57+ const stars = document . createElement ( "div" ) ;
58+ stars . style . position = "relative" ;
59+
60+ for ( let i = 1 ; i <= 5 ; i ++ ) {
61+ const star = document . createElement ( "span" ) ;
62+ star . innerHTML = "☆" ;
63+ star . style . fontSize = "24px" ;
64+ star . style . cursor = "pointer" ;
65+ star . style . margin = "0 3px" ;
66+ star . style . color = "#000" ;
67+
68+ star . addEventListener ( "mouseover" , ( ) => {
69+ [ ...stars . children ] . forEach ( ( s , index ) => {
70+ s . innerHTML = index < i ? "★" : "☆" ;
71+ s . style . color = index < i ? "#0E5FB5" : "#000" ;
72+ } ) ;
73+ } ) ;
74+
75+ star . addEventListener ( "mouseleave" , ( ) => {
76+ [ ...stars . children ] . forEach ( ( s ) => {
77+ s . innerHTML = "☆" ;
78+ s . style . color = "#000" ;
79+ } ) ;
80+ } ) ;
81+
82+ star . addEventListener ( "click" , ( ) => {
83+ const formURL = "https://docs.google.com/forms/d/e/1FAIpQLSfhscELpzoXB4uyh9pXNmXSeqKc10IH_DxmAoaVGID85sO0Aw/viewform" ;
84+ const ratingURL = `${ formURL } ?entry.303027158=${ i } ` ;
85+ window . open ( ratingURL , "_blank" ) ;
86+ } ) ;
87+
88+ stars . appendChild ( star ) ;
89+ }
90+
91+ container . appendChild ( stars ) ;
92+ document . body . appendChild ( container ) ;
93+ } ) ;
94+
0 commit comments