forked from johnmave126/better-history
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cedab3e
commit 8d32896
Showing
21 changed files
with
1,083 additions
and
1,369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,22 @@ | ||
(function() { | ||
var BrowserActions = function(options) { | ||
if(!options.chrome) { | ||
throw("Chrome API not set"); | ||
} | ||
if(!options.tracker) { | ||
throw("Tracker not set"); | ||
} | ||
var BrowserActions = function(options) { | ||
if (!options.chrome) { | ||
throw ("Chrome API not set"); | ||
} | ||
|
||
this.chromeAPI = options.chrome; | ||
this.tracker = options.tracker; | ||
}; | ||
this.chromeAPI = options.chrome; | ||
}; | ||
|
||
BrowserActions.prototype.listen = function() { | ||
var _this = this; | ||
if(this.chromeAPI.browserAction) { | ||
this.chromeAPI.browserAction.onClicked.addListener(function() { | ||
_this.openHistory(); | ||
}); | ||
} | ||
}; | ||
BrowserActions.prototype.listen = function() { | ||
var _this = this; | ||
if (this.chromeAPI.browserAction) { | ||
this.chromeAPI.browserAction.onClicked.addListener( | ||
function() { _this.openHistory(); }); | ||
} | ||
}; | ||
|
||
BrowserActions.prototype.openHistory = function() { | ||
this.tracker.browserActionClick(); | ||
this.chromeAPI.tabs.create({url: 'chrome://history'}); | ||
}; | ||
BrowserActions.prototype.openHistory = | ||
function() { this.chromeAPI.tabs.create({url : 'chrome://history'}); }; | ||
|
||
BH.Chrome.BrowserActions = BrowserActions; | ||
BH.Chrome.BrowserActions = BrowserActions; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,39 @@ | ||
(function() { | ||
var Omnibox = function(options) { | ||
if(!options.chrome) { | ||
throw("Chrome API not set"); | ||
} | ||
if(!options.tracker) { | ||
throw("Tracker not set"); | ||
} | ||
var Omnibox = function(options) { | ||
if (!options.chrome) { | ||
throw ("Chrome API not set"); | ||
} | ||
|
||
this.chromeAPI = options.chrome; | ||
this.tracker = options.tracker; | ||
}; | ||
this.chromeAPI = options.chrome; | ||
}; | ||
|
||
Omnibox.prototype.listen = function() { | ||
if(this.chromeAPI.omnibox) { | ||
var _this = this; | ||
this.chromeAPI.omnibox.onInputChanged.addListener(function(text, suggest) { | ||
_this.setDefaultSuggestion(text); | ||
}); | ||
Omnibox.prototype.listen = function() { | ||
if (this.chromeAPI.omnibox) { | ||
var _this = this; | ||
this.chromeAPI.omnibox.onInputChanged.addListener(function( | ||
text, suggest) { _this.setDefaultSuggestion(text); }); | ||
|
||
this.chromeAPI.omnibox.onInputEntered.addListener(function(text) { | ||
_this.tracker.omniboxSearch(); | ||
_this.getActiveTab(function(tabId) { | ||
_this.updateTabURL(tabId, text); | ||
}); | ||
}); | ||
} | ||
}; | ||
this.chromeAPI.omnibox.onInputEntered.addListener(function(text) { | ||
_this.getActiveTab(function(tabId) { _this.updateTabURL(tabId, text); }); | ||
}); | ||
} | ||
}; | ||
|
||
Omnibox.prototype.setDefaultSuggestion = function(text) { | ||
if(this.chromeAPI.omnibox) { | ||
this.chromeAPI.omnibox.setDefaultSuggestion({ | ||
description: "Search <match>" + text + "</match> in history" | ||
}); | ||
} | ||
}; | ||
Omnibox.prototype.setDefaultSuggestion = function(text) { | ||
if (this.chromeAPI.omnibox) { | ||
this.chromeAPI.omnibox.setDefaultSuggestion( | ||
{description : "Search <match>" + text + "</match> in history"}); | ||
} | ||
}; | ||
|
||
Omnibox.prototype.getActiveTab = function(callback) { | ||
this.chromeAPI.tabs.query({active: true, currentWindow: true}, function(tabs) { | ||
callback(tabs[0].id); | ||
}); | ||
}; | ||
Omnibox.prototype.getActiveTab = function(callback) { | ||
this.chromeAPI.tabs.query({active : true, currentWindow : true}, | ||
function(tabs) { callback(tabs[0].id); }); | ||
}; | ||
|
||
Omnibox.prototype.updateTabURL = function(tabId, text) { | ||
this.chromeAPI.tabs.update(tabId, { | ||
url: "chrome://history/#search/" + text | ||
}); | ||
}; | ||
Omnibox.prototype.updateTabURL = function(tabId, text) { | ||
this.chromeAPI.tabs.update(tabId, {url : "chrome://history/#search/" + text}); | ||
}; | ||
|
||
BH.Chrome.Omnibox = Omnibox; | ||
BH.Chrome.Omnibox = Omnibox; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,97 @@ | ||
(function() { | ||
var getDomain = function(url) { | ||
var match = url.match(/\w+:\/\/(.*?)\//); | ||
if(match) { | ||
return match[1].replace('www.', ''); | ||
var getDomain = function(url) { | ||
var match = url.match(/\w+:\/\/(.*?)\//); | ||
if (match) { | ||
return match[1].replace('www.', ''); | ||
} | ||
return false; | ||
}; | ||
|
||
var PageContextMenu = function(options) { | ||
if (!options.chrome) { | ||
throw ("Chrome API not set"); | ||
} | ||
|
||
this.chromeAPI = options.chrome; | ||
|
||
this.id = 'better_history_page_context_menu'; | ||
}; | ||
|
||
PageContextMenu.prototype.create = function() { | ||
this.menu = this.chromeAPI.contextMenus.create({ | ||
title : this.chromeAPI.i18n.getMessage('visits_to_domain', [ 'domain' ]), | ||
contexts : [ 'page' ], | ||
id : this.id | ||
}); | ||
|
||
var _this = this; | ||
this.chromeAPI.contextMenus.onClicked.addListener(function( | ||
data) { _this.onClick(data); }); | ||
}; | ||
|
||
PageContextMenu.prototype.onClick = function(data) { | ||
if (data.menuItemId === this.id) { | ||
var domain = getDomain(data.pageUrl); | ||
|
||
url = "chrome://history/#search"; | ||
if (domain) { | ||
url += '/' + domain; | ||
} | ||
return false; | ||
}; | ||
|
||
var PageContextMenu = function(options) { | ||
if(!options.chrome) { | ||
throw("Chrome API not set"); | ||
} | ||
if(!options.tracker) { | ||
throw("Tracker not set"); | ||
} | ||
|
||
this.chromeAPI = options.chrome; | ||
this.tracker = options.tracker; | ||
|
||
this.id = 'better_history_page_context_menu'; | ||
}; | ||
|
||
PageContextMenu.prototype.create = function() { | ||
this.menu = this.chromeAPI.contextMenus.create({ | ||
title: this.chromeAPI.i18n.getMessage('visits_to_domain', ['domain']), | ||
contexts: ['page'], | ||
id: this.id | ||
}); | ||
|
||
var _this = this; | ||
this.chromeAPI.contextMenus.onClicked.addListener(function(data) { | ||
_this.onClick(data); | ||
}); | ||
}; | ||
|
||
PageContextMenu.prototype.onClick = function(data) { | ||
if(data.menuItemId === this.id) { | ||
var domain = getDomain(data.pageUrl); | ||
|
||
url = "chrome://history/#search"; | ||
if(domain) { | ||
url += '/' + domain; | ||
} | ||
|
||
this.tracker.contextMenuClick(); | ||
|
||
this.chromeAPI.tabs.create({url: url}); | ||
this.chromeAPI.tabs.create({url : url}); | ||
} | ||
}; | ||
|
||
PageContextMenu.prototype.updateTitleDomain = function(tab) { | ||
if (tab) { | ||
var domain = getDomain(tab.url); | ||
if (domain) { | ||
this.chromeAPI.contextMenus.update(this.menu, { | ||
title : this.chromeAPI.i18n.getMessage('visits_to_domain', [ domain ]) | ||
}); | ||
} | ||
}; | ||
|
||
PageContextMenu.prototype.updateTitleDomain = function(tab) { | ||
if(tab) { | ||
var domain = getDomain(tab.url); | ||
if(domain) { | ||
this.chromeAPI.contextMenus.update(this.menu, { | ||
title: this.chromeAPI.i18n.getMessage('visits_to_domain', [domain]) | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
PageContextMenu.prototype.listenToTabs = function() { | ||
if(this.chromeAPI.tabs) { | ||
var _this = this; | ||
|
||
if(this.chromeAPI.tabs.onActivated) { | ||
this.chromeAPI.tabs.onActivated.addListener(function(tabInfo) { | ||
if(_this.menu) { | ||
_this.onTabSelectionChanged(tabInfo.tabId); | ||
} | ||
}); | ||
} | ||
|
||
if(this.chromeAPI.tabs.onUpdated) { | ||
this.chromeAPI.tabs.onUpdated.addListener(function(tabId, changedInfo, tab) { | ||
if(_this.menu) { | ||
_this.onTabUpdated(tab); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
|
||
PageContextMenu.prototype.onTabSelectionChanged = function(tabId) { | ||
PageContextMenu.prototype.listenToTabs = function() { | ||
if (this.chromeAPI.tabs) { | ||
var _this = this; | ||
this.chromeAPI.tabs.get(tabId, function(tab) { | ||
_this.updateTitleDomain(tab); | ||
}); | ||
}; | ||
|
||
PageContextMenu.prototype.onTabUpdated = function(tab) { | ||
if(tab && tab.selected) { | ||
this.updateTitleDomain(tab); | ||
} | ||
}; | ||
|
||
PageContextMenu.prototype.remove = function() { | ||
this.chromeAPI.contextMenus.remove(this.menu); | ||
delete(this.menu); | ||
}; | ||
if (this.chromeAPI.tabs.onActivated) { | ||
this.chromeAPI.tabs.onActivated.addListener(function(tabInfo) { | ||
if (_this.menu) { | ||
_this.onTabSelectionChanged(tabInfo.tabId); | ||
} | ||
}); | ||
} | ||
|
||
BH.Chrome.PageContextMenu = PageContextMenu; | ||
if (this.chromeAPI.tabs.onUpdated) { | ||
this.chromeAPI.tabs.onUpdated.addListener(function(tabId, changedInfo, | ||
tab) { | ||
if (_this.menu) { | ||
_this.onTabUpdated(tab); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
PageContextMenu.prototype.onTabSelectionChanged = function(tabId) { | ||
var _this = this; | ||
this.chromeAPI.tabs.get(tabId, | ||
function(tab) { _this.updateTitleDomain(tab); }); | ||
}; | ||
|
||
PageContextMenu.prototype.onTabUpdated = function(tab) { | ||
if (tab && tab.selected) { | ||
this.updateTitleDomain(tab); | ||
} | ||
}; | ||
|
||
PageContextMenu.prototype.remove = function() { | ||
this.chromeAPI.contextMenus.remove(this.menu); | ||
delete (this.menu); | ||
}; | ||
|
||
BH.Chrome.PageContextMenu = PageContextMenu; | ||
})(); |
Oops, something went wrong.