@snippyly/plugin 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants.js +180 -0
- package/firebase.js +5 -2
- package/package.json +2 -2
- package/plugin-ui.js +238 -292
- package/snippyly.js +67 -19
- package/utils.js +17 -0
package/constants.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
export const REVIEW_MODE = 'review-mode';
|
|
2
|
+
export const REVIEW_DOC_ID = 'review-doc-id';
|
|
3
|
+
|
|
4
|
+
export const TAGS = {
|
|
5
|
+
SNIPPYLY_PLUGIN: 'snippyly-plugin',
|
|
6
|
+
SNIPPYLY_ROOT: 'snippyly-root',
|
|
7
|
+
SNIPPYLY_PRESENCE: 'snippyly-presence',
|
|
8
|
+
SNIPPYLY_CURSOR: 'snippyly-cursor',
|
|
9
|
+
SNIPPYLY_COMMENT_TOOL: 'snippyly-comment-tool',
|
|
10
|
+
SNIPPYLY_COMMENTS: 'snippyly-comments',
|
|
11
|
+
SNIPPYLY_TEXT_HIGHLIGHT: 'snippyly-text-highlight',
|
|
12
|
+
SNIPPYLY_COMMENTS_SIDEBAR: 'snippyly-comments-sidebar',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const ICONS = {
|
|
16
|
+
GOOGLE: `
|
|
17
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
|
18
|
+
<g transform="matrix(1, 0, 0, 1, 27.009001, -39.238998)">
|
|
19
|
+
<path fill="#4285F4" d="M -3.264 51.509 C -3.264 50.719 -3.334 49.969 -3.454 49.239 L -14.754 49.239 L -14.754 53.749 L -8.284 53.749 C -8.574 55.229 -9.424 56.479 -10.684 57.329 L -10.684 60.329 L -6.824 60.329 C -4.564 58.239 -3.264 55.159 -3.264 51.509 Z"/>
|
|
20
|
+
<path fill="#34A853" d="M -14.754 63.239 C -11.514 63.239 -8.804 62.159 -6.824 60.329 L -10.684 57.329 C -11.764 58.049 -13.134 58.489 -14.754 58.489 C -17.884 58.489 -20.534 56.379 -21.484 53.529 L -25.464 53.529 L -25.464 56.619 C -23.494 60.539 -19.444 63.239 -14.754 63.239 Z"/>
|
|
21
|
+
<path fill="#FBBC05" d="M -21.484 53.529 C -21.734 52.809 -21.864 52.039 -21.864 51.239 C -21.864 50.439 -21.724 49.669 -21.484 48.949 L -21.484 45.859 L -25.464 45.859 C -26.284 47.479 -26.754 49.299 -26.754 51.239 C -26.754 53.179 -26.284 54.999 -25.464 56.619 L -21.484 53.529 Z"/>
|
|
22
|
+
<path fill="#EA4335" d="M -14.754 43.989 C -12.984 43.989 -11.404 44.599 -10.154 45.789 L -6.734 42.369 C -8.804 40.429 -11.514 39.239 -14.754 39.239 C -19.444 39.239 -23.494 41.939 -25.464 45.859 L -21.484 48.949 C -20.534 46.099 -17.884 43.989 -14.754 43.989 Z"/>
|
|
23
|
+
</g>
|
|
24
|
+
</svg>
|
|
25
|
+
`,
|
|
26
|
+
PIN: `
|
|
27
|
+
<div class="snippyly-feature-block comment-btn">
|
|
28
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-geo-alt-fill" viewBox="0 0 16 16">
|
|
29
|
+
<path d="M8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10zm0-7a3 3 0 1 1 0-6 3 3 0 0 1 0 6z"></path>
|
|
30
|
+
</svg>
|
|
31
|
+
</div>
|
|
32
|
+
`,
|
|
33
|
+
SHARE: `
|
|
34
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
|
|
35
|
+
class="bi bi-share-fill" viewBox="0 0 16 16">
|
|
36
|
+
<path
|
|
37
|
+
d="M11 2.5a2.5 2.5 0 1 1 .603 1.628l-6.718 3.12a2.499 2.499 0 0 1 0 1.504l6.718 3.12a2.5 2.5 0 1 1-.488.876l-6.718-3.12a2.5 2.5 0 1 1 0-3.256l6.718-3.12A2.5 2.5 0 0 1 11 2.5z" />
|
|
38
|
+
</svg>
|
|
39
|
+
`,
|
|
40
|
+
SIGNOUT: `
|
|
41
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-box-arrow-right" viewBox="0 0 16 16">
|
|
42
|
+
<path fill-rule="evenodd" d="M10 12.5a.5.5 0 0 1-.5.5h-8a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h8a.5.5 0 0 1 .5.5v2a.5.5 0 0 0 1 0v-2A1.5 1.5 0 0 0 9.5 2h-8A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h8a1.5 1.5 0 0 0 1.5-1.5v-2a.5.5 0 0 0-1 0v2z"/>
|
|
43
|
+
<path fill-rule="evenodd" d="M15.854 8.354a.5.5 0 0 0 0-.708l-3-3a.5.5 0 0 0-.708.708L14.293 7.5H5.5a.5.5 0 0 0 0 1h8.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3z"/>
|
|
44
|
+
</svg>
|
|
45
|
+
`,
|
|
46
|
+
CLOSE: `
|
|
47
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-lg" viewBox="0 0 16 16">
|
|
48
|
+
<path d="M2.146 2.854a.5.5 0 1 1 .708-.708L8 7.293l5.146-5.147a.5.5 0 0 1 .708.708L8.707 8l5.147 5.146a.5.5 0 0 1-.708.708L8 8.707l-5.146 5.147a.5.5 0 0 1-.708-.708L7.293 8 2.146 2.854Z"/>
|
|
49
|
+
</svg>
|
|
50
|
+
`,
|
|
51
|
+
TRASH: `
|
|
52
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash-fill" viewBox="0 0 16 16">
|
|
53
|
+
<path d="M2.5 1a1 1 0 0 0-1 1v1a1 1 0 0 0 1 1H3v9a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V4h.5a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H10a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1H2.5zm3 4a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5zM8 5a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7A.5.5 0 0 1 8 5zm3 .5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 1 0z"/>
|
|
54
|
+
</svg>
|
|
55
|
+
`,
|
|
56
|
+
SNIPPYLY: `
|
|
57
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="150" height="150" viewBox="0 0 165 150" fill="none">
|
|
58
|
+
<path d="M64.1815 1.85957C59.9002 0.028852 55.1655 -0.464714 50.5987 0.443652C46.0319 1.35202 41.8464 3.61987 38.5915 6.94957C35.2666 10.2075 33.002 14.3928 32.0939 18.9584C31.1858 23.5239 31.6764 28.2573 33.5015 32.5396C35.2405 36.8543 38.2411 40.5439 42.111 43.1256C45.9809 45.7073 50.5398 47.061 55.1915 47.0096H78.6715V23.5496C78.7227 18.8952 77.3666 14.334 74.781 10.4636C72.1954 6.59321 68.5008 3.59419 64.1815 1.85957V1.85957Z" fill="#FFCB00"/>
|
|
59
|
+
<path d="M149.732 31.0096C144.239 25.5215 137.243 21.784 129.627 20.2691C122.012 18.7541 114.118 19.5296 106.943 22.4977C99.7679 25.4657 93.6332 30.4932 89.3133 36.9453C84.9935 43.3974 82.6823 50.9849 82.6715 58.7496V98.0096H122.012C129.799 98.0918 137.43 95.8208 143.905 91.4939C150.38 87.167 155.398 80.9859 158.301 73.7596C161.337 66.5983 162.143 58.6883 160.614 51.062C159.085 43.4358 155.293 36.4476 149.732 31.0096V31.0096Z" fill="#FF7162"/>
|
|
60
|
+
<path d="M127.852 116.53C126.113 112.21 123.112 108.515 119.241 105.928C115.369 103.341 110.807 101.983 106.152 102.03H82.6715V125.51C82.6225 130.165 83.9806 134.726 86.5679 138.596C89.1552 142.467 92.8511 145.465 97.1715 147.2C100.062 148.415 103.166 149.044 106.302 149.05C110.151 149.01 113.931 148.029 117.313 146.191C120.695 144.353 123.575 141.714 125.702 138.505C127.828 135.296 129.136 131.616 129.51 127.785C129.885 123.954 129.316 120.089 127.852 116.53V116.53Z" fill="#0DCF82"/>
|
|
61
|
+
<path d="M3.10152 75.2796C0.0453598 82.4433 -0.776403 90.363 0.743827 98.0016C2.26406 105.64 6.05543 112.642 11.6215 118.09C15.2126 121.748 19.4944 124.658 24.2185 126.649C28.9425 128.64 34.0149 129.674 39.1415 129.69C44.3888 129.678 49.5819 128.628 54.4215 126.6C61.6486 123.697 67.8306 118.68 72.1576 112.204C76.4847 105.729 78.7551 98.0973 78.6715 90.3096V51.0096H39.3915C31.6018 50.9289 23.9694 53.2029 17.4939 57.5335C11.0185 61.8641 6.002 68.0496 3.10152 75.2796V75.2796Z" fill="#A259FE"/>
|
|
62
|
+
</svg>
|
|
63
|
+
`
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const styles = `
|
|
67
|
+
.snippyly-plugin-container {
|
|
68
|
+
display: flex;
|
|
69
|
+
border: 1px solid lightgrey;
|
|
70
|
+
border-radius: 8px;
|
|
71
|
+
position: fixed;
|
|
72
|
+
bottom: 0;
|
|
73
|
+
right: 0;
|
|
74
|
+
margin: 24px;
|
|
75
|
+
min-height: 48px;
|
|
76
|
+
align-items: center;
|
|
77
|
+
z-index: 999999999;
|
|
78
|
+
background: white;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.snippyly-feature-block {
|
|
82
|
+
padding: 8px;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
display: flex;
|
|
85
|
+
align-items: center;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#snippylyPlugin .snippyly-feature-block.snippyly-toggle-btn {
|
|
89
|
+
display: none;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#snippylyPlugin.show .snippyly-feature-block {
|
|
93
|
+
display: flex;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#snippylyPlugin.show .snippyly-feature-block.snippyly-toggle-btn {
|
|
97
|
+
display: none;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#snippylyPlugin.hide .snippyly-feature-block {
|
|
101
|
+
display: none !important;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#snippylyPlugin.hide .snippyly-feature-block.snippyly-toggle-btn {
|
|
105
|
+
display: flex !important;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.snippyly-feature-block.comment-btn:hover svg {
|
|
109
|
+
fill: #a259fe;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.snippyly-feature-block.share-btn:hover svg {
|
|
113
|
+
fill: rgb(13, 207, 130);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.snippyly-feature-block.close-btn:hover svg {
|
|
117
|
+
fill: rgb(255, 113, 98);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.snippyly-feature-block.remove-btn:hover svg {
|
|
121
|
+
fill: red;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.snippyly-feature-block svg {
|
|
125
|
+
height: 24px;
|
|
126
|
+
width: 24px;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.snippyly-feature-block img {
|
|
130
|
+
height: 28px;
|
|
131
|
+
width: 28px;
|
|
132
|
+
border-radius: 100px;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* The snackbar - position it at the bottom and in the middle of the screen */
|
|
136
|
+
#snackbar {
|
|
137
|
+
visibility: hidden; /* Hidden by default. Visible on click */
|
|
138
|
+
min-width: 250px; /* Set a default minimum width */
|
|
139
|
+
margin-left: -125px; /* Divide value of min-width by 2 */
|
|
140
|
+
background-color: #333; /* Black background color */
|
|
141
|
+
color: #fff; /* White text color */
|
|
142
|
+
text-align: center; /* Centered text */
|
|
143
|
+
border-radius: 2px; /* Rounded borders */
|
|
144
|
+
padding: 16px; /* Padding */
|
|
145
|
+
position: fixed; /* Sit on top of the screen */
|
|
146
|
+
z-index: 1; /* Add a z-index if needed */
|
|
147
|
+
left: 50%; /* Center the snackbar */
|
|
148
|
+
bottom: 30px; /* 30px from the bottom */
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* Show the snackbar when clicking on a button (class added with JavaScript) */
|
|
152
|
+
#snackbar.show {
|
|
153
|
+
visibility: visible; /* Show the snackbar */
|
|
154
|
+
/* Add animation: Take 0.5 seconds to fade in and out the snackbar.
|
|
155
|
+
However, delay the fade out process for 2.5 seconds */
|
|
156
|
+
-webkit-animation: fadein 0.5s, fadeout 0.5s 1.6s;
|
|
157
|
+
animation: fadein 0.5s, fadeout 0.5s 1.6s;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* Animations to fade the snackbar in and out */
|
|
161
|
+
@-webkit-keyframes fadein {
|
|
162
|
+
from {bottom: 0; opacity: 0;}
|
|
163
|
+
to {bottom: 30px; opacity: 1;}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@keyframes fadein {
|
|
167
|
+
from {bottom: 0; opacity: 0;}
|
|
168
|
+
to {bottom: 30px; opacity: 1;}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@-webkit-keyframes fadeout {
|
|
172
|
+
from {bottom: 30px; opacity: 1;}
|
|
173
|
+
to {bottom: 0; opacity: 0;}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@keyframes fadeout {
|
|
177
|
+
from {bottom: 30px; opacity: 1;}
|
|
178
|
+
to {bottom: 0; opacity: 0;}
|
|
179
|
+
}
|
|
180
|
+
`;
|
package/firebase.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// import { initializeApp } from "firebase/app";
|
|
2
2
|
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.8.3/firebase-app.js';
|
|
3
3
|
// import { getAuth, GoogleAuthProvider } from "firebase/auth";
|
|
4
|
-
import { getAuth, GoogleAuthProvider, signInWithPopup, onAuthStateChanged } from 'https://www.gstatic.com/firebasejs/9.8.3/firebase-auth.js';
|
|
4
|
+
import { getAuth, GoogleAuthProvider, signInWithPopup, onAuthStateChanged, signOut } from 'https://www.gstatic.com/firebasejs/9.8.3/firebase-auth.js';
|
|
5
5
|
|
|
6
6
|
// TODO: Replace the following with your app's Firebase project configuration
|
|
7
7
|
// See: https://firebase.google.com/docs/web/learn-more#config-object
|
|
@@ -31,7 +31,6 @@ export const loginWithGoogle = () => {
|
|
|
31
31
|
const token = credential.accessToken;
|
|
32
32
|
// The signed-in user info.
|
|
33
33
|
const user = result.user;
|
|
34
|
-
console.log('user', user);
|
|
35
34
|
return user;
|
|
36
35
|
// ...
|
|
37
36
|
}).catch((error) => {
|
|
@@ -48,4 +47,8 @@ export const loginWithGoogle = () => {
|
|
|
48
47
|
|
|
49
48
|
export const getUser = (callback) => {
|
|
50
49
|
onAuthStateChanged(auth, callback);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const signOutUser = () => {
|
|
53
|
+
signOut(auth);
|
|
51
54
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snippyly/plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "snippyly.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"publish:
|
|
8
|
+
"publish:plugin": "npm version patch && npm publish --access public"
|
|
9
9
|
},
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC"
|
package/plugin-ui.js
CHANGED
|
@@ -1,332 +1,278 @@
|
|
|
1
1
|
import * as firebase from './firebase.js';
|
|
2
|
+
import * as Constants from './constants.js';
|
|
2
3
|
|
|
3
4
|
let snippylyUser;
|
|
4
|
-
let commentBtnTool, shareBtn, loginBtn, closeBtn, snippylyBtn;
|
|
5
|
+
let commentBtnTool, shareBtn, loginBtn, logoutBtn, closeBtn, removeBtn, snippylyBtn, snackbar;
|
|
5
6
|
|
|
6
7
|
export const initializeSnippyly = async () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
try {
|
|
9
|
+
if (window.SNIPPYLY_API_KEY) {
|
|
10
|
+
if (window.Snippyly) {
|
|
11
|
+
await Snippyly.init(window.SNIPPYLY_API_KEY);
|
|
12
|
+
Snippyly.getCommentElement().enableTextComments(true);
|
|
13
|
+
Snippyly.getCommentElement().enableSignInButton(true);
|
|
14
|
+
setDocumentId();
|
|
15
|
+
getUser();
|
|
16
|
+
addPluginUI();
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
console.warn('Snippyly api key is not added.');
|
|
20
|
+
}
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.warn('Error in initializeSnippyly: ', err);
|
|
13
23
|
}
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
export const addPluginUI = () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
d="M11 2.5a2.5 2.5 0 1 1 .603 1.628l-6.718 3.12a2.499 2.499 0 0 1 0 1.504l6.718 3.12a2.5 2.5 0 1 1-.488.876l-6.718-3.12a2.5 2.5 0 1 1 0-3.256l6.718-3.12A2.5 2.5 0 0 1 11 2.5z" />
|
|
46
|
-
</svg>
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
// Add login btn
|
|
50
|
-
loginBtn = document.createElement('div');
|
|
51
|
-
loginBtn.classList.add(...['snippyly-feature-block']);
|
|
52
|
-
loginBtn.addEventListener('click', () => {
|
|
53
|
-
loginWithGoogle();
|
|
54
|
-
});
|
|
55
|
-
loginBtn.innerHTML = `
|
|
56
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
|
57
|
-
<g transform="matrix(1, 0, 0, 1, 27.009001, -39.238998)">
|
|
58
|
-
<path fill="#4285F4" d="M -3.264 51.509 C -3.264 50.719 -3.334 49.969 -3.454 49.239 L -14.754 49.239 L -14.754 53.749 L -8.284 53.749 C -8.574 55.229 -9.424 56.479 -10.684 57.329 L -10.684 60.329 L -6.824 60.329 C -4.564 58.239 -3.264 55.159 -3.264 51.509 Z"/>
|
|
59
|
-
<path fill="#34A853" d="M -14.754 63.239 C -11.514 63.239 -8.804 62.159 -6.824 60.329 L -10.684 57.329 C -11.764 58.049 -13.134 58.489 -14.754 58.489 C -17.884 58.489 -20.534 56.379 -21.484 53.529 L -25.464 53.529 L -25.464 56.619 C -23.494 60.539 -19.444 63.239 -14.754 63.239 Z"/>
|
|
60
|
-
<path fill="#FBBC05" d="M -21.484 53.529 C -21.734 52.809 -21.864 52.039 -21.864 51.239 C -21.864 50.439 -21.724 49.669 -21.484 48.949 L -21.484 45.859 L -25.464 45.859 C -26.284 47.479 -26.754 49.299 -26.754 51.239 C -26.754 53.179 -26.284 54.999 -25.464 56.619 L -21.484 53.529 Z"/>
|
|
61
|
-
<path fill="#EA4335" d="M -14.754 43.989 C -12.984 43.989 -11.404 44.599 -10.154 45.789 L -6.734 42.369 C -8.804 40.429 -11.514 39.239 -14.754 39.239 C -19.444 39.239 -23.494 41.939 -25.464 45.859 L -21.484 48.949 C -20.534 46.099 -17.884 43.989 -14.754 43.989 Z"/>
|
|
62
|
-
</g>
|
|
63
|
-
</svg>
|
|
64
|
-
`;
|
|
65
|
-
|
|
66
|
-
// Add close btn
|
|
67
|
-
closeBtn = document.createElement('div');
|
|
68
|
-
closeBtn.classList.add(...['snippyly-feature-block', 'close-btn']);
|
|
69
|
-
closeBtn.addEventListener('click', () => {
|
|
70
|
-
const plugin = shadowRoot.getElementById('snippylyPlugin');
|
|
71
|
-
if (plugin) {
|
|
72
|
-
if (plugin.classList.contains('show')) {
|
|
73
|
-
plugin.classList.remove('show');
|
|
74
|
-
plugin.classList.add('hide');
|
|
27
|
+
try {
|
|
28
|
+
const snippylyPlugin = document.createElement('snippyly-plugin');
|
|
29
|
+
snippylyPlugin.attachShadow({ mode: 'open' })
|
|
30
|
+
const shadowRoot = snippylyPlugin.shadowRoot;
|
|
31
|
+
|
|
32
|
+
const snippylyPluginContainer = document.createElement('div');
|
|
33
|
+
snippylyPluginContainer.id = 'snippylyPlugin';
|
|
34
|
+
snippylyPluginContainer.classList.add(...['snippyly-plugin-container', 'show']);
|
|
35
|
+
|
|
36
|
+
// Add comment btn
|
|
37
|
+
commentBtnTool = document.createElement('snippyly-comment-tool');
|
|
38
|
+
commentBtnTool.innerHTML = Constants.ICONS.PIN;
|
|
39
|
+
|
|
40
|
+
// Add share btn
|
|
41
|
+
shareBtn = document.createElement('div');
|
|
42
|
+
shareBtn.classList.add(...['snippyly-feature-block', 'share-btn']);
|
|
43
|
+
shareBtn.addEventListener('click', () => {
|
|
44
|
+
navigator.clipboard.writeText(window.location.href);
|
|
45
|
+
showSnackbar('Link copied!');
|
|
46
|
+
});
|
|
47
|
+
shareBtn.innerHTML = Constants.ICONS.SHARE;
|
|
48
|
+
|
|
49
|
+
// Add login btn
|
|
50
|
+
loginBtn = document.createElement('div');
|
|
51
|
+
loginBtn.classList.add(...['snippyly-feature-block']);
|
|
52
|
+
loginBtn.addEventListener('click', () => {
|
|
53
|
+
if (snippylyUser?.userId) {
|
|
54
|
+
// signOutUser();
|
|
75
55
|
} else {
|
|
76
|
-
|
|
77
|
-
plugin.classList.add('show');
|
|
56
|
+
loginWithGoogle();
|
|
78
57
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
snippylyBtn = document.createElement('div');
|
|
89
|
-
snippylyBtn.classList.add(...['snippyly-feature-block', 'snippyly-toggle-btn']);
|
|
90
|
-
snippylyBtn.addEventListener('click', () => {
|
|
91
|
-
const plugin = shadowRoot.getElementById('snippylyPlugin');
|
|
92
|
-
if (plugin) {
|
|
93
|
-
if (plugin.classList.contains('show')) {
|
|
94
|
-
plugin.classList.remove('show');
|
|
95
|
-
plugin.classList.add('hide');
|
|
58
|
+
});
|
|
59
|
+
loginBtn.innerHTML = Constants.ICONS.GOOGLE;
|
|
60
|
+
|
|
61
|
+
logoutBtn = document.createElement('div');
|
|
62
|
+
logoutBtn.classList.add(...['snippyly-feature-block']);
|
|
63
|
+
logoutBtn.style.display = 'none';
|
|
64
|
+
logoutBtn.addEventListener('click', () => {
|
|
65
|
+
if (snippylyUser?.userId) {
|
|
66
|
+
signOutUser();
|
|
96
67
|
} else {
|
|
97
|
-
|
|
98
|
-
plugin.classList.add('show');
|
|
68
|
+
// loginWithGoogle();
|
|
99
69
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
.
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
height: 28px;
|
|
178
|
-
width: 28px;
|
|
179
|
-
border-radius: 100px;
|
|
180
|
-
}
|
|
181
|
-
`;
|
|
182
|
-
|
|
183
|
-
shadowRoot.appendChild(styles);
|
|
184
|
-
shadowRoot.appendChild(snippylyPluginContainer);
|
|
185
|
-
|
|
186
|
-
// add snippyly elements
|
|
187
|
-
const snippylyComments = document.createElement('snippyly-comments');
|
|
188
|
-
document.body.appendChild(snippylyComments);
|
|
189
|
-
|
|
190
|
-
const snippylyCursor = document.createElement('snippyly-cursor');
|
|
191
|
-
document.body.appendChild(snippylyCursor);
|
|
70
|
+
});
|
|
71
|
+
logoutBtn.innerHTML = Constants.ICONS.SIGNOUT;
|
|
72
|
+
|
|
73
|
+
// Add close btn
|
|
74
|
+
closeBtn = document.createElement('div');
|
|
75
|
+
closeBtn.classList.add(...['snippyly-feature-block', 'close-btn']);
|
|
76
|
+
closeBtn.addEventListener('click', () => {
|
|
77
|
+
const plugin = shadowRoot.getElementById('snippylyPlugin');
|
|
78
|
+
if (plugin) {
|
|
79
|
+
if (plugin.classList.contains('show')) {
|
|
80
|
+
plugin.classList.remove('show');
|
|
81
|
+
plugin.classList.add('hide');
|
|
82
|
+
} else {
|
|
83
|
+
plugin.classList.remove('hide');
|
|
84
|
+
plugin.classList.add('show');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
closeBtn.innerHTML = Constants.ICONS.CLOSE;
|
|
89
|
+
|
|
90
|
+
// Add remove btn
|
|
91
|
+
removeBtn = document.createElement('div');
|
|
92
|
+
removeBtn.classList.add(...['snippyly-feature-block', 'remove-btn']);
|
|
93
|
+
removeBtn.addEventListener('click', () => {
|
|
94
|
+
removeSnippyly();
|
|
95
|
+
});
|
|
96
|
+
removeBtn.innerHTML = Constants.ICONS.TRASH;
|
|
97
|
+
|
|
98
|
+
// Add snippyly btn
|
|
99
|
+
snippylyBtn = document.createElement('div');
|
|
100
|
+
snippylyBtn.classList.add(...['snippyly-feature-block', 'snippyly-toggle-btn']);
|
|
101
|
+
snippylyBtn.addEventListener('click', () => {
|
|
102
|
+
const plugin = shadowRoot.getElementById('snippylyPlugin');
|
|
103
|
+
if (plugin) {
|
|
104
|
+
if (plugin.classList.contains('show')) {
|
|
105
|
+
plugin.classList.remove('show');
|
|
106
|
+
plugin.classList.add('hide');
|
|
107
|
+
} else {
|
|
108
|
+
plugin.classList.remove('hide');
|
|
109
|
+
plugin.classList.add('show');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
snippylyBtn.innerHTML = Constants.ICONS.SNIPPYLY;
|
|
114
|
+
|
|
115
|
+
snackbar = document.createElement('div');
|
|
116
|
+
snackbar.id = 'snackbar';
|
|
117
|
+
|
|
118
|
+
snippylyPluginContainer.appendChild(commentBtnTool);
|
|
119
|
+
snippylyPluginContainer.appendChild(shareBtn);
|
|
120
|
+
snippylyPluginContainer.appendChild(loginBtn);
|
|
121
|
+
snippylyPluginContainer.appendChild(logoutBtn);
|
|
122
|
+
snippylyPluginContainer.appendChild(closeBtn);
|
|
123
|
+
snippylyPluginContainer.appendChild(removeBtn);
|
|
124
|
+
snippylyPluginContainer.appendChild(snippylyBtn);
|
|
125
|
+
snippylyPluginContainer.appendChild(snackbar);
|
|
126
|
+
|
|
127
|
+
window.document.body.appendChild(snippylyPlugin);
|
|
128
|
+
|
|
129
|
+
const styles = document.createElement('style');
|
|
130
|
+
styles.innerHTML = Constants.styles;
|
|
131
|
+
|
|
132
|
+
shadowRoot.appendChild(styles);
|
|
133
|
+
shadowRoot.appendChild(snippylyPluginContainer);
|
|
134
|
+
|
|
135
|
+
// add snippyly elements
|
|
136
|
+
const snippylyComments = document.createElement('snippyly-comments');
|
|
137
|
+
snippylyComments.addEventListener('signIn', () => {
|
|
138
|
+
loginWithGoogle();
|
|
139
|
+
})
|
|
140
|
+
document.body.appendChild(snippylyComments);
|
|
141
|
+
|
|
142
|
+
const snippylyCursor = document.createElement('snippyly-cursor');
|
|
143
|
+
document.body.appendChild(snippylyCursor);
|
|
144
|
+
} catch (err) {
|
|
145
|
+
console.warn('Error in addPluginUI: ', err);
|
|
146
|
+
}
|
|
192
147
|
}
|
|
193
148
|
|
|
194
149
|
export const addSnippylyCdn = () => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
150
|
+
try {
|
|
151
|
+
const existingScript = document.getElementById('snippylyScript');
|
|
152
|
+
if (!existingScript) {
|
|
153
|
+
const script = document.createElement('script');
|
|
154
|
+
const version = window.SNIPPYLY_VERSION || 'latest';
|
|
155
|
+
const staging = !!window.SNIPPYLY_STAGING;
|
|
156
|
+
script.src = `https://cdn.jsdelivr.net/npm/@snippyly/sdk${staging ? '-staging' : ''}@${version}/snippyly.js`;
|
|
157
|
+
script.id = 'snippylyScript';
|
|
158
|
+
script.type = 'module';
|
|
159
|
+
document.body.appendChild(script);
|
|
160
|
+
script.onload = () => {
|
|
161
|
+
if (initializeSnippyly) {
|
|
162
|
+
initializeSnippyly();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
} else {
|
|
203
166
|
if (initializeSnippyly) {
|
|
204
167
|
initializeSnippyly();
|
|
205
168
|
}
|
|
206
|
-
};
|
|
207
|
-
} else {
|
|
208
|
-
if (initializeSnippyly) {
|
|
209
|
-
initializeSnippyly();
|
|
210
169
|
}
|
|
170
|
+
} catch (err) {
|
|
171
|
+
console.warn('Error in addSnippylyCdn: ', err);
|
|
211
172
|
}
|
|
212
173
|
}
|
|
213
174
|
|
|
214
|
-
const
|
|
215
|
-
{
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
{
|
|
224
|
-
userId: '2',
|
|
225
|
-
name: 'Maria Garcia',
|
|
226
|
-
email: 'maria.garcia@gmail.com',
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
userId: '3',
|
|
230
|
-
name: 'Sarah Wilson',
|
|
231
|
-
email: 'sarah.wilson@gmail.com',
|
|
232
|
-
}
|
|
233
|
-
]
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
userId: 'maria.garcia@gmail.com',
|
|
237
|
-
name: 'Maria Garcia',
|
|
238
|
-
photoUrl: '',
|
|
239
|
-
email: 'maria.garcia@gmail.com',
|
|
240
|
-
plan: 'paid',
|
|
241
|
-
groupId: '',
|
|
242
|
-
isReadOnly: true,
|
|
243
|
-
contacts: [
|
|
244
|
-
{
|
|
245
|
-
userId: '1',
|
|
246
|
-
name: 'James Smith',
|
|
247
|
-
email: 'james.smith@gmail.com',
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
userId: '3',
|
|
251
|
-
name: 'Sarah Wilson',
|
|
252
|
-
email: 'sarah.wilson@gmail.com',
|
|
253
|
-
}
|
|
254
|
-
]
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
userId: '3',
|
|
258
|
-
name: 'Sarah Wilson',
|
|
259
|
-
photoUrl: '',
|
|
260
|
-
email: 'sarah.wilson@gmail.com',
|
|
261
|
-
plan: 'trial',
|
|
262
|
-
groupId: '',
|
|
263
|
-
isAdmin: true,
|
|
264
|
-
contacts: [
|
|
265
|
-
{
|
|
266
|
-
userId: '1',
|
|
267
|
-
name: 'James Smith',
|
|
268
|
-
email: 'james.smith@gmail.com',
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
userId: '2',
|
|
272
|
-
name: 'Maria Garcia',
|
|
273
|
-
email: 'maria.garcia@gmail.com',
|
|
274
|
-
}
|
|
275
|
-
]
|
|
175
|
+
export const setDocumentId = () => {
|
|
176
|
+
try {
|
|
177
|
+
const url = (new URL(document.location));
|
|
178
|
+
const params = url.searchParams;
|
|
179
|
+
if (params.has(Constants.REVIEW_DOC_ID)) {
|
|
180
|
+
Snippyly.setDocumentId(params.get(Constants.REVIEW_DOC_ID));
|
|
181
|
+
}
|
|
182
|
+
} catch (err) {
|
|
183
|
+
console.warn('Error in setDocumentId: ', err);
|
|
276
184
|
}
|
|
277
|
-
|
|
185
|
+
}
|
|
278
186
|
|
|
279
187
|
const getUser = () => {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
188
|
+
try {
|
|
189
|
+
firebase.getUser((user) => {
|
|
190
|
+
try {
|
|
191
|
+
if (user) {
|
|
192
|
+
snippylyUser = {};
|
|
193
|
+
snippylyUser.userId = user.uid;
|
|
194
|
+
snippylyUser.name = user.displayName;
|
|
195
|
+
snippylyUser.email = user.email;
|
|
196
|
+
snippylyUser.photoUrl = user?.photoURL;
|
|
197
|
+
identifyUser();
|
|
198
|
+
}
|
|
199
|
+
} catch (err) {
|
|
200
|
+
console.warn('Error in getUser callback: ', err);
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
} catch (err) {
|
|
204
|
+
console.warn('Error in getUser: ', err);
|
|
205
|
+
}
|
|
291
206
|
}
|
|
292
207
|
|
|
293
208
|
const loginWithGoogle = () => {
|
|
294
209
|
firebase.loginWithGoogle();
|
|
295
210
|
}
|
|
296
211
|
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
// localStorage.setItem('user', JSON.stringify(user));
|
|
303
|
-
// } else {
|
|
304
|
-
// user = JSON.parse(localStorage.getItem('user'));
|
|
305
|
-
// }
|
|
306
|
-
|
|
307
|
-
// firebase.loginWithGoogle().then(async (user) => {
|
|
308
|
-
// if (user) {
|
|
309
|
-
// snippylyUser = {};
|
|
310
|
-
// snippylyUser.userId = user.uid;
|
|
311
|
-
// snippylyUser.name = user.displayName;
|
|
312
|
-
// snippylyUser.email = user.email;
|
|
313
|
-
// snippylyUser.photoUrl = user?.photoURL;
|
|
314
|
-
// await Snippyly.identify(snippylyUser);
|
|
315
|
-
// showUser(snippylyUser);
|
|
316
|
-
// }
|
|
317
|
-
// console.log('snippyly user', user);
|
|
318
|
-
// })
|
|
319
|
-
|
|
320
|
-
if(snippylyUser?.userId) {
|
|
321
|
-
await Snippyly.identify(snippylyUser);
|
|
212
|
+
const signOutUser = () => {
|
|
213
|
+
try {
|
|
214
|
+
Snippyly.signOutUser();
|
|
215
|
+
firebase.signOutUser();
|
|
216
|
+
snippylyUser = {};
|
|
322
217
|
showUser();
|
|
218
|
+
} catch (err) {
|
|
219
|
+
console.warn('Error in signOutUser: ', err);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const identifyUser = async () => {
|
|
224
|
+
try {
|
|
225
|
+
if (snippylyUser?.userId) {
|
|
226
|
+
await Snippyly.identify(snippylyUser);
|
|
227
|
+
showUser();
|
|
228
|
+
}
|
|
229
|
+
} catch (err) {
|
|
230
|
+
console.warn('Error in identifyUser: ', err);
|
|
323
231
|
}
|
|
324
232
|
}
|
|
325
233
|
|
|
326
234
|
const showUser = () => {
|
|
327
|
-
|
|
328
|
-
|
|
235
|
+
try {
|
|
236
|
+
if (snippylyUser?.userId) {
|
|
237
|
+
loginBtn.innerHTML = `
|
|
329
238
|
<img src="${snippylyUser?.photoUrl}" title="${snippylyUser?.name}" class="user-profile-img" />
|
|
330
|
-
|
|
239
|
+
`;
|
|
240
|
+
logoutBtn.style.display = 'flex';
|
|
241
|
+
} else {
|
|
242
|
+
loginBtn.innerHTML = Constants.ICONS.GOOGLE;
|
|
243
|
+
logoutBtn.style.display = 'none';
|
|
244
|
+
}
|
|
245
|
+
} catch (err) {
|
|
246
|
+
console.warn('Error in showUser: ', err);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const showSnackbar = (message) => {
|
|
251
|
+
try {
|
|
252
|
+
snackbar.innerText = message;
|
|
253
|
+
snackbar.className = 'show';
|
|
254
|
+
setTimeout(() => {
|
|
255
|
+
snackbar.className = snackbar.className.replace('show', '');
|
|
256
|
+
}, 2000);
|
|
257
|
+
} catch (err) {
|
|
258
|
+
console.warn('Error in showSnackbar: ', err);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const removeSnippyly = () => {
|
|
263
|
+
try {
|
|
264
|
+
const element = document.getElementById('snippylyScript');
|
|
265
|
+
if (element) {
|
|
266
|
+
element.remove();
|
|
267
|
+
}
|
|
268
|
+
sessionStorage.removeItem(Constants.REVIEW_MODE);
|
|
269
|
+
const url = new URL(document.location);
|
|
270
|
+
const params = url.searchParams;
|
|
271
|
+
params.delete(Constants.REVIEW_DOC_ID);
|
|
272
|
+
params.delete(Constants.REVIEW_MODE);
|
|
273
|
+
window.history.replaceState({}, document.title, url.href);
|
|
274
|
+
window.location.reload();
|
|
275
|
+
} catch (err) {
|
|
276
|
+
console.warn('Error in removeSnippyly: ', err);
|
|
331
277
|
}
|
|
332
278
|
}
|
package/snippyly.js
CHANGED
|
@@ -1,29 +1,77 @@
|
|
|
1
1
|
import * as ui from './plugin-ui.js';
|
|
2
|
+
import * as Constants from './constants.js';
|
|
3
|
+
import { cyrb53 } from './utils.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const checkUrl = () => {
|
|
7
|
+
try {
|
|
8
|
+
const url = new URL(document.location);
|
|
9
|
+
const params = url.searchParams;
|
|
10
|
+
if (params.has(Constants.REVIEW_MODE)) {
|
|
11
|
+
sessionStorage.setItem(Constants.REVIEW_MODE, true);
|
|
12
|
+
if (params.has(Constants.REVIEW_DOC_ID)) {
|
|
13
|
+
loadPluginUI();
|
|
14
|
+
} else {
|
|
15
|
+
// generate doc id and set it in params
|
|
16
|
+
const tempUrl = new URL(document.location);
|
|
17
|
+
tempUrl.searchParams.delete(Constants.REVIEW_MODE);
|
|
18
|
+
const docId = cyrb53(tempUrl.href);
|
|
19
|
+
params.append(Constants.REVIEW_DOC_ID, docId);
|
|
20
|
+
window.history.replaceState({}, document.title, url.href);
|
|
21
|
+
checkUrl();
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
// check if review mode is there in session storage
|
|
25
|
+
if (sessionStorage.getItem(Constants.REVIEW_MODE)) {
|
|
26
|
+
params.append(Constants.REVIEW_MODE, true);
|
|
27
|
+
window.history.replaceState({}, document.title, url.href);
|
|
28
|
+
checkUrl();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.warn('Error in checkUrl: ', err);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
2
35
|
|
|
3
36
|
const loadPluginUI = () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
37
|
+
try {
|
|
38
|
+
const pluginElement = document.querySelector('snippyly-plugin');
|
|
39
|
+
if (!pluginElement) {
|
|
40
|
+
ui.addSnippylyCdn();
|
|
41
|
+
} else {
|
|
42
|
+
ui.setDocumentId();
|
|
43
|
+
}
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.warn('Error in loadPluginUI: ', err);
|
|
8
46
|
}
|
|
9
47
|
}
|
|
10
48
|
|
|
11
49
|
(() => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
50
|
+
let oldPushState = history.pushState;
|
|
51
|
+
history.pushState = function pushState() {
|
|
52
|
+
let ret = oldPushState.apply(this, arguments);
|
|
53
|
+
window.dispatchEvent(new Event('pushstate'));
|
|
54
|
+
window.dispatchEvent(new Event('locationchange'));
|
|
55
|
+
return ret;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
let oldReplaceState = history.replaceState;
|
|
59
|
+
history.replaceState = function replaceState() {
|
|
60
|
+
let ret = oldReplaceState.apply(this, arguments);
|
|
61
|
+
window.dispatchEvent(new Event('replacestate'));
|
|
62
|
+
window.dispatchEvent(new Event('locationchange'));
|
|
63
|
+
return ret;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
window.addEventListener('popstate', () => {
|
|
67
|
+
window.dispatchEvent(new Event('locationchange'));
|
|
68
|
+
});
|
|
16
69
|
})();
|
|
17
70
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
loadPluginUI();
|
|
22
|
-
}
|
|
23
|
-
});
|
|
71
|
+
(() => {
|
|
72
|
+
checkUrl();
|
|
73
|
+
})();
|
|
24
74
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// }
|
|
29
|
-
// }, 3000);
|
|
75
|
+
window.addEventListener('locationchange', () => {
|
|
76
|
+
checkUrl();
|
|
77
|
+
});
|
package/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const cyrb53 = (str, seed = 0) => {
|
|
2
|
+
try {
|
|
3
|
+
let h1 = 0xdeadbeef ^ seed,
|
|
4
|
+
h2 = 0x41c6ce57 ^ seed;
|
|
5
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
6
|
+
ch = str.charCodeAt(i);
|
|
7
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
8
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
9
|
+
}
|
|
10
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
11
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
12
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
Console.catch('Error in cyrb53: ', err);
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
};
|