Forcing %s to escape spaces with plus instead of percent twenty
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT
Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay
--
Chapters
00:00 Forcing %S To Escape Spaces With Plus Instead Of Percent Twenty
00:46 Answer 1 Score 5
01:42 Answer 2 Score 3
02:21 Accepted Answer Score 5
03:49 Answer 4 Score 1
04:27 Thank you
--
Full question
https://superuser.com/questions/281934/f...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#googlechrome
#avk47
ANSWER 1
Score 5
You don't need to use the REST style of searching, but can instead use normal HTTP GET parameters like this:
http://www.metacritic.com/search/all/results?search_term=test+query
So in your case that would be:
http://www.metacritic.com/search/all/results?search_term=%s
Unfortunately, this doesn't work with Metacricic (?).
The best I could get is the following search function, however it doesn't really redirect for some reason:
data:text/html;charset=utf-8,<script>var s = "%s"; s = s.replace("%20", "+"); var url = "http://www.metacritic.com/search/all/" + s + "/results"; window.location = url;</script>
Background info:
Chrome encodes the sent parameters depending on the position, i.e. if its within an URL or as a GET parameter. Within an URL it makes sense to convert a space to %20
, whereas in a parameter the +
is used.
Unfortunately, they're not up to changing this behavior, so my guess would be that a simple line of Javascript could fix this. I'll look into it.
ACCEPTED ANSWER
Score 5
Though a bit crude, you can create a simple Chrome extensions that adjusts the URL for metacritic (or other sites if you want)
Here's the code I've used for a Metacritic Search URL Replace extension:
manifest.json:
{
"content_scripts": [ {
"include_globs": [ "http://www.metacritic.com/search/*%20*" ],
"js": [ "script.js" ],
"matches": [ "http://*/*", "https://*/*" ],
"run_at": "document_start"
} ],
"converted_from_user_script": true,
"description": "Replaces '%20' in metacritic search request to '+'",
"name": "Metacritic search replacer",
"version": "0.1"
}
script.js:
window.location = window.location.href.replace(/%20/g, "+");
Since I don't really have a reliable spot to upload my extension, here are the instructions to create a Chrome extension using these two files:
First, put the two files in a folder somehwere and browse to chrome://extensions. Make sure the developer mode is active (look at the top right of the page to enable this). Here you can select 'Pack extension..' which asks you for the folder where your script resides. Once you have selected this folder, the extension will be created and you can just drag & drop it into Chrome to install. If everything went according to plan, the script will rewrite the URL for a Metacritic search request from the '%20' to the '+' characters.
Now, you can use http://metacritic.com/search/all/%s/results
as a search engine url in Chrome itself to use a shortcut to this search.
Hope this helps.. ;)
ANSWER 3
Score 3
As pointed out by slhck in his answer, Chrome only supports %s, and insists on "intelligently" determining whether to use plus symbols or %20
to escape spaces (see Chromium bug 78429).
The particular test case I'm dealing with (metacritic.com) imposes too many hoops to leap through concurrently with their RESTful search interface.
Therefore, as a work-around, I elected to simply use app.metacritic.com's legacy interface:
http://apps.metacritic.com/search/process?tfs=game_title&sb=0&game_platform=PC&ts=%s
If that hadn't been available, I would have contacted metacritic.com, referred them to the Chromium bug, and begged for mercy. :-)
ANSWER 4
Score 1
I couldn't get neither the .crx or the .js to install properly (maybe it is my fault).
I managed to get it working by relying on a greasemonkey script (I do personnaly use the Tampermonkey google chrome extension to handle greasemonkey scripts).
Once in Tampermonkey I create a new script and paste the following (and it works! once again, a BIG THANKS to JiriB, as I just copy/pasted his findings):
// ==UserScript==
// @name Google-Chrome-URL-Replacer-Extension (Metacritic)
// @namespace https://github.com/FjearJiri/Google-Chrome-URL-Replacer-Extension/
// @version 1.0
// @description Replaces %20 with + in URLs in order to build valid URLS for search engine shortcuts
// @include http://www.metacritic.com/search/*%20*
// @copyright 2011+, FjearJiri ('ported' to greasemonkey script by zifnab)
// ==/UserScript==
// http://superuser.com/questions/281934/forcing-s-to-escape-spaces-with-plus-instead-of-percent-twenty
window.location = window.location.href.replace(/%20/g, "+");