[Ext] userChrome.js

Announce and Discuss the Latest Theme and Extension Releases.
Locked
old zeniko
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old zeniko »

Another new code snippet: Prominent Domain, an adaptation of the new Locationbar² extension which highlights the domain name in the address bar.

Update: I've additionally updated the Sub-Script Loader snippet to automatically include all files ending in .uc.xul as well. It now completely replaces the original userChrome.xul snippet.
User avatar
aaron
Posts: 3130
Joined: November 4th, 2002, 8:49 pm
Location: Texas
Contact:

Post by aaron »

Any way that I could modify the "Search web for 'xxxx'..." context-menu item in SeaMonkey? In Firefox, it opens in a new background tab but in SeaMonkey it opens in a new window. I'd like it to be able to open in a new background tab as well.
User avatar
Philip Chee
Posts: 6475
Joined: March 1st, 2005, 3:03 pm
Contact:

Post by Philip Chee »

aaron wrote:Any way that I could modify the "Search web for 'xxxx'..." context-menu item in SeaMonkey? In Firefox, it opens in a new background tab but in SeaMonkey it opens in a new window. I'd like it to be able to open in a new background tab as well.
All you need to do is to change

Code: Select all

browser.search.opentabforcontextsearch
from false to true.

Phil
User avatar
aaron
Posts: 3130
Joined: November 4th, 2002, 8:49 pm
Location: Texas
Contact:

Post by aaron »

Phil, that may be something that works for the new 1.1 beta of SeaMonkey, but it doesn't work for 1.0.x -- I didn't have that pref, and then when I added it, nothing changed.
User avatar
Philip Chee
Posts: 6475
Joined: March 1st, 2005, 3:03 pm
Contact:

Post by Philip Chee »

aaron wrote:Phil, that may be something that works for the new 1.1 beta of SeaMonkey, but it doesn't work for 1.0.x -- I didn't have that pref, and then when I added it, nothing changed.
It looks like I'm using Context Search for Seamonkey which by default opens the search results in a new tab. SHIFT-CLICK to open a new window. And this extension is supposed to honour "browser.tabs.loadInBackground" as well. Hmm I think I need to fix it so that it recognizes "browser.search.opentabforcontextsearch " too.

Phil
User avatar
aaron
Posts: 3130
Joined: November 4th, 2002, 8:49 pm
Location: Texas
Contact:

Post by aaron »

Fairly nice, but it makes me select the search engine to search with each time. Would like it better if it respected the default search engine...
pile0nades
Posts: 756
Joined: May 15th, 2005, 2:31 am

Post by pile0nades »

zeniko wrote:Update: I've additionally updated the Sub-Script Loader snippet to automatically include all files ending in .uc.xul as well. It now completely replaces the original userChrome.xul snippet.


That code is affected by bug 355038. It breaks if document.loadOverlay is called more than once in succession; the XUL files won't load. That's why my code had a setTimeout calling a seperate function to load the XULs as a workaround.

<a href="data:text/javascript;charset=utf-8;base64,LyogOjo6Ojo6OjogU3ViLVhVTC9TY3JpcHQgTG9hZGVyIDo6Ojo6Ojo6Ojo6Ojo6OiAqLw0KDQovLyBhdXRvbWF0aWNhbGx5IGluY2x1ZGVzIGFsbCBmaWxlcyBlbmRpbmcgaW4gLnVjLnh1bCBhbmQgLnVjLmpzIGZyb20gdGhlIHByb2ZpbGUncyBjaHJvbWUgZm9sZGVyDQoNCihmdW5jdGlvbigpIHsNCiAgdmFyIGNocm9tZURpciA9IENvbXBvbmVudHMuY2xhc3Nlc1siQG1vemlsbGEub3JnL2ZpbGUvZGlyZWN0b3J5X3NlcnZpY2U7MSJdLmdldFNlcnZpY2UoQ29tcG9uZW50cy5pbnRlcmZhY2VzLm5zSVByb3BlcnRpZXMpLmdldCgiVUNocm0iLCBDb21wb25lbnRzLmludGVyZmFjZXMubnNJTG9jYWxGaWxlKTsNCiAgdmFyIGZpbGVzID0gY2hyb21lRGlyLmRpcmVjdG9yeUVudHJpZXMuUXVlcnlJbnRlcmZhY2UoQ29tcG9uZW50cy5pbnRlcmZhY2VzLm5zSVNpbXBsZUVudW1lcmF0b3IpOw0KICBpZihmaWxlcy5oYXNNb3JlRWxlbWVudHMoKSkgbG9hZFhVTG9ySlMoZmlsZXMpOw0KDQogIGZ1bmN0aW9uIGxvYWRYVUxvckpTKGZpbGVzKSB7DQogICAgdmFyIGZpbGUgPSBmaWxlcy5nZXROZXh0KCkuUXVlcnlJbnRlcmZhY2UoQ29tcG9uZW50cy5pbnRlcmZhY2VzLm5zSUZpbGUpOw0KICAgIGlmICgvKF51c2VyQ2hyb21lfFwudWMpXC54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ug 258287
User avatar
aaron
Posts: 3130
Joined: November 4th, 2002, 8:49 pm
Location: Texas
Contact:

Post by aaron »

I found some more information about the context search for SeaMonkey -- perhaps this will enable someone to tell me how I can modify the behavior to open in a new, unfocused, tab instead of a new window for context searches.

