Skip to content

Commit

Permalink
Switch to optional permissions
Browse files Browse the repository at this point in the history
Cant request them on the preferences page and thus have to open preferences in a tab
Unfortunately SemanticUI CSS has a weird problem in the preferences tab
Part of #17
  • Loading branch information
stoically committed Feb 3, 2018
1 parent 47a7848 commit 82c1ade
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
9 changes: 6 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,25 @@
},

"options_ui": {
"page": "options/options.html"
"page": "options/options.html",
"open_in_tab": true
},

"permissions": [
"<all_urls>",
"contextMenus",
"contextualIdentities",
"cookies",
"history",
"management",
"storage",
"tabs",
"webRequest",
"webRequestBlocking"
],

"optional_permissions": [
"history"
],

"content_scripts": [
{
"matches": ["<all_urls>"],
Expand Down
33 changes: 30 additions & 3 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
<meta charset="utf-8">
<link rel="stylesheet" href="semantic/semantic.min.css">
<style>
body { padding: 5px; }
body { padding: 50px; }
.hidden { display: none; }
</style>
</head>

<body>
<div class="ui grid">
<div class="ui twelve wide column">
<div class="ui ten wide column">
<div class="ui pointing secondary menu">
<a class="item active" data-tab="general">General</a>
<a class="item" data-tab="mouseclicks">Mouse Clicks</a>
<a class="item" data-tab="alwaysopenin">Always per Website</a>
<a class="item" data-tab="advanced">Advanced</a>
</div>
<div class="ui bottom attached active tab segment" data-tab="general">
<div class="ui grid">
<div class="fourteen wide column">
<form class="ui form">
<div id="containerPreferences">
<div class="field" id="automaticModeField">
Expand Down Expand Up @@ -96,13 +98,17 @@
</div>
</div>
</form>
</div>
</div>
</div>
<div class="ui tab segment" data-tab="mouseclicks">
<div class="ui top attached tabular menu">
<a class="active item" data-tab="mouseclicks/global">Global</a>
<a class="item" data-tab="mouseclicks/perwebsite">Per Website</a>
</div>
<div class="ui bottom attached active tab segment" data-tab="mouseclicks/global">
<div class="ui grid">
<div class="fourteen wide column">
<form class="ui form">
<h4>When Mouse Clicks on Links should open new Temporary Containers</h4>
<div class="field">
Expand Down Expand Up @@ -154,8 +160,12 @@ <h4>When Mouse Clicks on Links should open new Temporary Containers</h4>
<button id="saveLinkClickGlobalPreferences" class="ui button primary">Save</button>
</div>
</form>
</div>
</div>
</div>
<div class="ui bottom attached tab segment" data-tab="mouseclicks/perwebsite">
<div class="ui grid">
<div class="fourteen wide column">
<form class="ui form" id="linkClickDomainForm">
<h4 data-tooltip="Website Rules overwrite Global Preferences">
On which Websites should Mouse Clicks on Links open new Temporary Containers [?]
Expand Down Expand Up @@ -218,9 +228,13 @@ <h3>Website Rules</h3>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="ui bottom attached tab segment" data-tab="alwaysopenin">
<div class="ui grid">
<div class="fourteen wide column">
<form class="ui form" id="alwaysOpenInDomainForm">
<h4 data-tooltip="Regardless how they're opened. Only if not already in a container.">
Which Websites should always open in new Temporary Containers [?]
Expand All @@ -238,16 +252,20 @@ <h3>Website Rules</h3>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="ui bottom attached tab segment" data-tab="advanced">
<div class="ui grid">
<div class="fourteen wide column">
<form class="ui form">
<div id="advancedPreferences">
<div class="field">
<label>Delete History</label>
<div class="ui negative message">
<strong>
WARNING: EVERY WEBSITE URL that you visit in a
"Deletes History Temporary Container" WILL GET DELETED FROM YOUR HISTORY.
"Deletes History Temporary Container" WILL GET DELETED FROM YOUR ENTIRE HISTORY.
This means if you visited a Website URL in another Container, Temporary Container
or in No Container before or while visiting it in a "Deletes History Temporary Container"
- those visits will get deleted from History too. This is true until Firefox supports a special History for Container Tabs.
Expand All @@ -259,6 +277,13 @@ <h3>Website Rules</h3>
<br>
Be careful. You have been warned. "Deletes History Temporary Containers" tabs have a "-deletes-history" suffix
in the container name to remind you.
<br><br>

<div class="ui checkbox" id="deletesHistoryContainerWarningRead">
<input type="checkbox" id="deletesHistoryContainerWarningReadCheckbox">
<label>I have read the WARNING and understand the implications that come with using "Deletes History Temporary Containers".
When ticking the checkbox Firefox will ask you for "Access browsing history" permissions, which you have to allow.</label>
</div>
</strong>
</div>
<select id="deletesHistoryContainer" class="ui fluid dropdown">
Expand All @@ -279,6 +304,8 @@ <h3>Website Rules</h3>
</div>
</div>
</form>
</div>
</div>
</div>
<div id="message" class="ui positive message hidden"></div>
</div>
Expand Down
23 changes: 23 additions & 0 deletions options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,32 @@ const initialize = async () => {
html: automaticModeToolTip,
inline: true
});

const historyPermission = await browser.permissions.contains({permissions: ['history']});
if (historyPermission) {
$('#deletesHistoryContainerWarningRead')
.checkbox('check')
.checkbox('set disabled');
}
};

document.addEventListener('DOMContentLoaded', initialize);
$('#saveContainerPreferences').on('click', saveContainerPreferences);
$('#saveAdvancedPreferences').on('click', saveAdvancedPreferences);
$('#saveLinkClickGlobalPreferences').on('click', saveLinkClickGlobalPreferences);


const requestHistoryPermissions = async () => {
const allowed = await browser.permissions.request({
permissions: ['history']
});
if (!allowed) {
$('#deletesHistoryContainerWarningRead')
.checkbox('uncheck');
} else {
$('#deletesHistoryContainerWarningRead')
.checkbox('check')
.checkbox('set disabled');
}
};
$('#deletesHistoryContainerWarningRead').on('click', requestHistoryPermissions);
2 changes: 1 addition & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ class TemporaryContainers extends Emittery {

case 'new_no_history_tab':
this.container.createTabInTempContainer({deletesHistory: true});
break;
}
}


async addContextMenu() {
browser.contextMenus.create({
id: 'open-link-in-new-temporary-container-tab',
Expand Down
1 change: 0 additions & 1 deletion src/background/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class Container {


async reloadTabInTempContainer(tab, url, active, deletesHistory) {
console.log('??', deletesHistory)
const newTab = await this.createTabInTempContainer({tab, url, active, deletesHistory});
if (!tab) {
return newTab;
Expand Down

0 comments on commit 82c1ade

Please sign in to comment.