It is possible to obfuscate the code with several Javascript obfuscators and compressors to prevent the code from being readable or editable, but the most accurate is to "reinforce" the code, which does not yet have any tool developed. It could be basically made a condition like this to check if the domain of the page is true:
var i = location.href.indexOf('//') + 2,
sub = location.href.substring(i,
(location.href.substring(i).indexOf('/') + i) || null
);
sub === "www.example.com" || sub === "example.com";
, which is not sufficient and difficult to apply several times in a project, however.
Jscrambler
Jscrambler is an online Javascript obfuscator and has an option to make the script work on a specific domain (it should be very simple in the basic version), which has a version ancient and a version new. The new version is not free and seems a better base, while the old version is free and has almost no obfuscation feature. I can not prove much the paid version since I never bought - he has an example of demonstration, luckily.
Thanks to easy-to-use Javascript interpreters some tool can be created in the future, or near here.
Not using this in the browser JS?
– Maniero
I need it because I don’t have access to the server.
– Haffy
So forget it..
– Maniero
CORS with authorization list of which domains you want to accept access. Still, credentials and authorization keys should never be present directly in Javascript.
– OnoSendai
@Haffy Do not use the edit field to change the intention of the question, as it risks invalidating the answers already given. Instead, ask another question.
– Pablo Almeida