Solved: Firefox – Adding New Custom Search-Engine Trick


here is how to do it for Google-Chrome (the reason why I want it..)
UnFuck Google-Search Shitty-Results By Actually Pre-Removing / Pre-Avoiding Many Known-To-Be-Crappy Websites!

also available here:
https://gist.github.com/eladkarako/d9a3772090f11529eed12f5f1beaf886


Adding a new custom search engine to firefox, instead of modifying browser.search.defaulturl and keyword.URL that won’t work anymore in new versions of firefox.

needs apache(XAMPP will do just fine), local HOSTS file editing, basic understanding in .htaccess, JavaScript, HTML, developers-panel operations, 5 minutes of your time.

close down firefox.

(optional step)
edit your HOSTS file (C:\Windows\System32\drivers\etc\hosts or /system/etc/hosts),
this might need admin access, and removing the readonly attribute from the file,
giving your 127.0.0.1 a real domain name in addition to domain-less localhost.

127.0.0.1 www.localhost.com
::1       www.localhost.com
:1        www.localhost.com

127.0.0.1 localhost.com
::1       localhost.com
:1        localhost.com

127.0.0.1 localhost
::1       localhost
:1        localhost

save, run ipconfig /flushdns

start your apache server,
create a new firefox_search_button folder,
within this .htaccess file:

#this is an optional file
#to force sending out
#additional HTTP headers
#with the file itself.

<IfModule mod_mime.c>
  DefaultLanguage     en-US
  AddDefaultCharset   UTF-8
  AddType application/opensearchdescription+xml  xml
</IfModule>

<FilesMatch "\.(?i:xml|xmlz)$">
  #include file-name header.
  ##<IfModule mod_setenvif.c>
  ##  SetEnvIf Request_URI "^.*/([^/]*)$" FILENAME=$1
  ##  Header set "Content-Disposition" "attachment;filename=\"%{FILENAME}e\""
  ##  UnsetEnv FILENAME
  ##</IfModule>

  #force mimetype
  <IfModule mod_mime.c> 
    ForceType application/opensearchdescription+xml
  </IfModule>
</FilesMatch>

this index.html file for testing:

<!doctype html>
<html itemtype="https://schema.org/WebPage" dir="ltr" lang="en-US">
<head>
</head>
<body>
<a type="application/opensearchdescription+xml" title="Install Search-Engine" href="your_search_engine_20170815.xml">Install Search-Engine</a>
</body>
</html>

and this your_search_engine_20170815.xml:

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
  <ShortName>Google (g-no-w3s)</ShortName>
  <Description>google.co.il search (g-no-w3s)</Description>
  <InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAglJREFUOI2Nk99L02EUxj/vNkthRdToFxLNJqaJESYVXtSN3ZS1CqMM6qKLQKJ/oPsF3eV1F1HRBrVcGV4FdRPeJUK0oeYaUmyzRbOxpvtuTxd+v7atIA+ci/e8z3nOe57zHmgwSQFJEUkzksq2z9ixtkZ8bSKSxvR/i0r6Z3LCQRRfxZS7claZ7u3KHPApd3lQxfE67rhDYmyCMSCo5RLfh89QSc6A2w1WebWCZwNaLtLU08fWxy+cus+NMRecniVJi+dOKtPfrUzPLhUij2TNz8lKzqkQfqjs0XZV8j8a2/FjiyPrQ1iZI61Kd+yUtZBahxSSpDC2wrImA1qZQMXo6HqTJSnhAfwAys9h3NA80FsnsLn1kw6vWTv/qkCwy829ay0AbZ46sMBUGkZUY9uaDW4DtQgXkATwbG6nBEwsxOtHPLqJRMhLIuTl4mEPhbLY53M51/Mu4D1AevcdDi6e4NRUhM9LX/6qns3D/UmLchX6O9cePmW0+j0/AQzErvO1mOVbpcjdQyMca+3FZVxMp6e5/SaFL32DPT6LJzdbHAK/85GiwPlSdYXg+Agfl1J4jJuyKghoMi5kCuzQcd4OhWjZCMAzY8yQQwAQB/YDvJx9zYPZGO9ycapA35YAVwOnudQ56FSOA13G/JmOsw/Rdcz+qRqXqU51yS8prNXlWrE9Ycf2NuJ/A6uf5JCErH2FAAAAAElFTkSuQmCC</Image>

