Skip to content

Commit

Permalink
Added new functions to fix URL formatting error for more complicated …
Browse files Browse the repository at this point in the history
…queries
  • Loading branch information
Zozman committed Oct 25, 2014
1 parent 8693147 commit 142bbcc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Binary file modified dist/theGifOracle.crx
Binary file not shown.
12 changes: 11 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function searchOracle(info)
{
var searchString = info;
// Replace spaces with plus signs
var modifiedSearchString = searchString.replace(" ", "+");
var modifiedSearchString = searchString.replaceAll(" ", "+");
// Set API Key for Gifly (Test Key, not a production key)
var apiKey = "dc6zaTOxFJmzC";
// Create search URL
Expand Down Expand Up @@ -183,6 +183,16 @@ chrome.omnibox.onInputEntered.addListener(
searchOmnibox(text);
});

// Helper function to handle Regular Expressions escape
RegExp.escape = function(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};

// Helper function to handle a replace all for a string
String.prototype.replaceAll = function(search, replace) {
return this.replace(new RegExp(RegExp.escape(search),'g'), replace);
};

// Adds the functions to the context menu (right click)
chrome.contextMenus.create({title: "Find Random GIF", contexts:["selection"], onclick: openInNotification});
chrome.contextMenus.create({title: "Open Random GIF In New Tab", contexts:["selection"], onclick: newTabSearch});
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"background": {
"scripts": ["jquery.min.js", "background.js"]
},
"version": "1.0.2",
"version": "1.0.3",
"omnibox": { "keyword" : "oracle" },
"description": "Select a word and retrieve a random GIF of it with the might of the ORACLE! Powered by the Giphy API.",
"permissions": [ "contextMenus", "tabs", "notifications", "clipboardWrite", "http://*/*", "https://*/*" ],
Expand Down

0 comments on commit 142bbcc

Please sign in to comment.