What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

I've written a basic stackoverflow ubiquity command.

The initial version refused to execute properly because one of the parameters was not in the correct format. Specifically the postData parameter to browser.loadURI and browser.loadOneTab needs to be a nsIMIMEInputStream object which shog9 pointed out.

The working version of code follows which can also be found at: http://www.appidx.com/ubiq/stackoverflow.js and installed (if you already have ubiquity) by visiting: http://www.appidx.com/ubiq/stackoverflow.html

Enjoy, Cheers!

CmdUtils.CreateCommand({
  name: "stackoverflow",
  author: {name: "Aryeh Goldsmith"},
  homepage: "http://www.appidx.com/ubiq/stackoverflow.html",
  icon: "http://stackoverflow.com/favicon.ico",
  takes: {search: noun_arb_text},
  license: "MPL",
  description: "Searches the highlighted text on stackoverflow.",
  _version: "55",

  preview: function ( pblock, inputObject) {
    var query = inputObject.text;
    pblock.innerHTML = "Search beta.stackoverflow.com for " + query + "<br/>";

    var url = "http://beta.stackoverflow.com/search";
    params = {"search-text": query, "hiddenstuff": ''};

    jQuery.post( url, params, function( html ) {
      var $ = jQuery;
      pblock.innerHTML += "<div style='display:none;'>" + html + "</div>";
      var links = $(pblock).find('.summary h3 a');
      links.each(function (i) {
            if (this.href.match(/^chrome/)) {
              this.href = this.href.replace(/chrome\:\/\/ubiquity/i, "http://beta.stackoverflow.com");
            } else if (this.href.match(/^\//)) {
              this.href = "http://beta.stackoverflow.com" + this.href;
            }

            this.target = "_blank";
        });

      var ques = $(pblock).find('.summary h3');
      var details = $(pblock).find('.summary .excerpt');
      var out = "<div style='margin-bottom: 6px;'><b>Previewing the first 5 results:</b></div>";
      for (var j = 0; j< ques.size() && j < 5; j++) {
        out += "<div style='padding: 5px;'><b>" + ques[j].innerHTML + "</b><br />";
        out += details[j].innerHTML + "</div>";
      }
      pblock.innerHTML = out;
    });
    },

  execute: function( inputObject ) {
    var query = inputObject.text;
    var url = "http://beta.stackoverflow.com/search";
    var params = {
      "search-text": query,
      hiddenstuff: ""
    };

    var dataString = Utils.paramsToString(params).substring(1);

    var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].
                  getService(Components.interfaces.nsIWindowMediator);
    var browserWindow = windowManager.getMostRecentWindow("navigator:browser");
    var browser = browserWindow.getBrowser();


    var stringStream = Components.classes["@mozilla.org/io/string-input-stream;1"].
                   createInstance(Components.interfaces.nsIStringInputStream);
    if ("data" in stringStream) // Gecko 1.9 or newer
      stringStream.data = dataString;
    else // 1.8 or older
      stringStream.setData(dataString, dataString.length);

    var postData = Components.classes["@mozilla.org/network/mime-input-stream;1"].
               createInstance(Components.interfaces.nsIMIMEInputStream);
    postData.addHeader("Content-Type", "application/x-www-form-urlencoded");
    postData.addContentLength = true;
    postData.setData(stringStream);


    if(browser.mCurrentBrowser.currentURI.spec == "about:blank")
      browserWindow.loadURI(url, null, postData, false);
    else
      browser.loadOneTab(url, null, null, postData, false, false);
  },
})
share

migration rejected from stackoverflow.com Sep 8 at 16:41

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by Shadow Wizard, Sompuperoo, Martijn Pieters, Monica Cellio, ProgramFOX Sep 8 at 16:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question pertains only to a specific site in the Stack Exchange Network. Questions on Meta Stack Exchange should pertain to our network or software that drives it as a whole, within the guidelines defined in the help center. You should ask this question on the meta site where your concern originated." – Shadow Wizard, Sompuperoo, Martijn Pieters, Monica Cellio, ProgramFOX
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Domain redirects to a domain speculator. –  Fish Below the Ice Sep 8 at 13:33

Browse other questions tagged .