<Url type="application/x-suggestions+json" method="GET" template="https://www.google.com/complete/search?client=firefox&amp;q={searchTerms}"/>

<Url type="text/html" method="GET" template="https://www.google.co.il/search?num=50&amp;gbv=1&amp;q={searchTerms}%20-site%3Aw3schools.com%20-site%3A4pda.ru%20-site%3Af5.com%20-site%3Aexperts-exchange.com%20-site%3Adaniweb.com%20-site%3Aoutbrain.com%20-site%3Ataboola.com%20-site%3Avisualstudio.com%20-site%3Atumblr.com%20-site%3Afacebook.com%20-site%3Ahe-il.facebook.com%20-site%3Apictaram.com%20-site%3Atwitter.com%20-site%3Ainstagram.com%20-site%3Awikihow.com%20-site%3Aquora.com%20-site%3Astumbleupon.com%20-site%3Apinterest.com%20-site%3Alinkedin.com%20-site%3Aplus.google.com%20-site%3Aflickr.com%20-site%3Abugzilla.mozilla.org%20-site%3Ajsfiddle.net%20-site%3Acodepen.io%20-site%3Abooks.google.com%20-site%3Asafaribooksonline.com%20-site%3Aw3.org%20-site%3Awufoo.com%20-site%3Ahtmlcodes.ws%20-site%3Agnu.org%20-site%3Asitelinks.info" rel="searchform"></Url>

</OpenSearchDescription> 

open firefox, start the developer-panel (F12), switch to the network tab,
then browse http://www.localhost.com/firefox_search_button/index.html.
click the link, and expect the Content-Type to have something like application/opensearchdescription+xml.

head over to https://addons.mozilla.org/en-US/firefox/search/,
hover over the line with Google (Default), the green button will be shown at the other side,
showing + Add to firefox, don’t click it just yet.
right click the green-button and choose “inspect element”.

(you should see the DOM-tree with the button element, which will be selected by default)

press F2 to edit the HTML of the element,

replace, what will appear to be something like this:

<a class="button add installer" data-hash="sha256:ad1f41a28222ad13500e646522c48a517109e0e6c1eac0d079dbbfc5728fcc51" href="/firefox/downloads/latest/google-default-1/addon-651932-latest.xml?src=search">
  <b></b>
  <span>Add to Firefox</span>
</a>

with

<a class="button add installer" type="application/opensearchdescription+xml" href="http://www.localhost.com/firefox_search_button/your_search_engine_20170815.xml">
  <b></b>
  <span>Add to Firefox</span>
</a>

and click something else to the newly modified HTML will be effected.

quickly switch back to the page (without refreshing it or something..)
hover the mouse over the button and you should see the url http://www.localhost.com/firefox_search_button/your_search_engine_20170815.xml shown below

click the button,
you can select the checkbox to allow it to be used by default.
select add it to firefox and it will be added to your list of search engines.


it will be kept in your list of search engines
and will be synced in your account so could even have it in your smartphone as well! :)


You could edit the your_search_engine_20170815.xml,
to have your desired website, and switches.

I’m using a modified URL of google-search.

the phrase {searchTerms} is preserved, and will be replaced with what you’ll be entering
in your addressbar when you’ll hit-ENTER (or the search bar).

and although you can specify it inside of the <Url> tag
like <Param name="q" value="{searchTerms}"/>, since I’m using
a complete google address with additional of spaces and -site: that should be escaped,
I’m simply dumping it there as it is.

just remember to replace & characters with &amp; in your URL,
since this IS AN XML after-all..

the end result will be the url, unescaped,
with your search term jammed into the place where the {searchTerms} was.

the entire thing is required to overcome firefox page-security,
(which is preety lame).


you can now remove the additions to your HOSTS file (keep in your HOSTS file at least once: 127.0.0.1 localhost)
and remove the apache server.


If you’ve done something wrong you can always remove the added search-engine through about:preferences.


Info Pic Dump…