Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 38 additions & 36 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,44 +326,46 @@ browser.tabs.onActivated.addListener( function( active ) {
browser.tabs.onUpdated.addListener( function( tabId, changeInfo, tab ) {
watch.Pull( tabId );
if ( changeInfo.status == "complete" ) {
console.log( "background tabs Listener:update", tabId, changeInfo, tab );
browser.tabs.get(tabId, tab => {
console.log( "background tabs Listener:update", tabId, changeInfo, tab );

if ( tab.url.startsWith( "http://ksria.com/simpread/auth.html" )) {
const url = tab.url.replace( "http://ksria.com/simpread/auth.html?id=", "" ),
id = url.includes( "#" ) || url.includes( "&" ) ? url.substr( 0, url.search( /\S(#|&)/ ) + 1 ) : url ;
browser.tabs.query( {}, tabs => {
const opts = tabs.find( tab => tab.url.includes( browser.extension.getURL( "options/options.html" ) ));
if ( opts ) {
browser.tabs.sendMessage( opts.id, msg.Add( msg.MESSAGE_ACTION.redirect_uri, { uri: tab.url, id } ));
browser.tabs.remove( tabId );
}
});
} else if ( tab.url.startsWith( "https://simpread.ksria.cn/plugins/install/" )) {
const url = tab.url.replace( "https://simpread.ksria.cn/plugins/install/", "" );
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#plugins?install=" + encodeURIComponent(url) ) });
browser.tabs.remove( tabId );
} else if ( tab.url.startsWith( "https://simpread.ksria.cn/sites/install/" )) {
const url = tab.url.replace( "https://simpread.ksria.cn/sites/install/", "" );
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#sites?install=" + encodeURIComponent(url) ) });
browser.tabs.remove( tabId );
} else if ( tab.url == browser.runtime.getURL( "options/options.html#sites?update=success" ) ) {
browser.tabs.remove( tabId );
upTabId > 0 && chrome.tabs.reload( upTabId, () => { upTabId == -1; });
} else if ( tab.url == browser.runtime.getURL( "options/options.html#sites?update=failed" ) ) {
browser.tabs.remove( tabId );
} else if ( tab.url == browser.runtime.getURL( "options/options.html#sites?update=complete" ) ) {
browser.tabs.remove( tabId );
} else if ( tab.url == browser.runtime.getURL( "options/options.html#sites?update=pending" ) ) {
browser.tabs.remove( tabId );
upTabId > 0 && browser.tabs.sendMessage( upTabId, msg.Add( msg.MESSAGE_ACTION.pending_site ));
upTabId == -1;
}
if ( tab.url.startsWith( "http://ksria.com/simpread/auth.html" )) {
const url = tab.url.replace( "http://ksria.com/simpread/auth.html?id=", "" ),
id = url.includes( "#" ) || url.includes( "&" ) ? url.substr( 0, url.search( /\S(#|&)/ ) + 1 ) : url ;
browser.tabs.query( {}, tabs => {
const opts = tabs.find( tab => tab.url.includes( browser.extension.getURL( "options/options.html" ) ));
if ( opts ) {
browser.tabs.sendMessage( opts.id, msg.Add( msg.MESSAGE_ACTION.redirect_uri, { uri: tab.url, id } ));
browser.tabs.remove( tabId );
}
});
} else if ( tab.url.startsWith( "https://simpread.ksria.cn/plugins/install/" )) {
const url = tab.url.replace( "https://simpread.ksria.cn/plugins/install/", "" );
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#plugins?install=" + encodeURIComponent(url) ) });
browser.tabs.remove( tabId );
} else if ( tab.url.startsWith( "https://simpread.ksria.cn/sites/install/" )) {
const url = tab.url.replace( "https://simpread.ksria.cn/sites/install/", "" );
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#sites?install=" + encodeURIComponent(url) ) });
browser.tabs.remove( tabId );
} else if ( tab.url == browser.runtime.getURL( "options/options.html#sites?update=success" ) ) {
browser.tabs.remove( tabId );
upTabId > 0 && chrome.tabs.reload( upTabId, () => { upTabId == -1; });
} else if ( tab.url == browser.runtime.getURL( "options/options.html#sites?update=failed" ) ) {
browser.tabs.remove( tabId );
} else if ( tab.url == browser.runtime.getURL( "options/options.html#sites?update=complete" ) ) {
browser.tabs.remove( tabId );
} else if ( tab.url == browser.runtime.getURL( "options/options.html#sites?update=pending" ) ) {
browser.tabs.remove( tabId );
upTabId > 0 && browser.tabs.sendMessage( upTabId, msg.Add( msg.MESSAGE_ACTION.pending_site ));
upTabId == -1;
}

if ( !tab.url.startsWith( "chrome://" ) ) {
browser.tabs.sendMessage( tabId, msg.Add( msg.MESSAGE_ACTION.tab_selected, { is_update: true } ));
} else {
setMenuAndIcon( tab.id, -1 );
}
if ( !tab.url.startsWith( "chrome://" ) ) {
browser.tabs.sendMessage( tabId, msg.Add( msg.MESSAGE_ACTION.tab_selected, { is_update: true } ));
} else {
setMenuAndIcon( tab.id, -1 );
}
});
}
});

Expand Down