Skip to content

Commit

Permalink
Add ability to close blank tab after redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed May 18, 2018
1 parent ab30f0c commit d79b3cd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"config_onlyMainFrame_label": { "message": "Only check URL which is shown in location bar" },
"config_forceielist_caption": { "message": "Websites to be opened by IE always" },
"config_disableForce_label": { "message": "Disable" },
"config_closeReloadPage_label": { "message": "Close blank tab left after redirection" },
"config_sitesOpenedBySelf_caption": { "message": "Exceptive websites (opened in Firefox directly)" },
"config_disableException_label": { "message": "Disable" },
"config_ignoreQueryString_label": { "message": "Ignore query string in URL" },
Expand Down
1 change: 1 addition & 0 deletions _locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"config_onlyMainFrame_label": { "message": "アドレスバーに表示されるURLのみを判定する" },
"config_forceielist_caption": { "message": "Internet Explorerで常に開くWebサイト" },
"config_disableForce_label": { "message": "無効化" },
"config_closeReloadPage_label": { "message": "リダイレクト後に残された空のタブを閉じる" },
"config_sitesOpenedBySelf_caption": { "message": "IEで開く対象から除外する(Firefoxで直接開く)サイト" },
"config_disableException_label": { "message": "無効化" },
"config_ignoreQueryString_label": { "message": "URLの?以降を無視する" },
Expand Down
19 changes: 19 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ function onBeforeRequest(aDetails) {
}
if (redirected) {
launch(aDetails.url);
if (configs.closeReloadPage &&
gOpeningTabs.has(aDetails.tabId)) {
gOpeningTabs.delete(aDetails.tabId);
browser.tabs.remove(aDetails.tabId);
}
}
else {
log('url is not redirected: ', aDetails.url);
Expand Down Expand Up @@ -193,6 +198,8 @@ function matchPatternToRegExp(pattern) {
return new RegExp(regex);
}

var gOpeningTabs = new Map();

(async () => {
await configs.$load();
await applyMCDConfigs();
Expand All @@ -212,6 +219,18 @@ function matchPatternToRegExp(pattern) {
setSitesOpenedBySelf();

configs.$addObserver(onConfigUpdated);


browser.tabs.onCreated.addListener(aTab => {
gOpeningTabs.set(aTab.id, true);
});
browser.tabs.onUpdated.addListener((aTabId, aChangeInfo, aTab) => {
if (aChangeInfo.status == 'complete' ||
(aChangeInfo.url &&
!/^(about:(blank|newtab|home))$/.test(aChangeInfo.url))) {
gOpeningTabs.delete(aTabId);
}
});
})();

async function applyMCDConfigs() {
Expand Down
1 change: 1 addition & 0 deletions common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ configs = new Configs({
ieargs : '',
forceielist : '',
disableForce : false,
closeReloadPage : true,
contextMenu : true,
onlyMainFrame : true,
ignoreQueryString : false,
Expand Down
7 changes: 7 additions & 0 deletions host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ type SendMCDConfigsResponse struct {
IEArgs string `json:"ieargs,omitempty"`
ForceIEList string `json:"forceielist,omitempty"`
DisableForce bool `json:"disableForce"`
CloseReloadPage bool `json:"closeReloadPage"`
ContextMenu bool `json:"contextMenu"`
OnlyMainFrame bool `json:"onlyMainFrame"`
SitesOpenedBySelf string `json:"sitesOpenedBySelf,omitempty"`
Expand Down Expand Up @@ -238,6 +239,12 @@ func SendMCDConfigs() {
} else {
LogForDebug("Failed to read extensions.ieview.disableForce.\n" + err.Error())
}
closeReloadPage, err := configs.GetBooleanValue("extensions.ieview.closeReloadPage")
if err == nil {
response.CloseReloadPage = closeReloadPage
} else {
LogForDebug("Failed to read extensions.ieview.closeReloadPage.\n" + err.Error())
}
sitesOpenedBySelf, err := configs.GetStringValue("extensions.ieview.sitesOpenedBySelf")
if err == nil {
response.SitesOpenedBySelf = sitesOpenedBySelf
Expand Down
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"contextMenus",
"nativeMessaging",
"storage",
"tabs",
"webRequest",
"webRequestBlocking",
"<all_urls>"
Expand Down
4 changes: 3 additions & 1 deletion options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<label><input id="ignoreQueryString"
type="checkbox">
__MSG_config_ignoreQueryString_label__</label></p>
<br />
<textarea id="forceielist"
rows="10"
cols="45"></textarea></div>
Expand All @@ -45,6 +44,9 @@
<textarea id="sitesOpenedBySelf"
rows="10"
cols="45"></textarea></div>
<p><label><input id="closeReloadPage"
type="checkbox">
__MSG_config_closeReloadPage_label__</label></p>
<hr>
<p><label><input id="logging"
type="checkbox">
Expand Down

0 comments on commit d79b3cd

Please sign in to comment.