add a remote JS to a crossrider extension - crossrider

I am working on crossrider to make an extension that needs to add two remote JS to all pages loaded using https protocole. one script should come before and the other one should be loaded after . I tried to follow the docs provided in crossrider website but all my attempts failed. Can you please help me to finish this.
This is what U tried to do
appAPI.ready(function($) {
src="http://code.jquery.com/jquery-1.10.1.min.js" />
appAPI.dom.addRemoteJS({
url: "http://code.jquery.com/jquery-1.10.1.min.js",
additionalAttributes: {charset: "UTF-8"},
callback: function(ref) {
appAPI.dom.addRemoteJS({
url: "http://domain.com/script.js"
});
}
});
});

In general, the snippet is correct and conforms to the example provided in the Crossrider docs.
Upon testing your specific script URL (that you provided elsewhere for privacy reasons) I can see in the console that that there is an error in the second script called in the callback function, i.e. the script.js in the example snippet you provided. Once you fix this error, you can proceed to complete your extension.
[Disclaimer: I am a Crossrider employee]

Related

How do I know I am being called from a progresive web app?

I've been following the guidance on google to create a PWA, but I am interested if there are any conventions to communicate with your data server that you are being called by a PWA. Is the easiest thing to add a parameter to the request i.e.
var dataUrl = 'https://query.myapi.com/v1/get?source=pwa';
and then check the source parameter? Or should I add to the request header?
In your code
if (window.matchMedia('(display-mode: standalone)').matches) {
// do things here
// set a variable to be used when calling something
// e.g. call Google Analytics to track standalone use
}
** Assumption made that you are also setting up your app to be added to the users home screen as a shortcut
You have to pass in the traffic source to Google Analytics indicating its from PWA. Refer this answer on more details.

Pop-up Scope to contain current tab URL on open

I've been using Crossrider's great API for some time now, however I have reached a great block in my progress.
I have been able to message the popup scope with the current domain through the tab change interrupts and the change of url interrupts. However, when I click the popup browser button, data about the current tab URL is supposed to be shown. Instead, such data is black, and when debugging - it was found that the reason for it being blank is either:
The current URL is being set to the popup extension internal URL
Some sort of bug with the popup logic
I am really stumped, and require such functionality to progress further. My Crossrider ID is 52909.
Thanks!
First and foremost, when posting questions to this forum please include code snippets for the benefit of others so that they can try an assist you. As-is they have no access to the extension code you provided.
Looking at your popup.html code, I can see that you are using the following Crossrider API methods that are not supported in the popup scope: appAPI.resources.includeJS, appAPI.webRequest.onRequest. For more information about API supported in the popup scope, see appAPI.browserAction.setPopup.
As alternatives/workarounds:
For appAPI.resources.includeJS, you can use the jquery to load resources scripts, as follows: $.globalEval(appAPI.resources.get('script.js'));
For appAPI.webRequest.onRequest, implement it in the background scope and use messaging to pass the data to the popup scope, something like:
background.js:
appAPI.ready(fucntion($) {
appAPI.webRequest.onRequest.addListener(function(details, opaqueData) {
appAPI.message.toPopup(details);
}, []);
});
crossriderMain in popup.html:
function crossriderMain($) {
appAPI.message.addListener(function(details) {
// Do something with the details from webRequest
});
}
[Disclosure: I am a Crossrider employee]

redirect_uri and how to host callback.html on SoundCloud?

I am trying to access Soundcloud from a local HTML page on my laptop. I am stuck at the part of hosting "callback.html" as a redirect_uri. The script I am trying to run is the basic Authenication JavaScript from the Soundcloud documentation page:
<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
client_id: 'my_client_id',
redirect_uri: 'http://127.0.0.1/Users/Maria/Documents/SoundcloudClient/callback.html'
});
// initiate auth popup
SC.connect(function() {
SC.get('/me', function(me) {
alert('Hello, ' + me.username);
});
});
</script>
This script gets me to the connect pop-up when I launch the page in Chrome and Firefox.
But, once I have logged in as a Soundcloud user, I get the following error:
Oops! Google Chrome could not connect to 127.0.0.1
If I change my redirect_uri to localhost I get the same error.
If I try:
files:///C:/Users/Maria/Documents/SoundcloudThinClient/callback.html
I get a similar error.
I also tried:
ocalhost:3000
and:
localhost:8080
even though I'm not sure what would be listening on those ports.
So, basically, I'm asking what path do I put for callback.html in order for this to work?
I confess I don't know how the redirct_uri actually functions. I looked at the Oauth pages for it, but I don't understand them. I am beginning to think that I can't simply create an HTML page, paste the JavaScript, create a callback.html file and have this work, even though the SC documentation seems to say that this is possible. If so, what steps am I missing?
I am beginning to attempt this. I believe you have to go to the developer site and sign up as having an app. The redirect uri is asked for and the form gives you an API key you can use in your app.
I'm using drupal so, perhaps adding the oath module and using Php to add the api key might work well.
I had the same problem and I think I solved it.
Morning-after-edit: I posted this dead-tired after working towards a solution through the night. Now, the day after, I realize that you were speaking about the general problem, whereof I face a very particular instance. The following only applies directly to registering soundcloudlabs' soundcloud-group-recorder: https://github.com/soundcloudlabs/soundcloud-group-recorder. There is probably a more general principle lurking behind there, though:
First: yes, you do have to register the app as your own at Soundcloud. At least I presumed so. And doing that, you must register correctly where on your server you will place the callback.html file. Take the ClientID assigned to your app and use that in the API intialize procedure.
Now, I'm a novice and know very little coding. But I started looking around in the main file, application.js.
At the top of the file there are two instances of client_id and redirect_uri each. I'm not sure if that serves a purpose or if one is technically superfluous. Through trial and error I found out that replacing the second instance of each with my own data worked.
Then there is groupId and groupUrl, both of which should contain your info, within quotation marks.
After a lot of trial and error, still having trouble getting the thing to run, I looked around and saw that, whereas early in the file, client_id was hooked within SC.initialize, redirect_uri was not. Under the line:
client_id: CLIENT_ID
I added:
redirect_uri: REDIRECT_URI
– with a customary comma in between. And that's it. It runs.

