Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tutor-shot-extension
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ramdayal Munda
tutor-shot-extension
Commits
3b4e49e5
Commit
3b4e49e5
authored
Nov 15, 2023
by
ramdayalmunda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storing the data locally so even if the BG process is inavtive we can retrieve the data
parent
fc770615
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
6 deletions
+62
-6
background.js
background.js
+59
-5
manifest.json
manifest.json
+2
-1
popup.js
popup.js
+1
-0
No files found.
background.js
View file @
3b4e49e5
...
@@ -9,7 +9,49 @@ var getUserDetails = null
...
@@ -9,7 +9,49 @@ var getUserDetails = null
var
userDetails
=
{}
var
userDetails
=
{}
function
createAPI
(
origin
){
function
setData
(
key
,
value
,
callback
)
{
return
new
Promise
((
res
,
rej
)
=>
{
try
{
chrome
.
storage
.
local
.
set
({
[
key
]:
value
},
()
=>
{
if
(
callback
)
callback
(
value
)
else
res
(
value
)
})
}
catch
(
err
)
{
if
(
callback
)
callback
(
undefined
,
err
)
else
callback
(
undefined
)
}
})
}
function
getData
(
key
,
callback
)
{
return
new
Promise
((
res
,
rej
)
=>
{
try
{
chrome
.
storage
.
local
.
get
(
key
,
(
data
)
=>
{
if
(
callback
)
callback
(
data
[
key
])
else
res
(
data
[
key
])
})
}
catch
(
err
)
{
if
(
callback
)
callback
(
undefined
,
err
)
else
res
(
undefined
)
}
})
}
getData
(
'userDetails'
,
async
(
data
)
=>
{
if
(
data
){
let
tso
=
await
getData
(
'tutorShot'
)
tutorShotId
=
tso
?
tso
:
null
let
imgNum
=
await
getData
(
'imageNumber'
)
imageNumber
=
imgNum
?
imgNum
:
0
let
rec
=
await
getData
(
'recording'
)
recording
=
rec
?
rec
:
false
loggedIn
=
true
userDetails
=
data
}
})
function
createAPI
(
origin
)
{
var
baseURL
=
origin
var
baseURL
=
origin
function
objectToQueryString
(
obj
)
{
function
objectToQueryString
(
obj
)
{
const
keyValuePairs
=
[];
const
keyValuePairs
=
[];
...
@@ -26,7 +68,7 @@ var getUserDetails = null
...
@@ -26,7 +68,7 @@ var getUserDetails = null
return
keyValuePairs
.
join
(
'&'
);
return
keyValuePairs
.
join
(
'&'
);
}
}
return
{
return
{
post
(
url
,
body
=
{},
headers
=
{})
{
post
(
url
,
body
=
{},
headers
=
{})
{
if
(
url
.
slice
(
0
,
4
)
!=
'http'
)
url
=
(
baseURL
+
`/api
${
url
[
0
]
==
'/'
?
''
:
'/'
}${
url
}
`
)
if
(
url
.
slice
(
0
,
4
)
!=
'http'
)
url
=
(
baseURL
+
`/api
${
url
[
0
]
==
'/'
?
''
:
'/'
}${
url
}
`
)
return
new
Promise
((
res
,
rej
)
=>
{
return
new
Promise
((
res
,
rej
)
=>
{
let
bodyObj
=
{
...
body
}
let
bodyObj
=
{
...
body
}
...
@@ -51,7 +93,7 @@ var getUserDetails = null
...
@@ -51,7 +93,7 @@ var getUserDetails = null
})
})
})
})
},
},
put
(
url
,
body
=
{},
headers
=
{})
{
put
(
url
,
body
=
{},
headers
=
{})
{
if
(
url
.
slice
(
0
,
4
)
!=
'http'
)
url
=
baseURL
+
`/api
${
url
[
0
]
==
'/'
?
''
:
'/'
}${
url
}
`
if
(
url
.
slice
(
0
,
4
)
!=
'http'
)
url
=
baseURL
+
`/api
${
url
[
0
]
==
'/'
?
''
:
'/'
}${
url
}
`
return
new
Promise
((
res
,
rej
)
=>
{
return
new
Promise
((
res
,
rej
)
=>
{
let
bodyObj
=
{
...
body
}
let
bodyObj
=
{
...
body
}
...
@@ -76,7 +118,7 @@ var getUserDetails = null
...
@@ -76,7 +118,7 @@ var getUserDetails = null
})
})
})
})
},
},
delete
(
url
,
obj
=
{
params
:
{},
headers
:
{}
})
{
delete
(
url
,
obj
=
{
params
:
{},
headers
:
{}
})
{
if
(
url
.
slice
(
0
,
4
)
!=
'http'
)
url
=
baseURL
+
`/api
${
url
[
0
]
==
'/'
?
''
:
'/'
}${
url
}
`
if
(
url
.
slice
(
0
,
4
)
!=
'http'
)
url
=
baseURL
+
`/api
${
url
[
0
]
==
'/'
?
''
:
'/'
}${
url
}
`
let
params
=
objectToQueryString
(
obj
.
params
)
let
params
=
objectToQueryString
(
obj
.
params
)
if
(
params
)
url
+=
`?
${
params
}
`
if
(
params
)
url
+=
`?
${
params
}
`
...
@@ -101,7 +143,7 @@ var getUserDetails = null
...
@@ -101,7 +143,7 @@ var getUserDetails = null
})
})
})
})
},
},
get
(
url
,
obj
=
{
params
:
{},
headers
:
{}
})
{
get
(
url
,
obj
=
{
params
:
{},
headers
:
{}
})
{
if
(
url
.
slice
(
0
,
4
)
!=
'http'
)
url
=
baseURL
+
`/api
${
url
[
0
]
==
'/'
?
''
:
'/'
}${
url
}
`
if
(
url
.
slice
(
0
,
4
)
!=
'http'
)
url
=
baseURL
+
`/api
${
url
[
0
]
==
'/'
?
''
:
'/'
}${
url
}
`
let
params
=
objectToQueryString
(
obj
.
params
)
let
params
=
objectToQueryString
(
obj
.
params
)
if
(
params
)
url
+=
`?
${
params
}
`
if
(
params
)
url
+=
`?
${
params
}
`
...
@@ -152,6 +194,10 @@ var getUserDetails = null
...
@@ -152,6 +194,10 @@ var getUserDetails = null
})
})
sendMessageToActiveTab
(
"loggedIn"
)
sendMessageToActiveTab
(
"loggedIn"
)
setData
(
"userDetails"
,
userDetails
)
setData
(
"recording"
,
false
)
setData
(
"tutorShotId"
,
tutorShotId
)
setData
(
"imageNumber"
,
imageNumber
)
return
return
}
}
...
@@ -178,6 +224,9 @@ var getUserDetails = null
...
@@ -178,6 +224,9 @@ var getUserDetails = null
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
});
});
sendMessageToActiveTab
(
"recordingStarted"
)
sendMessageToActiveTab
(
"recordingStarted"
)
setData
(
"recording"
,
true
)
setData
(
"tutorShotId"
,
tutorShotId
)
setData
(
"imageNumber"
,
imageNumber
)
return
return
}
}
if
(
loggedIn
&&
request
.
action
===
'pauseRecording'
)
{
if
(
loggedIn
&&
request
.
action
===
'pauseRecording'
)
{
...
@@ -189,6 +238,7 @@ var getUserDetails = null
...
@@ -189,6 +238,7 @@ var getUserDetails = null
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
});
});
sendMessageToActiveTab
(
"recordingPaused"
)
sendMessageToActiveTab
(
"recordingPaused"
)
setData
(
"recording"
,
false
)
return
return
}
}
if
(
loggedIn
&&
request
.
action
===
'resumeRecording'
)
{
if
(
loggedIn
&&
request
.
action
===
'resumeRecording'
)
{
...
@@ -200,6 +250,7 @@ var getUserDetails = null
...
@@ -200,6 +250,7 @@ var getUserDetails = null
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
});
});
sendMessageToActiveTab
(
"recordingResumed"
)
sendMessageToActiveTab
(
"recordingResumed"
)
setData
(
"recording"
,
true
)
return
return
}
}
if
(
loggedIn
&&
request
.
action
===
'stopRecording'
)
{
if
(
loggedIn
&&
request
.
action
===
'stopRecording'
)
{
...
@@ -213,6 +264,8 @@ var getUserDetails = null
...
@@ -213,6 +264,8 @@ var getUserDetails = null
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
});
});
sendMessageToActiveTab
(
"recordingStopped"
)
sendMessageToActiveTab
(
"recordingStopped"
)
setData
(
"recording"
,
false
)
setData
(
"tutorShotId"
,
tutorShotId
)
return
return
}
}
if
(
loggedIn
&&
request
.
action
===
'restartRecording'
)
{
if
(
loggedIn
&&
request
.
action
===
'restartRecording'
)
{
...
@@ -225,6 +278,7 @@ var getUserDetails = null
...
@@ -225,6 +278,7 @@ var getUserDetails = null
});
});
await
api
.
delete
(
'/tutor-shot/segments'
,
{
params
:
{
tutorShotOid
:
tutorShotId
}
})
await
api
.
delete
(
'/tutor-shot/segments'
,
{
params
:
{
tutorShotOid
:
tutorShotId
}
})
sendMessageToActiveTab
(
"recordingRestarted"
)
sendMessageToActiveTab
(
"recordingRestarted"
)
setData
(
"imageNumber"
,
0
)
return
return
}
}
...
...
manifest.json
View file @
3b4e49e5
...
@@ -5,7 +5,8 @@
...
@@ -5,7 +5,8 @@
"description"
:
"A basic Chrome extension"
,
"description"
:
"A basic Chrome extension"
,
"permissions"
:
[
"permissions"
:
[
"activeTab"
,
"activeTab"
,
"scripting"
"scripting"
,
"storage"
],
],
"host_permissions"
:
[
"host_permissions"
:
[
"<all_urls>"
"<all_urls>"
...
...
popup.js
View file @
3b4e49e5
...
@@ -78,6 +78,7 @@
...
@@ -78,6 +78,7 @@
function
domLoadHandler
()
{
function
domLoadHandler
()
{
chrome
.
runtime
.
sendMessage
({
action
:
"checkStatus"
},
function
(
response
)
{
chrome
.
runtime
.
sendMessage
({
action
:
"checkStatus"
},
function
(
response
)
{
console
.
log
(
'response'
,
response
)
userDetails
=
response
.
userDetails
;
userDetails
=
response
.
userDetails
;
loggedIn
=
response
.
loggedIn
,
loggedIn
=
response
.
loggedIn
,
recording
=
response
.
recording
recording
=
response
.
recording
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment