Skip to content

Commit d462658

Browse files
committed
work on check video on page
1 parent 9c04088 commit d462658

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/background.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function backgroundCheck() {
3737
if (tab !== undefined) {
3838
activity.setCurrentActiveTab(tab.url);
3939
chrome.idle.queryState(parseInt(setting_interval_inactivity), function (state) {
40-
if (state === 'active') {
40+
if (state === 'active' || (state === 'idle' && checkDOM())) {
4141
if (activity.isLimitExceeded(activeUrl, tab)) {
4242
setBlockPageToCurrent(activeUrl);
4343
}
@@ -89,6 +89,21 @@ function setBlockPageToCurrent(activeUrl) {
8989
});
9090
}
9191

92+
function isVideoPlayedOnPage() {
93+
var videoElement = document.getElementsByTagName('video')[0];
94+
if (videoElement !== undefined && videoElement.currentTime > 0 && !videoElement.paused && !videoElement.ended && videoElement.readyState > 2)
95+
return true;
96+
}
97+
98+
function checkDOM(){
99+
chrome.tabs.executeScript({
100+
code: '(' + isVideoPlayedOnPage + ')();'
101+
}, (results) => {
102+
if (results !== undefined && results !== null && results[0] !== undefined)
103+
return results[0];
104+
});
105+
}
106+
92107
function backgroundUpdateStorage() {
93108
if (tabs != undefined && tabs.length > 0)
94109
storage.saveTabs(tabs);

0 commit comments

Comments
 (0)