The CSS name of the item is #context-searchselect, and the oncommand attribute is OpenSearch('internet', gContextMenu.searchSelected(), true);. The code for the OpenSearch function can be found in the navigator.js file and is listed below. I believe that by modifying the window.open(defaultSearchURL, "_blank"); line, it could open results in a new, unfocused, tab -- but I'm unsure how to override this behavior with userchrome.js.

Code: Select all

function OpenSearch(tabName, searchStr, newWindowFlag)
{
  //This function needs to be split up someday.

  var autoOpenSearchPanel = false;
  var defaultSearchURL = null;
  var fallbackDefaultSearchURL = gNavigatorRegionBundle.getString("fallbackDefaultSearchURL");
  ensureSearchPref()
  //Check to see if search string contains "://" or "ftp." or white space.
  //If it does treat as url and match for pattern
 
  var urlmatch= /(:\/\/|^ftp\.)[^ \S]+$/
  var forceAsURL = urlmatch.test(searchStr);

  try {
    autoOpenSearchPanel = pref.getBoolPref("browser.search.opensidebarsearchpanel");
    defaultSearchURL = pref.getComplexValue("browser.search.defaulturl",
                                            Components.interfaces.nsIPrefLocalizedString).data;
  } catch (ex) {
  }

  // Fallback to a default url (one that we can get sidebar search results for)
  if (!defaultSearchURL)
    defaultSearchURL = fallbackDefaultSearchURL;

  if (!searchStr) {
    BrowserSearchInternet();
  } else {

    //Check to see if location bar field is a url
    //If it is a url go to URL.  A Url is "://" or "." as commented above
    //Otherwise search on entry
    if (forceAsURL) {
       BrowserLoadURL()
    } else {
      if (searchStr) {
        var escapedSearchStr = encodeURIComponent(searchStr);
        defaultSearchURL += escapedSearchStr;
        var searchDS = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
                                 .getService(Components.interfaces.nsIInternetSearchService);

        searchDS.RememberLastSearchText(escapedSearchStr);
        try {
          var searchEngineURI = pref.getCharPref("browser.search.defaultengine");
          if (searchEngineURI) {         
            var searchURL = getSearchUrl("actionButton");
            if (searchURL) {
              defaultSearchURL = searchURL + escapedSearchStr;
            } else {
              searchURL = searchDS.GetInternetSearchURL(searchEngineURI, escapedSearchStr, 0, 0, {value:0});
              if (searchURL)
                defaultSearchURL = searchURL;
            }
          }
        } catch (ex) {
        }

        if (!newWindowFlag)
          loadURI(defaultSearchURL);
        else
          window.open(defaultSearchURL, "_blank");
      }
    }
  }

  // should we try and open up the sidebar to show the "Search Results" panel?
  if (autoOpenSearchPanel)
    RevealSearchPanel();
}
pile0nades
Posts: 756
Joined: May 15th, 2005, 2:31 am

Post by pile0nades »

Preserve toolbar icon size in Fullscreen mode

I wrote this because I was annoyed that my toolbar icons were turned small when entering Fullscreen. It actually made my toolbar become 1 or 2 pixels taller.

<a href="data:text/javascript;charset=utf-8;base64,ZXZhbCgiRnVsbFNjcmVlbi5zaG93WFVMQ2hyb21lID0gIiArIEZ1bGxTY3JlZW4uc2hvd1hVTENocm9tZS50b1N0cmluZygpLnJlcGxhY2UoImVsc1tpXS5zZXRBdHRyaWJ1dGUoXCJpY29uc2l6ZVwiLCBcInNtYWxsXCIpOyIsICIiKSk7">fullscreensizemode.uc.js</a>
Linkify bug numbers - test: bug 258287
max1million
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Post by max1million »

aaron if you want to just edit what you got there, try changing
window.open(defaultSearchURL, "_blank");
to gBrowser.addTab(defaultSearchURL);

if you wanted it selected
gBrowser.selectedTab = gBrowser.addTab(defaultSearchURL);
User avatar
aaron
Posts: 3130
Joined: November 4th, 2002, 8:49 pm
Location: Texas
Contact:

Post by aaron »

Thanks for the tip Max. I'd have to edit the navigator.js file right? Any way that I could do this with some userchrome.js code so I don't have to re-do it when I update SeaMonkey?
max1million
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Post by max1million »

I was under the impression that code was part of an extension and you could just change that. You can override a browser's function using an extension (I read somewhere, don't remember) by overlaying it with the new (edited) function. It was not recommended because the code changes between versions. Perhaps someone else has the specifics for you. There may be another method.
User avatar
dougeeebear
Posts: 548
Joined: September 15th, 2005, 4:17 pm

Post by dougeeebear »

I posted this question in the Custom Buttons extension thread, but then I thought maybe this might be a more appropriate place.

I was wondering if it would be possible to create a userChrome.js hack that would open the custom buttons editor in a new tab when editing an existing button or creating a new button?
This would be the ideal situation for me.

Thanks,
Doug
old zeniko
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post by old zeniko »

aaron wrote:Any way that I could do this with some userchrome.js code so I don't have to re-do it when I update SeaMonkey?

It seems that you're after the following line:

Code: Select all

eval("OpenSearch = " + OpenSearch.toString().replace('window.open(defaultSearchURL, "_blank");', 'gBrowser.addTab(defaultSearchURL);'));
User avatar
aaron
Posts: 3130
Joined: November 4th, 2002, 8:49 pm
Location: Texas
Contact:

Post by aaron »

Zenizko -- that's EXACTLY what I was looking for! Thank you, sir!
Locked