Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add currentTab options #61

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/assets/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@
"description": "Value of the option."
},

"optionTitle_onlyCurrentTab": {
"message": "Only current tab",
"description": "Title of the option."
},

"optionTitle_clearSince": {
"message": "Time range",
"description": "Title of the option."
Expand Down Expand Up @@ -509,6 +514,11 @@
"description": "Tooltip of the button."
},

"buttonTooltip_onlyCurrentTab": {
"message": "Only current tab",
"description": "Tooltip of the button."
},

"buttonTooltip_contribute": {
"message": "Contribute",
"description": "Tooltip of the button."
Expand Down
2 changes: 1 addition & 1 deletion src/assets/manifest/chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

"minimum_chrome_version": "123.0",

"permissions": ["browsingData", "notifications", "storage"],
"permissions": ["browsingData", "notifications", "storage", "tabs"],

"content_security_policy": {
"extension_pages": "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src * data:; connect-src *; object-src 'none'; media-src 'none'; child-src 'none'; form-action 'none';"
Expand Down
2 changes: 1 addition & 1 deletion src/assets/manifest/edge.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

"minimum_chrome_version": "123.0",

"permissions": ["browsingData", "notifications", "storage"],
"permissions": ["browsingData", "notifications", "storage", "tabs"],

"content_security_policy": "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src * data:; connect-src *; object-src 'none'; media-src 'none'; child-src 'none'; form-action 'none';",

Expand Down
2 changes: 1 addition & 1 deletion src/assets/manifest/firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},

"permissions": ["browsingData", "notifications", "storage"],
"permissions": ["browsingData", "notifications", "storage", "tabs"],

"content_security_policy": "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src * data:; connect-src *; object-src 'none'; media-src 'none'; child-src 'none'; form-action 'none'; upgrade-insecure-requests;",

Expand Down
2 changes: 1 addition & 1 deletion src/assets/manifest/opera.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

"minimum_opera_version": "109.0",

"permissions": ["browsingData", "notifications", "storage"],
"permissions": ["browsingData", "notifications", "storage", "tabs"],

"content_security_policy": "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src * data:; connect-src *; object-src 'none'; media-src 'none'; child-src 'none'; form-action 'none';",

Expand Down
17 changes: 14 additions & 3 deletions src/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ async function clearDataType(dataType, options = null, enDataTypes = null) {
options = await storage.get(optionKeys);
}

await processAppUse({showContribPage: options.closeTabs !== 'exit'});
const {id: activeTabId, url: activeTabUrl} = await getActiveTab();

let removeOptions = {};
if (options.onlyCurrentTab) {
const hostname = new URL(activeTabUrl).hostname;
removeOptions.hostnames = [hostname];
}

let since;
if (options.clearSince === 'epoch') {
Expand Down Expand Up @@ -88,7 +94,6 @@ async function clearDataType(dataType, options = null, enDataTypes = null) {
}

let tempTabId;
const {id: activeTabId} = await getActiveTab();
const android = await isAndroid();

if (options.closeTabs !== 'false') {
Expand Down Expand Up @@ -170,7 +175,13 @@ async function clearDataType(dataType, options = null, enDataTypes = null) {
delete dataTypes.localStorage;
}
if (Object.keys(dataTypes).length) {
await browser.browsingData.remove({since}, dataTypes);
await browser.browsingData.remove({
...removeOptions,
since: since
}, dataTypes);

// 重新加载当前标签页
await browser.tabs.reload(activeTabId, {bypassCache: true});
}
} catch (err) {
await showNotification({
Expand Down
7 changes: 7 additions & 0 deletions src/options/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
v-model="options.confirmDataRemoval"
></vn-switch>
</div>
<div class="option">
<vn-switch
:label="getText('optionTitle_onlyCurrentTab')"
v-model="options.onlyCurrentTab"
></vn-switch>
</div>
<div class="option" v-if="enableContributions">
<vn-switch
:label="getText('optionTitle_showContribPage')"
Expand Down Expand Up @@ -217,6 +223,7 @@ export default {
notifyOnSuccess: false,
showDataTypeIcons: false,
confirmDataRemoval: false,
onlyCurrentTab: false,
appTheme: false,
showContribPage: false
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const optionKeys = [
'disabledDataTypes',
'clearAllDataTypesAction',
'clearSince',
'onlyCurrentTab',
'closeTabs',
'closePinnedTabs',
'reloadTabs',
Expand Down
Loading