Commit f73b468d by ramdayalmunda

refresh issue resolved

parent 9d806564
...@@ -9,10 +9,37 @@ const origin = "http://localhost:3039" ...@@ -9,10 +9,37 @@ const origin = "http://localhost:3039"
var userDetails = {}; var userDetails = {};
var btn = {}; var btn = {};
var tutorShotOid = null; var tutorShotOid = null;
var containerDiv;
var sr;
!(async function () { !(async function () {
if (window.origin == origin) login() if (window.origin == origin) login()
containerDiv = document.createElement('div')
containerDiv.style.position = "fixed"
containerDiv.style.display = "block"
containerDiv.style.background = "transparent"
containerDiv.style.width = "0px"
containerDiv.style.height = "0px"
containerDiv.style.zIndex = "9999"
document.body.append(containerDiv)
const observer = new MutationObserver(async function (mutationsList, observer) {
for (let mutation of mutationsList) {
if (mutation.type === 'childList' && mutation.removedNodes.length > 0) {
if ([...mutation.removedNodes].includes(containerDiv)) {
console.log('The target node has been removed from the DOM.');
let data = await getCaptureData()
reRenderFloatingBar(data)
}
}
}
});
observer.observe(document.body, { childList: true })
sr = containerDiv.attachShadow({ mode: 'open' });
let styleTag = document.createElement('style') let styleTag = document.createElement('style')
styleTag.setAttribute('tutor-shot-style', '') styleTag.setAttribute('tutor-shot-style', '')
styleString = /*css*/` styleString = /*css*/`
...@@ -47,6 +74,7 @@ var tutorShotOid = null; ...@@ -47,6 +74,7 @@ var tutorShotOid = null;
align-items: center; align-items: center;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
transition: 0.3s; transition: 0.3s;
pointer-events: auto;
} }
.tutor-shot.tutor-shot-right { .tutor-shot.tutor-shot-right {
...@@ -128,12 +156,11 @@ var tutorShotOid = null; ...@@ -128,12 +156,11 @@ var tutorShotOid = null;
} }
` `
styleTag.innerHTML = styleString styleTag.append(styleString)
document.body.append(styleTag) sr.append(styleTag)
floatingBar = document.createElement('div') floatingBar = document.createElement('div')
floatingBar.setAttribute('class', `tutor-shot tutor-shot-right`) floatingBar.setAttribute('class', `tutor-shot tutor-shot-right`)
document.body.append(floatingBar)
let innerHTML = /*html*/` let innerHTML = /*html*/`
<div class="counter-count" tutor-shot="counter" style="display:none;"></div> <div class="counter-count" tutor-shot="counter" style="display:none;"></div>
...@@ -169,6 +196,8 @@ var tutorShotOid = null; ...@@ -169,6 +196,8 @@ var tutorShotOid = null;
` `
floatingBar.innerHTML = innerHTML floatingBar.innerHTML = innerHTML
floatingBar.style.pointerEvents = 'auto'
sr.append(floatingBar)
floatingBar.addEventListener('mouseenter', (e) => { floatingBar.addEventListener('mouseenter', (e) => {
floatingBar.style.width = '' floatingBar.style.width = ''
...@@ -180,6 +209,7 @@ var tutorShotOid = null; ...@@ -180,6 +209,7 @@ var tutorShotOid = null;
document.addEventListener("visibilitychange", async function () { document.addEventListener("visibilitychange", async function () {
if (document.visibilityState === 'visible') { if (document.visibilityState === 'visible') {
if (window.origin == origin) login()
let data = await getCaptureData() let data = await getCaptureData()
reRenderFloatingBar(data) reRenderFloatingBar(data)
} }
...@@ -210,44 +240,44 @@ async function getCaptureData() { ...@@ -210,44 +240,44 @@ async function getCaptureData() {
function reRenderFloatingBar(data) { function reRenderFloatingBar(data) {
if (data) { if (data) {
if (data.status == 'stopped') { if (data.status == 'stopped') {
floatingBar.remove() containerDiv.remove()
return return
} }
else if (!document.body.contains(floatingBar)) { else if (!document.body.contains(floatingBar)) {
document.body.append(floatingBar) document.body.append(containerDiv)
} }
} }
if (!btn.play) { if (!btn.play) {
btn.play = document.querySelector('[tutor-shot="play-btn"]') btn.play = sr.querySelector('[tutor-shot="play-btn"]')
btn.play.addEventListener('click', resumeRecording) btn.play.addEventListener('click', resumeRecording)
} }
if (!btn.mainLogo){ if (!btn.mainLogo) {
btn.mainLogo = document.querySelector('[tutor-shot="main-logo"]') btn.mainLogo = sr.querySelector('[tutor-shot="main-logo"]')
} }
if (!btn.generatingVideo){ if (!btn.generatingVideo) {
btn.generatingVideo = document.querySelector('[tutor-shot="generating-video"]') btn.generatingVideo = sr.querySelector('[tutor-shot="generating-video"]')
} }
if (!btn.capture) { if (!btn.capture) {
btn.capture = document.querySelector('[tutor-shot="capture-btn"]') btn.capture = sr.querySelector('[tutor-shot="capture-btn"]')
} }
if (!btn.playText) btn.playText = document.querySelector('[tutor-shot="play-text"]') if (!btn.playText) btn.playText = sr.querySelector('[tutor-shot="play-text"]')
if (!btn.pause) { if (!btn.pause) {
btn.pause = document.querySelector('[tutor-shot="pause-btn"]') btn.pause = sr.querySelector('[tutor-shot="pause-btn"]')
btn.pause.addEventListener('click', pauseRecording) btn.pause.addEventListener('click', pauseRecording)
} }
if (!btn.stop) { if (!btn.stop) {
btn.stop = document.querySelector('[tutor-shot="stop-btn"]') btn.stop = sr.querySelector('[tutor-shot="stop-btn"]')
btn.stop.addEventListener('click', stopRecording) btn.stop.addEventListener('click', stopRecording)
} }
if (!btn.restart) { if (!btn.restart) {
btn.restart = document.querySelector('[tutor-shot="restart-btn"]') btn.restart = sr.querySelector('[tutor-shot="restart-btn"]')
btn.restart.addEventListener('click', restartRecording) btn.restart.addEventListener('click', restartRecording)
} }
if (!btn.switch) { if (!btn.switch) {
btn.switch = document.querySelector('[tutor-shot="switch-btn"]') btn.switch = sr.querySelector('[tutor-shot="switch-btn"]')
btn.switch.addEventListener('click', changeBarPosition) btn.switch.addEventListener('click', changeBarPosition)
} }
if (!btn.counter) btn.counter = document.querySelector('[tutor-shot="counter"]') if (!btn.counter) btn.counter = sr.querySelector('[tutor-shot="counter"]')
if (data?.hasOwnProperty('imageNumber')) { if (data?.hasOwnProperty('imageNumber')) {
btn.counter.innerHTML = `${data.imageNumber}` btn.counter.innerHTML = `${data.imageNumber}`
...@@ -271,7 +301,7 @@ function reRenderFloatingBar(data) { ...@@ -271,7 +301,7 @@ function reRenderFloatingBar(data) {
btn.mainLogo.style.display = 'block' btn.mainLogo.style.display = 'block'
// btn.capture.style.display = 'flex' // btn.capture.style.display = 'flex'
} }
else if ( data?.status == 'generatingVideo' ){ else if (data?.status == 'generatingVideo') {
btn.play.style.display = 'none' btn.play.style.display = 'none'
btn.pause.style.display = 'none' btn.pause.style.display = 'none'
btn.stop.style.display = 'none' btn.stop.style.display = 'none'
...@@ -301,7 +331,7 @@ const api = axios.create({ ...@@ -301,7 +331,7 @@ const api = axios.create({
window.addEventListener('mousedown', async function (e) { window.addEventListener('mousedown', async function (e) {
// to prevent the event when clicking inside the floating bar // to prevent the event when clicking inside the floating bar
if (floatingBar?.contains(e.target) || startingOverlay?.contains(e.target)) { if (containerDiv?.contains(e.target) || startingOverlay?.contains(e.target)) {
return return
} }
if (e.button === 0) { // only left click allowed if (e.button === 0) { // only left click allowed
...@@ -341,7 +371,7 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon ...@@ -341,7 +371,7 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon
let counter = 5 let counter = 5
startingOverlay = document.createElement('div') startingOverlay = document.createElement('div')
startingOverlay.setAttribute('class', 'tutor-shot-overlay') startingOverlay.setAttribute('class', 'tutor-shot-overlay')
document.body.append(startingOverlay) sr.append(startingOverlay)
function changeText() { function changeText() {
if (counter <= 0) { if (counter <= 0) {
clearInterval(overlayInterval) clearInterval(overlayInterval)
......
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "Tutor Shot", "name": "Tutor Shot Local",
"version": "1.0", "version": "1.2",
"description": "Capture web-page screenshots instantly with a single click. They're saved to your account at http://localhost:3039.", "description": "Capture web-page screenshots instantly with a single click. They're saved to your account at http://localhost:3039.",
"permissions": [ "permissions": [
"activeTab", "activeTab",
......
...@@ -96,6 +96,7 @@ ...@@ -96,6 +96,7 @@
} }
// this code should run everytime the popup is opened // this code should run everytime the popup is opened
document.addEventListener("DOMContentLoaded", domLoadHandler); document.addEventListener("DOMContentLoaded", domLoadHandler);
console.log('pop-up loaded again')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment