Skip to content

Commit

Permalink
never override builtin prototypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Eaton authored and Jake Eaton committed Feb 27, 2017
1 parent 43e5a6b commit 7031222
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 144 deletions.
12 changes: 6 additions & 6 deletions background_scripts/actions.js
Expand Up @@ -173,7 +173,7 @@ Actions = (function() {
_.openLinksWindow = function(o) {
var urls = o.request.urls;
if (!o.request.noconvert) {
urls = urls.map(function(e) { return e.convertLink(); });
urls = urls.map(function(e) { return Utils.toSearchURL(e); });
}
for (var i = 0; i < o.request.repeats; i++) {
chrome.windows.create({
Expand Down Expand Up @@ -417,17 +417,17 @@ Actions = (function() {
return;
}
paste = paste.split('\n').filter(function(e) { return e.trim(); });
if (paste.length && paste[0].convertLink(o.request.engineUrl) !== paste[0]) {
if (paste.length && Utils.toSearchURL(paste[0], o.request.engineUrl) !== paste[0]) {
paste = paste.join('\n');
openTab({
url: paste.convertLink(o.request.engineUrl),
url: Utils.toSearchURL(paste, o.request.engineUrl),
index: getTabOrderIndex(o.sender.tab)
});
} else {
for (var i = 0; i < o.request.repeats; ++i) {
for (var j = 0, l = paste.length; j < l; ++j) {
openTab({
url: paste[j].convertLink(o.request.engineUrl),
url: Utils.toSearchURL(paste[j], o.request.engineUrl),
index: getTabOrderIndex(o.sender.tab)
});
}
Expand All @@ -442,7 +442,7 @@ Actions = (function() {
}
paste = paste.split('\n')[0];
chrome.tabs.update({
url: paste.convertLink(o.request.engineUrl)
url: Utils.toSearchURL(paste, o.request.engineUrl)
});
};

Expand Down Expand Up @@ -941,7 +941,7 @@ Actions = (function() {
o.request.repeats = Math.max(~~o.request.repeats, 1);

if (o.request.url && !o.request.noconvert) {
o.url = o.request.url.convertLink();
o.url = Utils.toSearchURL(o.request.url);
} else if (o.request.url) {
o.url = o.request.url;
} else {
Expand Down
9 changes: 4 additions & 5 deletions background_scripts/bookmarks.js
Expand Up @@ -16,15 +16,14 @@ Bookmarks.containsFolder = function(path, directory) {
};

Bookmarks.getFolderLinks = function(path, callback) {
path = path.split('/').compress();
path = Utils.compressArray(path.split('/'));
chrome.bookmarks.getTree(function(tree) {
var dir = tree[0];
while (dir = Bookmarks.containsFolder(path[0], dir)) {
path = path.slice(1);
if (!path || !path.length) {
callback(dir.children.map(function(e) {
return e.url;
}).compress());
var links = dir.children.map(function(e) { return e.url; });
callback(Utils.compressArray(links));
}
}
});
Expand All @@ -40,7 +39,7 @@ Bookmarks.getPath = function(marks, path, callback, initialPath) {
if (typeof path !== 'string' || path[0] !== '/') {
return false;
}
path = path.split(/\//).compress();
path = Utils.compressArray(path.split(/\//));
marks.forEach(function(item) {
if (item.title === path[0]) {
folder = item;
Expand Down
4 changes: 2 additions & 2 deletions background_scripts/options.js
Expand Up @@ -125,7 +125,7 @@ Options.getAllSettings = function(request, sender, callback) {
};

Options.updateBlacklistsMappings = function() {
var rc = settings.RC.split(/\n+/).compress(),
var rc = Utils.compressArray(settings.RC.split(/\n+/)),
i, index, line;
if (settings.BLACKLISTS) {
settings.blacklists = settings.BLACKLISTS.split(/\n+/);
Expand All @@ -137,7 +137,7 @@ Options.updateBlacklistsMappings = function() {
index = i;
}
}
settings.blacklists = settings.blacklists.unique();
settings.blacklists = Utils.uniqueElements(settings.blacklists);
if (settings.blacklists.length) {
line = 'let blacklists = ' + JSON.stringify(settings.blacklists);
if (index) {
Expand Down
4 changes: 2 additions & 2 deletions background_scripts/popup.js
Expand Up @@ -5,7 +5,7 @@ var Popup = {
Popup.getBlacklisted = function(callback) {
if (typeof callback === 'object')
callback = callback.callback;
var blacklists = settings.blacklists.compress();
var blacklists = Utils.compressArray(settings.blacklists);
this.getActiveTab(function(tab) {
var url = tab.url;
for (var i = 0, l = blacklists.length; i < l; ++i) {
Expand Down Expand Up @@ -83,7 +83,7 @@ Popup.toggleEnabled = function(obj) {
};

Popup.toggleBlacklisted = function() {
var blacklists = settings.blacklists.compress();
var blacklists = Utils.compressArray(settings.blacklists);
this.getActiveTab(function(tab) {
var url = tab.url;
var foundMatch = false;
Expand Down
25 changes: 12 additions & 13 deletions content_scripts/command.js
Expand Up @@ -292,7 +292,7 @@ Command.callCompletionFunction = (function() {

var searchCompletion = function(value) {
self.deleteCompletions('engines,bookmarks,complete,chrome,search');
search = search.split(/ +/).compress();
search = Utils.compressArray(search.split(/ +/));
if ((search.length < 2 && value.slice(-1) !== ' ') ||
(!Complete.engineEnabled(search[0]) && !Complete.hasAlias(search[0]))) {
self.completions.engines = Complete.getMatchingEngines(search.join(' ')).map(function(name) {
Expand Down Expand Up @@ -500,7 +500,7 @@ Command.execute = function(value, repeats) {

commandMode = false;

var split = value.split(/\s+/g).compress();
var split = Utils.compressArray(value.split(/\s+/g));
if (this.customCommands.hasOwnProperty(split[0])) {
this.execute(this.customCommands[split[0]] + ' ' + split.slice(1).join(' '), 1);
return;
Expand Down Expand Up @@ -547,7 +547,7 @@ Command.execute = function(value, repeats) {
value = value.replace(/[&$*!=?|]+$/, function(e) {
return e.replace(/[^=?]/g, '');
});
if (Complete.engineEnabled(value.split(/\s+/g).compress()[1]))
if (Complete.engineEnabled(Utils.compressArray(value.split(/\s+/g))[1]))
value = value.replace(/[=?]+$/, '');

this.history.index = {};
Expand Down Expand Up @@ -732,7 +732,7 @@ Command.execute = function(value, repeats) {
if (Number.isNaN(+sessionId) && this.completionResults.length)
sessionId = this.completionResults[0][3];
RUNTIME('restoreChromeSession', {
sessionId: sessionId.trimAround()
sessionId: Utils.trim(sessionId)
});
}

Expand Down Expand Up @@ -784,7 +784,7 @@ Command.execute = function(value, repeats) {
}

if (/^delsession/.test(value)) {
value = value.replace(/^\S+(\s+)?/, '').trimAround();
value = Utils.trim(value.replace(/^\S+(\s+)?/, ''));
if (value === '') {
Status.setMessage('argument required', 1, 'error');
return;
Expand All @@ -800,7 +800,7 @@ Command.execute = function(value, repeats) {
}

if (/^mksession/.test(value)) {
value = value.replace(/^\S+(\s+)?/, '').trimAround();
value = Utils.trim(value.replace(/^\S+(\s+)?/, ''));
if (value === '') {
Status.setMessage('session name required', 1, 'error');
return;
Expand All @@ -820,7 +820,7 @@ Command.execute = function(value, repeats) {
}

if (/^session/.test(value)) {
value = value.replace(/^\S+(\s+)?/, '').trimAround();
value = Utils.trim(value.replace(/^\S+(\s+)?/, ''));
if (value === '') {
Status.setMessage('session name required', 1, 'error');
return;
Expand Down Expand Up @@ -1142,11 +1142,10 @@ Command.updateSettings = function(config) {
if (config.locale) {
Complete.setLocale(config.locale);
}
if (config.hintcharacters &&
config.hintcharacters.split('').unique().length > 1) {
settings.hintcharacters = config.hintcharacters
.split('').unique().join('');
}

var chars = Utils.uniqueElements((config.hintcharacters || '').split(''));
settings.hintcharacters = chars.join('');

if (config !== settings) {
for (key in config) {
if (key.toUpperCase() !== key && settings.hasOwnProperty(key)) {
Expand Down Expand Up @@ -1265,7 +1264,7 @@ Command.configureSettings = function(_settings) {
Command.blacklisted = false;
var isBlacklisted = false;
for (var i = 0, l = blacklists.length; i < l; i++) {
blacklist = blacklists[i].trimAround().split(/\s+/g);
blacklist = Utils.split(blacklists[i], /\s+/);
if (!blacklist.length) {
continue;
}
Expand Down

0 comments on commit 7031222

Please sign in to comment.