remove parameter based on visitors country - javascript

I'm looking for a javascript that allows me the function described, I would like to get removed the parameter aff_id from any url depending on visitors country:
www.domain.com/join/?language=es&aff_id=3
resulting url: www.domain.com/join/?language=es
(can be this or any other url, what matters is that aff_id=X doesn´t show for that country in particular, but it does for others)
Is this possible? Could anyone show me something similar to what I´m looking for?
Thank you in advance.

First you need to lookup user IP-address in some geoip service (e.g. hostip.info). It can be done client-side. Check out this and this questions to get some ideas on how this can be implemented.
Next you need to substitute a part of URL. That should be simple, e.g. using location.replace.

Related

I need to get an Instagram User ID# for use in Google Script

I'd like to take a username and plug it into this format
https://www.instagram.com/{username}/?__a=1
thanks to this thread for that tip
I then need to follow that link in java, and when doing so it presents the following page code, which I've abridged to save space. I used professional Skateboarder Nyjah Huston as my example.
{"logging_page_id":"profilePage_8223552","show_suggested_profiles":false,"show_follow_dialog":false,"graphql":{"user":{"biography":"Sender\ud83d\ude08\n#nikesb #monsterenergy #elementbrand #blackplaguebrewing #socialcbd #priverevaux","blocked_by_viewer":false,"restricted_by_viewer":null,"country_block":false,"external_url":"https://www.nike.com/t/sb-nyjah-free-skate-shoe-oKwn7N/AA4272-300","external_url_linkshimmed":"https://l.instagram.com/?u=https%3A%2F%2Fwww.nike.com%2Ft%2Fsb-nyjah-free-skate-shoe-oKwn7N%2FAA4272-300&e=ATMW9Q8NwN2Mcwm_Bd5I8DeuAKP4L7IHpy_PdylDnGU8qqokJU6Z1kh_emEIVfJ1q8Xtq1b0&s=1","edge_followed_by":{"count":3969537},"followed_by_viewer":false,"edge_follow":{"count":694},"follows_viewer":false,"full_name":"Nyjah Huston"
As you can see, the User ID is one of the first things on the page
{"logging_page_id":"profilePage_8223552"
the user id being 8223552 in this case. I'm quite new to java, and I need to know how to follow that link and parse that data in order to turn the user id into a var for use in my google script. Thank you for your help!
You can easily parse this JSON content to a object that has only the information you need:
class UserInformation{
private String logging_page_id;
}
I suggest this option because if you need in the future to get another info, you can easily just extend the object.
How to do the conversion, please reference to this stackoverflow

Get the Base Hostname Using Only JavaScript So Cookies Work Sitewide

I am looking for a way to take window.location.hostname and end up with the base domain name, regardless of situation. So from all of:
http://example.domain.com
https://www.example.domain.com
https://www.example.domain.com/stuff/index.php
I would end up with:
domain.com
And from: example.domain.co.uk/ would result: domain.co.uk
I have searched many questions on this topic here on SO and it seems like none ever really result in a complete answer. Some involve using complicated regex that it's hard to tell if wouldn't sometimes fail. And other answers only net a result of example.domain.com.
I am utterly floored that there is not just a simple way of getting this value in JavaScript. I am writing a plugin for websites that uses cookies to store user preferences. I am concerned that if a user sets preferences while using the plugin on a page from one hostname, say one.domain.com, on the off chance they go to use the plugin on another page hosted on two.domain.com, they would need to set their preferences all over again. When I set the cookies, I would like to be able to set them site-wide (at the domain.com level). Because this is a plugin, the domain name will not be known and needs to be calculated starting from window.location.hostname.
So is there a standard way of arriving at what I'm looking for? Or am I just approaching this the wrong way? I suppose I could just have a configuration setting for the website owner to input their base domain name and get it that way, but I'd prefer not to go that route if possible. And honestly, I'd still like to know how to do this anyway. Thanks in advance for any suggestions!
window.location.host
will return the domain name. But, in your case it would return "example.domain.com".
Then you need to do some manipulation on it, using split function , to get the desired value.

How to encode/decode URL parameters in javascript?

Before anyone jumps in and says, "Oh!! that's a bad idea", I know it is.
I want to keep both the key and value in the query string to be not easily visible to the end user.
I have something like this google.com/?category=textile&user=user1
I need to make it unintelligible like this: google.com/?kasjdhfkashasdfsf32423
Is there any way to achieve this in javascript. I have already seen this
I have already seen this
and this.
but I don't think encoding will solve the problem. Also, this code is entirely in client side. I know that it is not secure but I just need this is a naive, weak defense.
Please help.
Edit
I apologize if my question was not clear earlier.
The URL google.com/?category=textile&user=user1 is being passed on from a different application.
The values passed in the query string directly controls what is being displayed to the user. As is, anyone with no technical knowledge can easily change the value and view the data corresponding to a different category or user. I need to make this unintelligible so that it is not obvious. If a user is a techie and figures out the encryption used, then it is fine. I need a stop-gap solution till we have a better architecture in place
You can use base64. Javascript has native functions to do that :
alert(btoa("category=textile&user=user1")); // ==> Y2F0ZWdvcnk9dGV4dGlsZSZ1c2VyPXVzZXIx
and to reverse it :
alert(atob("Y2F0ZWdvcnk9dGV4dGlsZSZ1c2VyPXVzZXIx")); // ==> category=textile&user=user1
Be careful to read the doc if you have unicode strings, it's a little different : https://developer.mozilla.org/en-US/docs/Web/API/Window.btoa
If you don't looking for serious strong crypto, you can use ROT13:
http://en.wikipedia.org/wiki/ROT13
This is enough for slightly obfuscate keys/values in the your URLs.

Extract search engines' keywords with javascript and HTTP referer

I can't find anything googling. How can I extract search engine keywords for traffic sent to my website using javascript?
I don't want to reinvent the wheel, I'm looking for something that already exists, a tested library, however I can't find it.
As an answer, rather than just a comment. Your javascript code will need to inspect document.referrer (This may have been the magic keyword missing from your search).
Different search engines use different parameter names for the query, so you will need to know what to look for. Google uses q Yahoo! appear to use pqstr. Look for the value of that parameter in the referring url, and unencode it (with unencodeURIComponent).
However, there is still this answer to check out.

Adapting Etherpad to react on new params

I try to adapt etherpad so it is only accessible if certain params are sent with the request.
For example I want a certain pad just to be displayed if there is a unique id provided like
http://myetherpad.com/thepadid?myparam=blub
Does anyone know where exactly I can parse the params? I searched all the js-files but didn't find exactly what I am looking for.
I found out that there is some kind of request object. You can access it like
request.params.padId
But I also don't know where to search for the implementation of this object.
I hope somebody can help me. Thanks :)
You could probably hack something into the code at https://github.com/ether/pad/blob/master/etherpad/src/etherpad/licensing.js#L153
But if all you need is some kind of password protection, there are easier ways. The easiest would be to use something that is built in to your web server, or to use the built-in pro functionality -- more on that on http://etherpad.org/2010/10/14/241/
(Your idea with using URL-parameters for password could be simplified; just use a complicated pad name and only those with the URL will find it. Having a "nice" pad name and adding a complicated password at the end doesn't protect the pad at all.)
For anyone with the same problem: You can get the GET-parameters via
request.headers['Referer']
It returns the URI the user called. But I still don't know how to do it properly (or get the POST parameters).

Categories

Resources