Alfresco Share: Using ALfresco.Util.PopupManager in my customized Login page

I am working on customizing Alfresco Share for Business purpose. So I have Customized and Overridden the default login page. But now I want to show the pop up a message for invalid logins in the same way as ALfresco Share does. Going through the core files I found it makes use of ALfresco.Util.Popupmanager and Alfresco.Util.Message. So I included the alfresco.js file and copied the portion of the code from slingshot-login.ftl where it uses ALfresco.Util.Popupmanager.displayprompt, but when I deploy it, rendered the page and issued an invalid login I got the following error:
Alfresco.messages.global is null var globalMsg =
Alfresco.messages.global[p_messageId];
Kindly help.
What is your p_messageId?
This is should work:
Alfresco.util.PopupManager.displayPrompt(
{
text: "My message here"
});

Google Search autocomplete API?

Does Google provide API access to autocomplete for search like on the actual site? I have not been able to find anything.
I would like to use Google's autocomplete logic for web search on my own site which relies on Google's search API.
The new url is:
http://suggestqueries.google.com/complete/search?client=firefox&q=YOURQUERY
the client part is required; I did't test other clients.
[EDIT]
If you want the callback use this:
http://suggestqueries.google.com/complete/search?client=chrome&q=YOURQUERY&callback=callback
As #Quandary found out; the callback does not work with client "firefox".
[EDIT2]
As indicated by # user2067021 this api will stop working as of 10-08-2015: Update on the Autocomplete API
First, go to google, click Settings (bottom right corner), change Search Settings to "never show instant results. That way, you'll get regular autocomplete instead of a full page of instant results.
After your settings are saved, go back to the Google main home page. Open your browser's developer tools and go to the Network tab. If you're in Firefox, you might have to reload the page.
Type a letter in the search box. A new line should appear in the Network window you just opened. That line is showing where the autocomplete data came from. Copy that url. It should look something like this:
https://www.google.com/complete/search?client=hp&hl=en&sugexp=msedr&gs_rn=62&gs_ri=hp&cp=1&gs_id=9c&q=a&xhr=t&callback=hello
You'll notice your search term right after the part that says q=.
Add &callback=myAmazingFunction to the end of the url. You may replace myAmazingFunction with whatever you want to name your function that will handle the data.
Here's an example of the code required to show the autocomplete data for the search term "a".
<div id="output"></div>
<script>
/* this function shows the raw data */
function myAmazingFunction(data){
document.getElementById('output').innerHTML = data;
}
</script>
<script src="https://www.google.com/complete/search?client=hp&hl=en&sugexp=msedr&gs_rn=62&gs_ri=hp&cp=1&gs_id=9c&q=a&xhr=t&callback=hello&callback=myAmazingFunction"></script>
Now that you know how to get the data, the next step is to automatically change that last script (the one with the autocomplete url). The basic procedure is: each time the user types something in the search box (onkeyup) replace the search term (q=whatever) in the url, and then append to the body a script with that url. Remove the previous script so that the body doesn't get cluttered.
For more info, see http://simplestepscode.com/autocomplete-data-tutorial/
Most of the above mentioned methods works for me, specifically the following serves my purpose.
http://suggestqueries.google.com/complete/search?client=firefox&q=YOURQUERY
Being a newbie in web programming, I'm not much aware of the "Callback" functionality and the format of the file returned by query. I'm little aware of AJAX and JSON.
Could someone provide more details about the format of file returned by the query.
Thanks.
Hi I don't know if this answer is relevant for you anymore or not but google returns JSON data through following get request (although this isn't an official API but many toolbars are using this API so there's no reason why google might discontinue it):
http://google.com/complete/search?q=<Your keywords here>&hl=en
You should use AutocompleteService and pass that text box value into the service.getPlacePredictions function. It send the data in callback function.
let service = new google.maps.places.AutocompleteService();
let displaySuggestions = function(predictions, status) {
}
service.getPlacePredictions({
input: value
}, displaySuggestions);
Base: https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompleteService.getPlacePredictions
example: https://dzone.com/articles/implement-and-optimize-autocomplete-with-google-pl
I'm using (( Edrra.com )) API that have google search and suggestions that works with both GET & POST:
Google suggestions:
https://edrra.com/v1/api.php?c=google&f=suggest&k=YOUR_API_KEY&v=YOUR_SEARCH
Google search:
https://edrra.com/v1/api.php?c=google&f=search&k=YOUR_API_KEY&v=YOUR_SEARCH
and more...
What are you trying to use an auto-complete for? More information would help narrow it down.
As far as I know, google does not provide one, but they do exist like jQuery UI's auto-complete.
EDIT:
If you are using their custom search API view here for autocomplete.