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
Hide 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
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
function
objectToQueryString
(
obj
)
{
const
keyValuePairs
=
[];
...
...
@@ -26,7 +68,7 @@ var getUserDetails = null
return
keyValuePairs
.
join
(
'&'
);
}
return
{
post
(
url
,
body
=
{},
headers
=
{})
{
post
(
url
,
body
=
{},
headers
=
{})
{
if
(
url
.
slice
(
0
,
4
)
!=
'http'
)
url
=
(
baseURL
+
`/api
${
url
[
0
]
==
'/'
?
''
:
'/'
}${
url
}
`
)
return
new
Promise
((
res
,
rej
)
=>
{
let
bodyObj
=
{
...
body
}
...
...
@@ -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
}
`
return
new
Promise
((
res
,
rej
)
=>
{
let
bodyObj
=
{
...
body
}
...
...
@@ -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
}
`
let
params
=
objectToQueryString
(
obj
.
params
)
if
(
params
)
url
+=
`?
${
params
}
`
...
...
@@ -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
}
`
let
params
=
objectToQueryString
(
obj
.
params
)
if
(
params
)
url
+=
`?
${
params
}
`
...
...
@@ -152,6 +194,10 @@ var getUserDetails = null
})
sendMessageToActiveTab
(
"loggedIn"
)
setData
(
"userDetails"
,
userDetails
)
setData
(
"recording"
,
false
)
setData
(
"tutorShotId"
,
tutorShotId
)
setData
(
"imageNumber"
,
imageNumber
)
return
}
...
...
@@ -178,6 +224,9 @@ var getUserDetails = null
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
});
sendMessageToActiveTab
(
"recordingStarted"
)
setData
(
"recording"
,
true
)
setData
(
"tutorShotId"
,
tutorShotId
)
setData
(
"imageNumber"
,
imageNumber
)
return
}
if
(
loggedIn
&&
request
.
action
===
'pauseRecording'
)
{
...
...
@@ -189,6 +238,7 @@ var getUserDetails = null
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
});
sendMessageToActiveTab
(
"recordingPaused"
)
setData
(
"recording"
,
false
)
return
}
if
(
loggedIn
&&
request
.
action
===
'resumeRecording'
)
{
...
...
@@ -200,6 +250,7 @@ var getUserDetails = null
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
});
sendMessageToActiveTab
(
"recordingResumed"
)
setData
(
"recording"
,
true
)
return
}
if
(
loggedIn
&&
request
.
action
===
'stopRecording'
)
{
...
...
@@ -213,6 +264,8 @@ var getUserDetails = null
status
:
tutorShotId
?
(
recording
?
"recording"
:
"paused"
)
:
"stopped"
});
sendMessageToActiveTab
(
"recordingStopped"
)
setData
(
"recording"
,
false
)
setData
(
"tutorShotId"
,
tutorShotId
)
return
}
if
(
loggedIn
&&
request
.
action
===
'restartRecording'
)
{
...
...
@@ -225,6 +278,7 @@ var getUserDetails = null
});
await
api
.
delete
(
'/tutor-shot/segments'
,
{
params
:
{
tutorShotOid
:
tutorShotId
}
})
sendMessageToActiveTab
(
"recordingRestarted"
)
setData
(
"imageNumber"
,
0
)
return
}
...
...
manifest.json
View file @
3b4e49e5
...
...
@@ -5,7 +5,8 @@
"description"
:
"A basic Chrome extension"
,
"permissions"
:
[
"activeTab"
,
"scripting"
"scripting"
,
"storage"
],
"host_permissions"
:
[
"<all_urls>"
...
...
popup.js
View file @
3b4e49e5
...
...
@@ -78,6 +78,7 @@
function
domLoadHandler
()
{
chrome
.
runtime
.
sendMessage
({
action
:
"checkStatus"
},
function
(
response
)
{
console
.
log
(
'response'
,
response
)
userDetails
=
response
.
userDetails
;
loggedIn
=
response
.
loggedIn
,
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