Skip to content

Commit 5399dfc

Browse files
committed
Release version 2.7
Disable history processor in firefox Various bug fixes and optimizations
1 parent fe6baf3 commit 5399dfc

7 files changed

+46
-43
lines changed

background.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
* Background JS
1313
*/
1414

15-
let isChrome = typeof browser === "undefined";
16-
1715
//Check if a tab should have it's history killed by checking it's HTML
1816
function killHistory(tab) {
1917
//Check if tab is undefined
@@ -164,13 +162,11 @@ function markPage(tab) {
164162
chrome.tabs.insertCSS(tab.id, cssObj);
165163
};
166164

167-
//Firefox uses promises, chrome uses callback
168165
if(isChrome) {
169166
//Not yet implemented: https://bugs.chromium.org/p/chromium/issues/detail?id=608854
170-
//chrome.tabs.removeCSS(tab.id, cssObj, afterRemove);
171167
afterRemove();
172168
} else {
173-
chrome.tabs.removeCSS(tab.id, cssObj).then(afterRemove, afterRemove);
169+
chrome.tabs.removeCSS(tab.id, cssObj, afterRemove);
174170
}
175171
}
176172
if(opt.injectJs) {
@@ -364,6 +360,9 @@ chrome.runtime.onMessage.addListener(function(request, sender) {
364360

365361
function updatePopup() {
366362
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
363+
//No active tab!
364+
if(tabs.length <= 0) return;
365+
367366
let entry = tabMap[tabs[0].id];
368367

369368
if(entry != null)
@@ -433,6 +432,10 @@ window.addEventListener('message', function(event) {
433432

434433
let sandboxIframe = null;
435434
function triggerHistoryProcessor(item) {
435+
//Do not execute empty history processor
436+
if(historyProcessor.trim().length <= 0)
437+
return;
438+
436439
if(sandboxIframe == null)
437440
sandboxIframe = document.getElementById("sandbox");
438441

@@ -476,9 +479,3 @@ if(localStorage.getItem('install_time') == null)
476479
if(items.installTime === -1)
477480
installNotice();
478481
});
479-
480-
//Open options page onclick
481-
/*chrome.browserAction.onClicked.addListener(function(tab) {
482-
chrome.runtime.openOptionsPage();
483-
});*/
484-

history_processor_sandbox.html

+1-22
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
11
<html>
22
<head>
3-
<script>
4-
window.addEventListener('message', function(event) {
5-
try {
6-
let item = event.data.apiItem;
7-
8-
//Add API functions
9-
item.removalQueued = false;
10-
item.remove = function() {
11-
item.removalQueued = true;
12-
};
13-
14-
eval(event.data.code);
15-
16-
//Clear API functions
17-
item.remove = null;
18-
19-
event.source.postMessage(event.data, event.origin);
20-
} catch(e) {
21-
console.error("Could not run history processor!", e);
22-
}
23-
});
24-
</script>
3+
<script src="history_processor_sandbox.js"></script>
254
</head>
265
</html>

history_processor_sandbox.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
window.addEventListener('message', function(event) {
2+
try {
3+
let item = event.data.apiItem;
4+
5+
//Add API functions
6+
item.removalQueued = false;
7+
item.remove = function() {
8+
item.removalQueued = true;
9+
};
10+
11+
eval(event.data.code);
12+
13+
//Clear API functions
14+
item.remove = null;
15+
16+
event.source.postMessage(event.data, event.origin);
17+
} catch(e) {
18+
console.error("Could not run history processor!", e);
19+
}
20+
});

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"short_name": "DynamicHistory",
1010
"author": "nulldev",
1111
"description": "Automagically delete history based on the keywords on the page!",
12-
"version": "2.6",
12+
"version": "2.7",
1313
"options_ui": {
1414
"page": "options.html",
1515
"chrome_style": true,

options.html

+10-8
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,20 @@ <h3>Badge color:</h3>
161161
The color of the badge to show if "Show Badge" is enabled:<br />
162162
<input id="badge_color" type="color" style="width: 100px"><br /><br />
163163
<h3>CSS code:</h3>
164-
The CSS to be injected if "Inject CSS" is enabled:
164+
The CSS to be injected if "Inject CSS" is enabled:<br />
165165
<textarea id="css_code" rows="5" data-placeholder="Example:\n\nbody {\n filter: grayscale(100%);\n}"></textarea><br /><br />
166166
<h3>JavaScript code:</h3>
167-
The JavaScript to be injected if "Inject JavaScript" is enabled:
167+
The JavaScript to be injected if "Inject JavaScript" is enabled:<br />
168168
<textarea id="js_code" rows="5" data-placeholder="Example:\n\nalert(&quot;History removed!&quot;);"></textarea><br /><br />
169169

170-
<h2>Advanced</h2>
171-
<h3>Custom history processor:</h3>
172-
Run a custom JavaScript function to modify history items as they are added to the history database.<br><br><b>Be careful when writing your own history processors</b>, as history processors are run continuously on a history entry until an iteration is reached where the entry is not modified by the history processor. When in doubt, open the console for the background page to monitor your history processor's activities so it doesn't end up in an infinite loop.<br />
173-
<textarea id="history_processor" rows="10" cols="50" data-placeholder="Example:\n\n//Pretend that all the sites we visit are secure\nif(item.url.startsWith(&quot;http&quot;) && !item.url.startsWith(&quot;https&quot;))\n item.url = item.url.replace('http', 'https');\n\n//Remove all FTP sites\nif(item.url.startsWith(&quot;ftp&quot;)\n item.remove();"></textarea><br /><br />
174-
<h3>History processor templates:</h3>
175-
<div id="hp_templates">
170+
<div id="custom_hist_proc">
171+
<h2>Advanced</h2>
172+
<h3>Custom history processor:</h3>
173+
Run a custom JavaScript function to modify history items as they are added to the history database.<br><br><b>Be careful when writing your own history processors</b>, as history processors are run continuously on a history entry until an iteration is reached where the entry is not modified by the history processor. When in doubt, open the console for the background page to monitor your history processor's activities so it doesn't end up in an infinite loop.<br />
174+
<textarea id="history_processor" rows="10" cols="50" data-placeholder="Example:\n\n//Pretend that all the sites we visit are secure\nif(item.url.startsWith(&quot;http&quot;) && !item.url.startsWith(&quot;https&quot;))\n item.url = item.url.replace('http', 'https');\n\n//Remove all FTP sites\nif(item.url.startsWith(&quot;ftp&quot;)\n item.remove();"></textarea><br /><br />
175+
<h3>History processor templates:</h3>
176+
<div id="hp_templates">
177+
</div>
176178
</div>
177179

178180
<h2>Useful actions</h2>

options.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ jQuery(document).ready(function () {
243243
bindHpTemplates();
244244

245245
//Show oninstall link if chrome
246-
if (typeof browser === "undefined")
246+
if (isChrome)
247247
$("#oninstall_link").show();
248248

249249
//Load initial settings
@@ -267,6 +267,9 @@ jQuery(document).ready(function () {
267267
readBackup(fileInput);
268268
});
269269

270+
//Disable history processor on firefix (no eval)
271+
if(!isChrome)
272+
$("#custom_hist_proc").hide();
270273
});
271274

272275
function readBackup(element) {

shared.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* Shared JS
1313
*/
1414

15+
let isChrome = typeof browser === "undefined";
16+
1517
function DEFAULT_OPTIONS() {
1618
return {
1719
dangerDomains: '',

0 commit comments

Comments
 (0)