import
This commit is contained in:
33
inject/sub-success-handler.js
Normal file
33
inject/sub-success-handler.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// Listen for subscription status updates from the webpage
|
||||
window.addEventListener(
|
||||
'message',
|
||||
function (event) {
|
||||
// Validate message structure and origin
|
||||
if (!event.data || typeof event.data !== 'object') return
|
||||
|
||||
const { type, text } = event.data
|
||||
|
||||
// Verify all required fields are present and valid
|
||||
if (
|
||||
type === 'FROM_PAGE' &&
|
||||
text?.type === 'subscription_status' &&
|
||||
text?.extensionId === chrome.runtime.id &&
|
||||
typeof text?.status === 'string'
|
||||
) {
|
||||
// Log the validated message
|
||||
console.log('Subscription status update received:', text.status)
|
||||
|
||||
chrome.storage.sync.set(
|
||||
{ dm_subscription_status: text.status.toLowerCase() },
|
||||
() => {
|
||||
console.log('Subscription status updated:', text.status)
|
||||
}
|
||||
)
|
||||
|
||||
if (text.status.toLowerCase() === 'active') {
|
||||
chrome.storage.sync.remove('dm_clicks_count', () => {})
|
||||
}
|
||||
}
|
||||
},
|
||||
false
|
||||
)
|
||||
Reference in New Issue
Block a user