Skip to content

Commit

Permalink
完善“跳过不发音标签”的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
tumuyan committed Sep 22, 2021
1 parent 09c52f1 commit c418e48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "__MSG_name__",
"short_name": "Auto Mute",
"author": "Tumuyan",
"version": "0.2",
"version": "0.2.1",
"update_url": "https://edge.microsoft.com/extensionwebstorebase/v1/crx",
"manifest_version": 2,
"minimum_chrome_version": "22.0",
Expand Down
13 changes: 13 additions & 0 deletions scripts/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var tabNow = -1;
var tabActive = -1;
var sw_on = true;

if (localStorage['sw_on'] == 'false')
Expand All @@ -11,6 +12,7 @@ if (localStorage['audible'] == 'false')
sw2(sw_audible);

chrome.tabs.onActivated.addListener(function (activeInfo) {
tabActive = activeInfo.tabId;
console.log("onSelectionChanged: tabid-> " + activeInfo.tabId + " sw_on="+sw_on);
if (!sw_on)
return;
Expand All @@ -22,6 +24,7 @@ chrome.tabs.onActivated.addListener(function (activeInfo) {
let muted = tab.active?false:true;
await chrome.tabs.update(tabId, { muted });

// 不智能跳过,或者智能跳过但是这个页面发音
if(!sw_audible || tab.audible){
if(tabNow != tabId){
await chrome.tabs.update(tabNow, { muted:true} );
Expand All @@ -37,6 +40,16 @@ chrome.tabs.onActivated.addListener(function (activeInfo) {

});


// 如果智能跳过,需要检查前台标签内容更新时自动发声
chrome.tabs.onUpdated.addListener(function (id, info, tab) {
if(sw_audible && id == tabActive && id!=tabNow && tab.audible){
chrome.tabs.update(id, { muted:false });
chrome.tabs.update(tabNow, { muted:true} );
tabNow = tabActive;
}
});

function sw(sw) {
sw_on = sw;
localStorage['sw_on'] = sw_on;
Expand Down

0 comments on commit c418e48

Please sign in to comment.