Skip to content

Commit

Permalink
Save options automatically (without button press), wording changes, a…
Browse files Browse the repository at this point in the history
…nd indentation changes.
  • Loading branch information
aghorler committed May 8, 2018
1 parent 993639e commit cf1d5fd
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 113 deletions.
8 changes: 4 additions & 4 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
The permissions History Disabler requires on install are declared in the manifest.

"permissions": [
"browsingData",
"history",
"downloads",
"storage"
"browsingData",
"history",
"downloads",
"storage"
]

Each permission is required for the reasons set out below.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## History Disabler for Chromium
**Version 1.5.2 | June 18 2017**
**Version 1.6 | May 8 2018**

Uses different methods to effectively disable browsing history in Chrome (and other Chromium) browsers.

Expand Down
58 changes: 26 additions & 32 deletions html/options.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<title>History Disabler</title>
</head>
<body>
<h3>Advanced options</h3>
<head>
<title>History Disabler</title>
</head>
<body>
<h3>Advanced options</h3>

<p>
<label>
<input type="checkbox" id="download_option"> Disable download history.
<br>
<i style="color:red">Enabling this setting will have the browser forget a download as soon as the download is completed, or interrupted.</i>
</label>
</p>
<p>
<label>
<input type="checkbox" id="download_option" style="top: -2px;">
<label for="download_option">Disable download history.</label>
<br>
<p style="color:red">Enabling this setting will cause the browser to forget a download as soon as the download is completed, or interrupted.</p>
</label>
</p>

<p>
<label>
<input type="checkbox" id="tabs_option"> Retain 'Recently closed' tabs.
<br>
<i style="color:red">Enabling this setting will cause History Disabler not to clear the list of 'Recently closed' tabs for the session. This will enable, for example, the Ctrl-Shift-T keyboard shortcut to open recently closed tabs.</i>
</label>
</p>
<p style="margin-top: 20px;">
<label>
<input type="checkbox" id="tabs_option" style="top: -2px;">
<label for="tabs_option">Retain 'Recently closed' tabs.</label>
<br>
<p style="color:red">Enabling this setting will prevent clearing 'Recently closed' tabs for the session. This will enable, for example, the Ctrl-Shift-T keyboard shortcut to open recently closed tabs.</p>
</label>
</p>

<p>
<span>
<button id="save">Apply settings</button>
</span>
<p align="center" style="color:grey">
Developed by <a href="https://aaronhorler.com">Aaron Horler</a> (aghorler) | <a href="https://github.com/aghorler/History-Disabler-for-Chromium">GitHub source</a>
</p>

<span id="status"></span>
</p>

<p align="center" style="color:grey">
Developed by Aaron Horler (aghorler) | <a href="https://github.com/aghorler/History-Disabler-for-Chromium">GitHub source</a>
</p>

<script src="/js/options.js"></script>
</body>
<script src="/js/options.js"></script>
</body>
</html>
74 changes: 37 additions & 37 deletions js/background.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
/* Function to clear all browsing history using the BrowsingData API. */
/* Function to clear all browsing history using the BrowsingData API. */
function clearBrowsingData(){
chrome.browsingData.removeHistory({
"originTypes": {
"protectedWeb": true,
"unprotectedWeb": true,
"extension": true
}
});
chrome.browsingData.removeHistory({
"originTypes": {
"protectedWeb": true,
"unprotectedWeb": true,
"extension": true
}
});
}

/* Function to clear a specific item from history using the History API. */
/* Function to clear a specific item from history using the History API. */
function clearHistory(historyItem){
chrome.history.deleteUrl({
"url": historyItem
});
chrome.history.deleteUrl({
"url": historyItem
});
}

