Adding a new search engine through a firefox restartless extension using SDK - firefox-addon

I wanted to add a new search engine to be displayed in the drop down for search bar that appears in firefox nav-bar. And set this as the default searchEngine when user sets it through my extension's preferences.
For a non-restartless extension, through XUL, we use Components to do something like this:
Cc["#mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService).addEngineWithDetails(...); //Adds a new search engine
Cc["#mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService).currentEngine = ...; //sets the current search engine value.
How can I do something similar in a restartless extension created using Firefox addon-sdk? One problem I see is that there is no stable API to get and set firefox preferences listed at 'about:config'. But even if I use the unstable preferences service documented here, I am not able to do default search engine changes through extension. Help please!

Search in Firefox has two pieces you have to worry about.
First for the Search Input
You're actually going to use the same system for setting the search engine but you'll need to load the chrome module in the SDK.
var { Cc, Ci } = require("chrome");
var SearchService = Cc["#mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
// Add your engine to the list of engines in the drop down
SearchService.addEngineWithDetails('yoursearch', 'icon', 'yoursearchalias', 'your search description', 'get', 'http://stackoverflow.com/search?q={searchTerms}');
// Set your engine as the currentEngine so it's the default engine for the search input
SearchService.currentEngine = SearchService.getEngineByName('yoursearch');
Next for the URL bar
Update: As of Firefox 23 the keyword.URL preference has no effect, the above code will change the default behavior in both areas.
If you wanted to alter the search engine that's used for the URL bar you'll have to work with the user preferences.
var preferences = require('sdk/preferences/service');
// the 'search keyword' will be appended to the url you provide so strip out the
// {searchTerms} OpenSearch identifier
preferences.set('keyword.URL', 'http://stackoverflow.com/search?q=');
// When you want to set things back just reset the value
preferences.reset('keyword.URL');
Good luck!

Related

Set the Visitor ID in Adobe Analytics through DTM

I'm trying to set the Visitor ID in Adobe Analytics through DTM.
Above the s_code I have:
var visitor = new Visitor("xxxx")
visitor.trackingServer = "xxx.xx.xx.omtrdc.net"
I've created a data element where the legacy code used to call the
Visitor.getInstance("xxxx");
and set the Visitor ID to %Visitor ID%
That's not working however, and my visitor ID is always just set to %Visitor ID% and obviously not reading any values. I'd really appreciate any input that someone can give me.
Thanks,
Mike
The Visitor ID pops s.visitorID and is in general related to visitor id, but is not the same as s.visitor which is what gets popped for the VisitorAPI integration. DTM does not currently have a built-in field for the s.visitor variable, so you will have to set it yourself within the config, either in the Library Management code editor (assuming you are opting to c/p the core lib and not the "Managed by Adobe" option) or else in the Custom Page Code section.
Since you are popping it in a data layer first, you can reference the data layer like this:
s.visitor = _satellite.getVar('Visitor ID');
NOTE: A separate potential issue you may have is with whether or not the Visitor object is available for your data element. Since data elements are the first thing to be evaluated by DTM, you will need to ensure that the VisitorAPI.js library is output before your top page DTM script include.
If this is a problem for you, or if you are wanting to host VisitorAPI.js within DTM, then you may need to adjust where you are popping that stuff. For example, place the VisitorAPI core code above the custom code as the first stuff within the data element, before:
var visitor = new Visitor("xxxx") visitor.trackingServer = "xxx.xx.xx.omtrdc.net
Or, don't use the data element at all. Instead, put the VisitorAPI code within the Adobe Analytics custom code or core lib section and pop all that stuff (aboove the s.visitor assignment). Or a number of other methods; point is, VisitorAPI stuff must be loaded before the data element can make use of it, same as it must be loaded before Adobe Analytics can make use of it.
So DTM is changing pretty fast and furious right now. They have a "Marketing Cloud Service ID" that works well. Before I used that, however, I did find a way to fix the code. Crayon Violent was right, as usual, that the problem was that the script wasn't available yet. I fixed this by putting the following code in between the VisitorAPI.js and the AppMeasurement stuff in the DTM managed library.
var aA = new AppMeasurement();
aA.visitorNamespace="companyname";
aA.visitor = Visitor.getInstance("companyname");
In addition, there were also some issues using my localhost for testing while trying to see if I had this correct or not. If you are having issues and think you have it correct, it may be worthwhile to elevate it to a different environment.

Automatically populating default issue fields?

We are working on transitioning to Zephyr for JIRA from HP QC/QTP; but a tiny wiggle has presented itself:
When creating a new issue from a test run; the tester has to manually enter version info for the new defect, which on its own is fine, but it's an additional step, and on occasion forgotten.
What we would like then, is for the field "Affects Version/s" to be automatically filled based on either the state of the project, or the sepcific values set in fields in the test.
How can this be achieved?
Allright. You can add custom javascript to JIRA by going to JIRA Administration -> System -> User Interface -> Announcement Banner.
The easiest way is to add a tag linking to your javascript file (wherever it is, must be available to all users. Preferably on the same server as your JIRA installation or a public domain).
Example:
<script type="text/javascript" src="http://YOUR_JIRA_SERVER/includes/custom/javascript/custom.js"></script>
If you add it like above, go into your JIRA installation into the atlassian-jira/includes/ folder and add a folder called custom within which you add another folder called javascript and create a file called custom.js.
In that file, add the following code:
AJS.$(document).ready(function()
{
AJS.$(document.body).on('change', '#issuetype-field', function()
{
var issuetype = AJS.$(this).val();
if(issuetype === "Test") //Might want to change this!
{
AJS.$("#fixVersions").val(17403); //Might want to change this!
}
});
});
This will add an eventlistener to the issuetype-field input found in the create modal window in JIRA. When it changes (which it automatically does on load, then on every user select) it check its value to see if it's Test and if so changes the fixVersion input to a whatever you want to set it to (change this to match your own preferences).
Using jQuery with jira is a bit tricky, you need to use the AJS object to access the jQuery object (more information here: https://docs.atlassian.com/aui/latest/docs/applicationHeader.html).
The two parts you need to change are the actual names and values of your issuetype and your fix version (use firebug or your browsers equivalent to get this).
I've tried this and it worked well! Good luck!

How do I localize the interface of Google Custom Search Control

I'm using Google Custom Search with a CustomSearchControl to display search results for a website. I can get the search results localized, and can add a localized no results string without problems. However, I cannot get the search box itself to become localized, i.e. the "Search" button and "XXX results".
The Google documentation CustomSearchControl doesn't mention any way to achieve this. Isn't this possible?
Here is the code I'm using.
google.load('search', '1', {language : 'is', style : google.loader.themes.MINIMALIST});
google.setOnLoadCallback(function() {
var customSearchControl = new google.search.CustomSearchControl('MY_ID');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.setNoResultsString("Ekkert fannst.");
customSearchControl.draw('cse');
var queryFromUrl = parseQueryFromUrl();
if (queryFromUrl) {
customSearchControl.execute(queryFromUrl);
}
}, true);
Official response from Google support
I would like to update that currently for custom search element V2 code, you can change the search engine language only from the control panel->Basics->Language section. Whatever language you select it will be the same in all of your multilingual sites. You can't have different languages in different sites. Currently we don't have any parameter such as "language" in the Google Site Search code snippet to customize the language.
In your case you can consider creating different search engine for different languages and change the Language setting in Control Panel --> Setup --> Basics --> Language in all the search engine respectively and share the query quota by adding the search engine in the Business group.
Once you do that all these free search engines will share the query quota of your master GSS search engine.
After that, you can configure each search engine with respective sites/URL pattern only and implement the specific search engines on respective sites.
Please review the document below to know about Language settings
https://support.google.com/customsearch/answer/2633296?hl=en
Please review the document below know about business group:
https://support.google.com/customsearch/answer/2633350?hl=en
With the CSE Element v2, the search button becomes an icon, so there is no need to localize, if you switch to v2.

Displaying how often an issue has been reopen in JIRA

I'm currently running a fairly out-of-the-box JIRA setup that is live and being used.
Now I'm at a point where I would like a custom field in each bug that will display the total amount of times and issue/bug has been reopened.
There is a plugin (https://answers.atlassian.com/questions/19665/how-to-count-based-on-status-jira) that does something similar, however, I am looking for a solution that doesn't require purchasing a third-party plugin (OPS doesn't like plugins).
I've searched forums high and low and was unable to even find a good starting point. Your help is always appreciated. Thanks in advance!
EDIT: Current JIRA version: 5.2
Create a custom field for counting the times an issue was opened, and set it's default value to one. Then use the Behaviours Plugin to add validation script to the transitions you wish to count. In the validation script, increment the custom field and return true. should be something like:
FormField formComponent = getFieldById(fieldChanged)
FormField formUserField = getFieldByName("UserFieldA"
formUserField.setFormValue(Integer.valueOf(formUserField.getFormValue()) + 1)
If you're having trouble coding that have a look here or ask here.
An easier way would be to attack a post-function to the re-open transition using
Jira Scripting Suite and use it to increment the field, but it doesn't support Jira 5.2 yet.
If you don't want to use any plugins, you can use Webhooks attached to the re-open workflow transition that will post to an URL , which in turn, will connect back using the REST API and increment that field.
A Custom field holds some information (metric, counter, misc. info, etc.) but it is not logic by itself. So the problem here is that in order to increment a (custom) field you will have to have some logic doing that. So you're left with three options:
Use the plugin you're talking about
Custom-build a plugin for this
Use a custom-built external application utilizing the REST API that polls for changes on issues and when it detects "Reopenings" and increments the custom field's value.
Manually assign this field (not really an option)
So at the end there aren't that many options that do not require resouces - development or purchasing some plugin. Usually it's best to buy a plugin because you're also buying support with that. However beware that if the plugin is not developed by Atlassian there is the possibility that it may not support future JIRA versions or it may not be compatible right after a new JIRA version release.
My solution is to add the post-function to the 'Reopen' transition with the following code (it assumes you have Script Runner plugin installed and enabled; also you have to add custom field 'Reopen count' to the corresponding view screen):
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
def componentManager = ComponentManager.getInstance()
def customFieldManager = componentManager.getCustomFieldManager()
def reopenCount = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Reopen count'}
def changeHolder = new DefaultIssueChangeHolder();
def reopenCountValue = issue.getCustomFieldValue(reopenCount)
if(reopenCountValue == null) reopenCountValue = 0.0d
reopenCount.updateValue(
null,
issue,
new ModifiedValue(
reopenCountValue,
++reopenCountValue
),
changeHolder
);

Firefox extension trying to insert chrome:// image into page

I'm working on a firefox extension and I am trying to make it add an image stored with the extension (the kind that you access using chrome://, although I'm not sure if there is an official name)
body.innerHTML+="<div style=\"position:fixed;top:0em;left:0em;background-color:white;\"><img src=\"chrome://tumblrscrollr/content/save.png\" /></div>";
This should put save.png at the top left of the page, however nothing appears there (not even the white background). If I replace chrome://tumblrscrollr/content/save.png with a url on the internet, the image displays properly. If I visit chrome://tumblrscrollr/content/save.png directly in the address bar, it displays fine. I assume there's some security thing or something going on that doesn't allow an img tag in a page to access an extension's files, but since google doesn't support symbols and any search for 'chrome' just returns the browser, I am finding it very hard to find any answer.
You need to use the contentaccessible flag for the tumblrscrollr chrome package, this will allow web pages to use its images. Meaning that your chrome.manifest file should have a line like this:
content tumblrscrollr foo/bar contentaccessible=yes
Note that this flag always has to be specified on the content entry but it affects any address starting with chrome://tumblrscrollr/ meaning also chrome://tumblrscrollr/skin/ for example.
Btw, you shouldn't add elements like that - this makes the browser to parse the entire document body again which is slow and might cause all kinds of side-effects. If you need to add a single element then just create that element and add it, e.g.:
var element = body.ownerDocument.createElement("div");
element.setAttribute("style", "position:fixed;top:0em;left:0em;background-color:white;");
element.innerHTML = "<img src=\"chrome://tumblrscrollr/content/save.png\" />";
body.appendChild(element);

Resources