1

I'm trying to create a google chrome extension (I'm almost a newb at programming, although I understand the basics, somewhat) that will search a video streaming site for the title that you enter. The site is somewhat slow, and going through a page or two to get to the sites' search bar can be a pain. I would (for now) like this extension to tie into the sites' existing search url. Here is part of the URL. When you leave the search field blank and search, this is the resulting URL

anisrch_title=&op=srch&anisrch_cat=

When you actually search for something, it simply inserts the search term as follows:

anisrch_title=(SEARCH TERM HERE WITHOUT PARENTHESES)&op=srch&anisrch_cat=

As I mentioned before, I am a programming newbie, and am unfamiliar with all sorts of programming techniques. How would I go about making an extension that redirects you to the URL + the search term inserted into the appropriate place?

For example, upon clicking the extension Icon, a pop-up appears with a text field and a "Go" button. Textfield input = SearchTitle

And upon clicking the "Go" button, the extension redirects you to the full link of: anisrch_title=(SearchTitle)&op=srch&anisrch_cat=

Please be patient with me, as I am a newbie at coding and I am still learning. The site I am making this for is strained by heavy load, and insufficient server resources. Could someone please walk me through this?

Cory Liseo
  • 81
  • 1
  • 2
  • 8

1 Answers1

1

For example, upon clicking the extension Icon, a pop-up appears with a text field and a "Go" button. Textfield input = SearchTitle

Use a browser action (https://developer.chrome.com/trunk/extensions/browserAction.html). The popup of a browser action can be a html page. Just put your text field, go button, etc in popup.html.

And upon clicking the "Go" button, the extension redirects you to the full link of: anisrch_title=(SearchTitle)&op=srch&anisrch_cat=

redirect? Did you mean opening the search page in the current tab? If that is the case, use chrome.tabs.update (https://developer.chrome.com/extensions/tabs.html#method-update) in your handler of onclick for the button (say your button id is go and text field id is query). Because of CSP (https://developer.chrome.com/trunk/extensions/contentSecurityPolicy.html), you must place your JavaScript code in a separate popup.js and refer to it in your popup.html.

document.getElementById('go').addEventListener('click', function() {
  chrome.tabs.update({url: 'http://yoursite.com/path?anisrch_title=' + document.getElementById('query')'&op=srch&anisrch_cat='});
});

If you prefer opening a new tab, use chrome.tabs.create instead.

If you're not familiar with basics of Chrome extensions, the Getting Started tutorial will help you much: https://developer.chrome.com/extensions/getstarted.html.

方 觉
  • 4,042
  • 1
  • 24
  • 28