/* Function to erase an item from download history using the Downloads API. */
/* Function to erase an item from download history using the Downloads API. */
function eraseDownload(downloadItem){
if(typeof downloadItem.state !== 'undefined'){
if(downloadItem.state.current === 'complete' || downloadItem.state.current === 'interrupted'){
chrome.downloads.erase({
limit: 1,
id: downloadItem.id
});
}
}
if(typeof downloadItem.state !== 'undefined'){
if(downloadItem.state.current === 'complete' || downloadItem.state.current === 'interrupted'){
chrome.downloads.erase({
limit: 1,
id: downloadItem.id
});
}
}
}

/* Call clearHistory when a website is added to history. */
/* Call clearHistory when a website is added to history. */
chrome.history.onVisited.addListener(function(historyItem){
clearHistory(historyItem.url);
clearHistory(historyItem.url);
});

/* Call clearBrowsingData on tab close, if retain option is not enabled.
This clears any browsing history listed in 'Recently closed' tabs. */
/* Call clearBrowsingData on tab close, if retain option is not enabled.
This clears any browsing history listed in 'Recently closed' tabs. */
chrome.tabs.onRemoved.addListener(function(){
chrome.storage.local.get('retainTabs', function(option){
if(!option.retainTabs){
clearBrowsingData();
}
});
chrome.storage.local.get('retainTabs', function(option){
if(!option.retainTabs){
clearBrowsingData();
}
});
});

/* Call eraseDownload on download completion, if clear option is enabled. */
/* Call eraseDownload on download completion, if clear option is enabled. */
chrome.downloads.onChanged.addListener(function(downloadItem){
chrome.storage.local.get('clearDownloads', function(option){
if(option.clearDownloads){
eraseDownload(downloadItem);
}
});
chrome.storage.local.get('clearDownloads', function(option){
if(option.clearDownloads){
eraseDownload(downloadItem);
}
});
});

/* Call clearBrowsingData on browser start, and extension install. */
/* Call clearBrowsingData on browser start, and extension install. */
clearBrowsingData();
36 changes: 15 additions & 21 deletions js/options.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
function saveOptions(){
var downloadOption = document.getElementById('download_option').checked;
var tabsOption = document.getElementById('tabs_option').checked;
chrome.storage.local.set({
clearDownloads: downloadOption,
retainTabs: tabsOption
}, function(){
var status = document.getElementById('status');
status.textContent = 'Options saved.';
status.style.color = "green";
setTimeout(function(){
status.textContent = '';
}, 750);
});
var downloadOption = document.getElementById('download_option').checked;
var tabsOption = document.getElementById('tabs_option').checked;
chrome.storage.local.set({
clearDownloads: downloadOption,
retainTabs: tabsOption
});
}

function restoreOptions(){
chrome.storage.local.get({
clearDownloads: false,
retainTabs: false
}, function(items){
document.getElementById('download_option').checked = items.clearDownloads;
document.getElementById('tabs_option').checked = items.retainTabs;
});
chrome.storage.local.get({
clearDownloads: false,
retainTabs: false
}, function(items){
document.getElementById('download_option').checked = items.clearDownloads;
document.getElementById('tabs_option').checked = items.retainTabs;
});
}

document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);
document.getElementById('download_option').addEventListener('change', saveOptions);
document.getElementById('tabs_option').addEventListener('change', saveOptions);
36 changes: 18 additions & 18 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "History Disabler",
"version": "1.5.2",
"manifest_version": 2,
"description": "Disable history in Chrome.",
"background": {
"scripts": ["/js/background.js"],
"persistent": false
},
"icons": {
"128": "/img/icon128.png"
},
"options_ui": {
"name": "History Disabler",
"version": "1.6",
"manifest_version": 2,
"description": "Disable history in Chrome.",
"background": {
"scripts": ["/js/background.js"],
"persistent": false
},
"icons": {
"128": "/img/icon128.png"
},
"options_ui": {
"page": "/html/options.html",
"chrome_style": true,
"open_in_tab": false
},
"permissions": [
"browsingData",
"history",
"downloads",
"storage"
]
"permissions": [
"browsingData",
"history",
"downloads",
"storage"
]
}

0 comments on commit cf1d5fd

Please sign in to comment.