PageRenderTime 59ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/ubiquity.js

https://github.com/cosimo/ubiquity-opera
JavaScript | 2149 lines | 1760 code | 221 blank | 168 comment | 219 complexity | 316a5a79e4589dff2213320e9a6c766f MD5 | raw file
  1. //
  2. // Ubiquity for Opera? A nightly experiment...
  3. // http://github.com/cosimo/ubiquity-opera/
  4. // -------------------------------------------
  5. //
  6. // An attempt to rewrite Firefox's Ubiquity extension
  7. // for Opera using UserJS.
  8. //
  9. // Original Ubiquity Project: http://labs.mozilla.org/ubiquity/
  10. //
  11. // To use this in Opera, you need to:
  12. //
  13. // * Enable UserJS. Point your browser to opera:config#Javascript and:
  14. //
  15. // - tick "User Javascript" checkbox
  16. // - type the folder you want to run the scripts from
  17. // in the "User Javascript File" textfield
  18. //
  19. // If you want, you can also allow UserJS execution in
  20. // HTTPS pages.
  21. //
  22. // * Remove the default shortcut key bound to CTRL + SPACE,
  23. // since the original Ubiquity is activated and deactivated
  24. // with CTRL + SPACE.
  25. //
  26. // Have fun!
  27. //
  28. // ----------------------------------------------
  29. // Cosimo Streppone, <cosimo@opera.com>
  30. // First version: 19/01/2009
  31. // ----------------------------------------------
  32. //
  33. // Includes a-lib-stacktrace.js and a-lib-xmlhttp-cd.js
  34. // Copyright © 2007 by João Eiras.
  35. // ----------------------------------------------
  36. ;
  37. // -------------------------------------
  38. // ==UserScript==
  39. // @name Stack Trace getter
  40. // @author Joao Eiras
  41. // @ujs:modified 2007-04-11
  42. // ==/UserScript==
  43. // -------------------------------------
  44. (function(opera) {
  45. if (!opera) return;
  46. //caching native functions - overriding these can make the script
  47. //break, which therefore can't be trusted for security
  48. var RegExp_test = RegExp.prototype.test;
  49. var RegExp_exec = RegExp.prototype.exec;
  50. var String_split = String.prototype.split;
  51. var Function_call = Function.prototype.call;
  52. function extend(object,fields_src){
  53. for(var prop in fields_src){
  54. try{
  55. object[prop] = fields_src[prop];
  56. }catch(ex){}
  57. }
  58. return object;
  59. };
  60. //types of places where scripts run
  61. var scriptTypes = {
  62. UNKNOWN : 0,
  63. INLINE : 1,
  64. LINKED : 2,
  65. USERJS : 3,
  66. EVAL : 4
  67. };
  68. function scriptTypeToString(t){
  69. switch(t){
  70. case scriptTypes.INLINE :return 'inline script';
  71. case scriptTypes.LINKED :return 'linked script';
  72. case scriptTypes.USERJS :return 'UserJS';
  73. case scriptTypes.EVAL :return 'eval';
  74. case scriptTypes.UNKNOWN:return 'unknown';
  75. }
  76. return t;
  77. };
  78. function StackTrace(){
  79. extend(this,[]);//in case of prototype editing...Array.prototype can change though
  80. //using this.fname = function(){} is safer that prototype, because
  81. //this way methods in the prototype aren't overriden
  82. this.toString = function(){
  83. var s='';
  84. for(var k=0; k<this.length; k++)
  85. s += this[k].toString('\t')+',\n';
  86. return '[object StackTrace]{\n'+s.substring(0,s.length-2)+'\n}';
  87. };
  88. this.toSmallString = function(){
  89. var s='';
  90. for(var k=0; k<this.length; k++)
  91. s += this[k].toSmallString('\t')+',\n';
  92. return '{\n'+s.substring(0,s.length-2)+'\n}';
  93. };
  94. this.UserJsOnly = function(){
  95. //yes eval can be called from userjs, but it can too be called from a page script, and it's not detectable
  96. //and eval can easily be workarounded
  97. //the last element is skipped because it's always unknown when functions are called by the event dispatcher
  98. //a regular page can too set up a event listener, but it can't wrap the function call
  99. for(var k=0; k<this.length; k++){
  100. if( k == (this.length - 1) )//for timers, event listeners or address bar
  101. if( this[k].type == scriptTypes.UNKNOWN )
  102. return true;
  103. if( this[k].type != scriptTypes.USERJS )
  104. return false;
  105. }
  106. return true;
  107. };
  108. };
  109. //[] indexing operator can only be copied this way
  110. StackTrace.prototype = [];
  111. function StackTraceElement(line,type,src,expr){
  112. this.lineno = line||0;
  113. this.type = type||scriptTypes.UNKNOWN;
  114. this.src = src||'';
  115. this.expression = expr||'';
  116. this.typeToString=function(t){
  117. return scriptTypeToString(t||this.type);
  118. };
  119. this.toString = function(pad){
  120. if( typeof pad == 'undefined' )
  121. pad ='';
  122. return pad+'[object StackTraceElement]{\n'+
  123. pad+'\tLine '+this.lineno+'\n'+
  124. pad+'\tType '+this.typeToString()+'\n'+
  125. pad+'\tUrl: '+(this.src||'unknown location')+'\n'+
  126. pad+'\tExpression: \n\t\t'+this.expression+'\n'+
  127. pad+'}';
  128. };
  129. this.toSmallString = function(){
  130. return this.type == scriptTypes.UNKNOWN?
  131. '"'+this.expression+'" at unknown location':
  132. '"'+this.expression+'" at line '+this.lineno+' of '+this.typeToString()+' at '+(this.src||'unknown location');
  133. };
  134. //make constants accessible inside a instance
  135. extend(this,scriptTypes);
  136. };
  137. //make constants public
  138. extend(StackTraceElement,scriptTypes);
  139. StackTraceElement.typeToString = scriptTypeToString;
  140. var addUnknown = false;
  141. function getStackTrace(exception,prevStackTrace){
  142. RegExp_exec.call = RegExp_test.call = String_split.call = Function_call;
  143. function trim(s){ return (typeof s=='string')?s.replace(/^\s+/,'').replace(/\s+$/,''):s; }
  144. function clean(s){ return (typeof s=='string')?s.replace(/\s+/g,' '):s; }
  145. var skip = 0;
  146. if( arguments.length==0 )
  147. try{
  148. undefined()();
  149. }catch(ex){
  150. exception = ex;
  151. skip=2;
  152. }
  153. else if( !(exception instanceof Error) )
  154. return ['ERROR: wrong object type passed to opera.getStackTrace. Exception required'];
  155. var line_re = /\s*Line (\d+) of (User JS|inline#\d+|linked|eval|unknown) script( in)? (.*)?/;
  156. var unk_re = /At unknown location/;
  157. var parts = String_split.call(trim(exception.message), '\n');
  158. var str = new StackTrace();
  159. for(var k=2;k<parts.length;k++){
  160. if( RegExp_test.call(unk_re, parts[k]) ){
  161. //push can't be used...
  162. if( addUnknown )
  163. str[str.length++] = new StackTraceElement(0,scriptTypes.UNKNOWN,'',trim(parts[++k]).replace(/^\[(.*)\]$/,'$1'));
  164. else k++;
  165. continue;
  166. }
  167. if( !RegExp_exec.call(line_re, parts[k]) )
  168. continue;
  169. if( skip ){ skip--; continue; }
  170. var lineno = parseInt(RegExp.$1);
  171. var stype = RegExp.$2;
  172. var url = RegExp.$4||RegExp.$3;
  173. var expression = '';
  174. for(var m=k+1;m<parts.length && !RegExp_test.call(line_re, parts[m]) && !RegExp_test.call(unk_re, parts[m]);m++){
  175. expression += parts[m];
  176. }
  177. expression = clean(expression);
  178. if( stype=='User JS' ) stype = scriptTypes.USERJS;
  179. else if( stype.substring(0,6)=='inline' ) stype = scriptTypes.INLINE;
  180. else if( stype=='linked' ) stype = scriptTypes.LINKED;
  181. else if( stype=='eval' ) stype = scriptTypes.EVAL;
  182. else if( stype=='unknown' ) stype = scriptTypes.UNKNOWN;
  183. else stype = scriptTypes.UNKNOWN;
  184. //alert(str.length+' '+str[str.length]);
  185. if( stype != scriptTypes.UNKNOWN || addUnknown ){
  186. str[str.length++] = new StackTraceElement(lineno,stype,url,expression);
  187. }
  188. //str.length++;
  189. k=m-1;
  190. }
  191. if(prevStackTrace && prevStackTrace instanceof StackTrace){
  192. for(var k=0;str[k];k++)
  193. prevStackTrace[prevStackTrace.length++] = str[k];
  194. return prevStackTrace;
  195. }
  196. return str;
  197. }
  198. opera.getStackTrace = getStackTrace;
  199. }) (window.opera);
  200. // -------------------------------------
  201. // ==UserScript==
  202. // @name Cross-domain XMLHttpRequest
  203. // @author Joao Eiras
  204. // @ujs:modified 2009-10-01
  205. // ==/UserScript==
  206. // -------------------------------------
  207. (function(window, opera, document, dom_implementation) {
  208. if (!opera) return;
  209. /*
  210. Cross domain XMLHttpRequest implementation for Opera
  211. */
  212. var commonToken = "opera.XMLHttp.";
  213. var crossDocRequest = commonToken+"Request.";
  214. var crossDocResponse = commonToken+"Response.";
  215. var acknowledge = commonToken+"acknowledge.";
  216. var urlToken = "#opera-XMLHttp-tk-";
  217. var location = window.location;
  218. //all user js run once before any page script, therefore this is executed, all
  219. //opera.* functions and properties are the original ones, and not probable values
  220. //overridden by the current page
  221. var Function_call = Function.prototype.call;
  222. var setTimeout = window.setTimeout;
  223. var setInterval = window.setInterval;
  224. var clearInterval = window.clearInterval;
  225. var parseInt = window.parseInt;
  226. var postMessage = window.postMessage || window.document.postMessage;
  227. var opera_addEventListener = opera.addEventListener;
  228. var window_addEventListener = window.addEventListener;
  229. var opera_getStackTrace = opera.getStackTrace;
  230. var String_match = String.prototype.match;
  231. var String_replace = String.prototype.replace;
  232. var String_split = String.prototype.split;
  233. var String_substring = String.prototype.substring;
  234. var String_toLowerCase = String.prototype.toLowerCase;
  235. var String_toUpperCase = String.prototype.toUpperCase;
  236. var Array_push = Array.prototype.push;
  237. var Array_join = Array.prototype.join;
  238. var Array_splice = Array.prototype.splice;
  239. var Document_createDocumentFragment = Document.prototype.createDocumentFragment;
  240. var Document_createElement = Document.prototype.createElement;
  241. var Document_createElementNS = Document.prototype.createElementNS;
  242. var Document_createDocument = document.implementation.createDocument;
  243. var DOMParser = window.DOMParser;
  244. var DOMParser_parseFromString = DOMParser.prototype?DOMParser.prototype.parseFromString:new DOMParser().parseFromString;
  245. var escape = window.escape;
  246. var encodeURIComponent = window.encodeURIComponent;
  247. var unescape = window.unescape;
  248. var XMLHttpRequest = window.XMLHttpRequest;
  249. var XMLHttpRequest_abort = XMLHttpRequest.prototype.abort;
  250. var XMLHttpRequest_open = XMLHttpRequest.prototype.open;
  251. var XMLHttpRequest_send = XMLHttpRequest.prototype.send;
  252. var XMLHttpRequest_setRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
  253. var XMLHttpRequest_getResponseHeader = XMLHttpRequest.prototype.getResponseHeader;
  254. var XMLHttpRequest_getAllResponseHeaders = XMLHttpRequest.prototype.getAllResponseHeaders;
  255. var Event_preventDefault = Event.prototype.preventDefault
  256. var RegExp = window.RegExp;
  257. var RegExp_exec = RegExp.prototype.exec;
  258. var Math = window.Math;
  259. var Math_abs = Math.abs;
  260. var Math_random = Math.random;
  261. var Date = window.Date;
  262. var Date_getTime = Date.prototype.getTime;
  263. var Node_appendChild = Node.prototype.appendChild;
  264. var Node_removeChild = Node.prototype.removeChild;
  265. var DOMLoadedEventType = (opera.version() >= 9 ? 'DOMContentLoaded' : 'load');
  266. var documentLoaded = false;
  267. window_addEventListener.call(window,DOMLoadedEventType,function(){ documentLoaded = true; },false);
  268. var iskestrelup = (window.opera&&opera.version()>=9.5);
  269. function resetFunctionsCall(){
  270. setTimeout.call = parseInt.call = postMessage.call = opera_addEventListener.call =
  271. window_addEventListener.call = String_match.call = String_replace.call = String_split.call =
  272. String_substring.call = String_toLowerCase.call = String_toUpperCase.call = Array_push.call =
  273. Array_join.call = Array_splice.call = Document_createDocumentFragment.call =
  274. Document_createElement.call = Document_createElementNS.call = DOMParser_parseFromString.call =
  275. XMLHttpRequest_abort.call = XMLHttpRequest_open.call = XMLHttpRequest_send.call =
  276. XMLHttpRequest_setRequestHeader.call = XMLHttpRequest_getResponseHeader.call =
  277. XMLHttpRequest_getAllResponseHeaders.call = Event_preventDefault.call = RegExp_exec.call =
  278. Math_abs.call = Math_random.call = Date_getTime.call = Node_appendChild.call = Node_removeChild.call =
  279. Function_call;
  280. };
  281. function _throw(ex){
  282. setTimeout(function(){ throw ex; },1);
  283. }
  284. function callWrapped(obj,fn){
  285. if( typeof obj[fn] == 'function' )
  286. try{ return obj[fn](); }catch(ex){ _throw(ex); }
  287. }
  288. function parseDOM(markup,useDocument){
  289. if(!markup)
  290. return Document_createDocument.call(dom_implementation,null,null,null);
  291. try{
  292. markup = trimString(markup);
  293. var nd = DOMParser_parseFromString.call(new DOMParser(),
  294. (String_match.call(markup,/<!\s*doctype\b/i)?'':
  295. '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
  296. +markup,'text/xml');
  297. return useDocument?nd:nd.documentElement;//doctype for entities
  298. }catch(ex){
  299. try{
  300. var frag = Document_createDocumentFragment.call(document);
  301. var d = Document_createElement.call(document, String_match.call(markup,/<(\w+)\b/) ? RegExp.$1: 'html');
  302. if( typeof d.innerHTML == 'undefined' )
  303. return null;
  304. d.innerHTML = markup;
  305. if( !useDocument ){ return d; }
  306. var doc = Document_createDocument.call(dom_implementation,null,null,null);
  307. doc.appendChild(d);
  308. return doc;
  309. }catch(ex){
  310. return null;
  311. }
  312. }
  313. }
  314. function trimString(str){
  315. return String_replace.call(String_replace.call(str, /^\s+/,''),/\s+$/,'');
  316. }
  317. function serializeRequestHeaders(hdrs){
  318. var s = '';
  319. for(var k=0; k<hdrs.length; k++)//cookie style :) ';' is escaped too - great
  320. s += escape(hdrs[k].name)+'='+escape(hdrs[k].value)+';';
  321. return s;
  322. }
  323. function deSerializeRequestHeaders(hdrs){
  324. var all = String_split.call(hdrs,';'), ret=[];
  325. for(var k=0; k<all.length; k++){
  326. var crumbs = String_split.call(all[k],'=');
  327. if(crumbs.length==2)
  328. Array_push.call(ret,{name:unescape(crumbs[0]),value:unescape(crumbs[1])});
  329. }
  330. return ret;
  331. }
  332. function getAllXMLHttpHeaders( xmlhttp ){
  333. var allHeaders = '', ret = [];
  334. try{
  335. allHeaders = String_split.call(XMLHttpRequest_getAllResponseHeaders.call(xmlhttp),'\n');
  336. }catch(ex){}
  337. for(var k=0; k<allHeaders.length; k++){
  338. var crumbs = String_split.call(allHeaders[k],':');
  339. if(crumbs.length>=2){
  340. Array_push.call(ret,{name:trimString(crumbs[0]),
  341. value:trimString(Array_join.call(Array_splice.call(crumbs,1,crumbs.length-1),':'))});
  342. //,toString:function(){return '['+this.name+','+this.value+']\n';}
  343. }
  344. }
  345. return ret;
  346. }
  347. function checkScriptRights(){
  348. //tells if current executing script can use cross domain XMLHttp
  349. if( !opera_getStackTrace )
  350. throw new Error("opera.StackTrace module required for opera.XMLHttpRequest module");
  351. if( !opera_getStackTrace().UserJsOnly() )
  352. throw new Error("Security violation - user scripts only");
  353. }
  354. function cleanCurrentPage(){
  355. opera_addEventListener.call(opera,"BeforeExternalScript",function(ejs){resetFunctionsCall();Event_preventDefault.call(ejs);},false);
  356. opera_addEventListener.call(opera,"BeforeScript",function(ejs){resetFunctionsCall();Event_preventDefault.call(ejs);},false);
  357. opera_addEventListener.call(opera,"BeforeEventListener",function(ejs){resetFunctionsCall();Event_preventDefault.call(ejs);},false);
  358. opera_addEventListener.call(opera,"BeforeJavascriptURL",function(ejs){resetFunctionsCall();Event_preventDefault.call(ejs);},false);
  359. function doCleaning(){
  360. resetFunctionsCall();
  361. while( document.documentElement.firstChild )
  362. Node_removeChild.call(document.documentElement, document.documentElement.firstChild );
  363. }
  364. if( documentLoaded )
  365. doCleaning();
  366. else{
  367. if( opera.version() >= 9 ){
  368. window_addEventListener.call(window,DOMLoadedEventType,doCleaning,false);
  369. }
  370. else{
  371. var clean_n_calls = 0;
  372. var clean_interval;
  373. var clean_f = function(){
  374. doCleaning();
  375. clean_n_calls++;
  376. if( clean_n_calls == 20 )//10 seconds
  377. clearInterval(clean_interval);
  378. }
  379. clean_interval = setInterval(clean_f,500);
  380. window_addEventListener.call(window,DOMLoadedEventType,function(){clean_f();clearInterval(clean_interval);},false);
  381. }
  382. }
  383. }
  384. function resolveUrl(url){
  385. var a=Document_createElementNS.call(document,'http://www.w3.org/1999/xhtml','a');
  386. a.href=url;
  387. return a.href;
  388. }
  389. var dummyRequest = new XMLHttpRequest();
  390. function copyXMLHttpObjProperties(src,dest){
  391. for(var prop in src)
  392. if( !(prop in dummyRequest) || String_substring.call(prop,0,2)=='on' )
  393. dest[prop] = src[prop];
  394. }
  395. //the fetching iframe
  396. if( ts = RegExp_exec.call(new RegExp( urlToken+"(\\d+)$" ), location.href ) ){
  397. cleanCurrentPage();
  398. var ts = parseInt(ts[1]);
  399. function filterExcept(obj,prop){
  400. try{
  401. return obj[prop];
  402. }catch(ex){
  403. return undefined;
  404. }
  405. }
  406. opera_addEventListener.call(opera,'BeforeEvent.message',function(ev){
  407. resetFunctionsCall();
  408. if( !ev.event.data ){ return; }
  409. var data = String_split.call(ev.event.data, '\n');
  410. if( data[0]!=(crossDocRequest+ts) ){ return; }
  411. Event_preventDefault.call(ev);
  412. var method = data[1];
  413. var url = data[2];
  414. var username = data[3];
  415. var password = data[4];
  416. var postArgs = unescape(data[5]);
  417. var reqHeaders = deSerializeRequestHeaders(data[6]);
  418. var xmlhttp = new XMLHttpRequest();
  419. var evsource = ev.event.source;
  420. xmlhttp.onreadystatechange=function(){
  421. resetFunctionsCall();
  422. if( this.readyState >1 )
  423. postMessage.call( evsource,
  424. crossDocResponse+ts+'\n'+
  425. this.readyState+'\n'+
  426. escape(filterExcept(this,'responseText'))+'\n'+
  427. filterExcept(this,'status')+'\n'+
  428. filterExcept(this,'statusText')+'\n'+
  429. serializeRequestHeaders(getAllXMLHttpHeaders( this ))
  430. );
  431. };
  432. if(username&&password)
  433. XMLHttpRequest_open.call(xmlhttp,method,url,false,username,password);
  434. else
  435. XMLHttpRequest_open.call(xmlhttp,method,url,false);
  436. for(var k=0; k<reqHeaders.length; k++)
  437. try{
  438. XMLHttpRequest_setRequestHeader.call(xmlhttp,reqHeaders[k].name,reqHeaders[k].value);
  439. }catch(ex){}
  440. try{
  441. XMLHttpRequest_send.call(xmlhttp, postArgs);
  442. }catch(ex){
  443. postMessage.call( evsource, crossDocResponse+ts+'\nERROR\n'+ex.message );
  444. }
  445. },false);
  446. var target = iskestrelup ? window.parent : window.parent.document;
  447. postMessage.call( target, acknowledge+ts );
  448. }
  449. else{
  450. //holds the data needed for the beforevent.message listener
  451. var allRequestsData = {};
  452. var precompRE = {
  453. //req:new RegExp(crossDocRequest+"(\\d+)"),
  454. res:new RegExp("^"+crossDocResponse.replace(/\./g,'\.')+"(\\d+)"),
  455. ack:new RegExp("^"+acknowledge.replace(/\./g,'\.')+"(\\d+)")
  456. };
  457. opera_addEventListener.call(opera,'BeforeEvent.message',function(ev){
  458. if( !ev.event.data )
  459. return;
  460. resetFunctionsCall();
  461. if( String_match.call(ev.event.data, precompRE.res ) ){
  462. Event_preventDefault.call(ev);
  463. var ts = parseInt(RegExp.$1);
  464. allRequestsData[ts].getResponseListener(ev.event);
  465. }
  466. else if( String_match.call(ev.event.data, precompRE.ack ) ){
  467. Event_preventDefault.call(ev);
  468. var ts = parseInt(RegExp.$1);
  469. allRequestsData[ts].acknowledgeListener(ev.event);
  470. }
  471. else{return;}
  472. },false);
  473. function XMLHttpRequestCD(){
  474. checkScriptRights();
  475. resetFunctionsCall();
  476. //unique random number to filter messages
  477. var ts = Math_abs.call(Math,Date_getTime.call(new Date()) ^ (Math_random.call(Math)*0x7fffffff|0) );
  478. var request = new XMLHttpRequest();
  479. var requestHeaders = [];
  480. var responseHeaders = [];
  481. var requestAborted = false;
  482. var uri,hostname,port,protocol,username,password,method;
  483. var sent = false;
  484. var this_xmlhttp = this;
  485. var ifr = null;
  486. allRequestsData[ts] = {};
  487. this.toString = function(){ return "[object opera.XMLHttpRequest]"; }
  488. function isCrossDomain(){
  489. return location.hostname!=hostname ||
  490. location.port !=port ||
  491. location.protocol!=protocol;
  492. }
  493. this.timeout = 10000;//msec
  494. this.ontimeout = null;
  495. this.onreadystatechange = null;
  496. this.onload = null;
  497. this.open = function(p_method, p_uri, p_asyncFlag, p_username, p_password){
  498. checkScriptRights();
  499. resetFunctionsCall();
  500. requestAborted = false;
  501. protocol = "http:";
  502. hostname = "";
  503. port = "";
  504. method = p_method||'';
  505. uri = resolveUrl(p_uri||'');
  506. username = p_username||'';
  507. password = p_password||'';
  508. if( uri.match(/^((\w+:)\/\/?([^\/:]+)(:(\d+))?)\/(.*)$/) ){
  509. protocol = RegExp.$2;
  510. hostname = RegExp.$3;
  511. port = RegExp.$5||"";
  512. path = '/'+RegExp.$6;
  513. }else{
  514. throw new Error("URI resolution failed or unknown");
  515. }
  516. if( !isCrossDomain() ){
  517. copyXMLHttpObjProperties(this,request);
  518. if(username&&password)
  519. return XMLHttpRequest_open.call(request, method, uri, p_asyncFlag, username, password);
  520. else
  521. return XMLHttpRequest_open.call(request, method, uri, p_asyncFlag);
  522. }
  523. else{
  524. this_xmlhttp.readyState = 1;
  525. this_xmlhttp.status = 0;
  526. this_xmlhttp.statusText = '';
  527. this_xmlhttp.responseText = '';
  528. this_xmlhttp.responseXML = null;
  529. callWrapped(this_xmlhttp, 'onreadystatechange');
  530. }
  531. }
  532. this.setRequestHeader = function(hdr, val){
  533. checkScriptRights();
  534. resetFunctionsCall();
  535. if( !isCrossDomain() ){
  536. return XMLHttpRequest_setRequestHeader.call(request, hdr, val);
  537. };
  538. if( sent ){
  539. throw new Error("INVALID_STATE_ERR: setRequestHeader()");
  540. }else{
  541. for(var k=0; k<requestHeaders.length ;k++)
  542. if( String_toLowerCase.call(requestHeaders[k].name) == String_toLowerCase.call(''+hdr) ){
  543. requestHeaders[k].value = val;
  544. return;
  545. }
  546. Array_push.call(requestHeaders,{name:hdr,value:val});
  547. };
  548. };
  549. this.getResponseHeader = function(hdr){
  550. checkScriptRights();
  551. resetFunctionsCall();
  552. if( !isCrossDomain() ){
  553. return XMLHttpRequest_getResponseHeader.call(request,hdr);
  554. };
  555. if( sent && this.readyState > 2 ){
  556. for(var k=0; k<responseHeaders.length ;k++)
  557. if( String_toLowerCase.call(responseHeaders[k].name) == String_toLowerCase.call(''+hdr) )
  558. return responseHeaders[k].value;
  559. return null;
  560. }else{
  561. throw new Error("INVALID_STATE_ERR: getResponseHeader()");
  562. };
  563. };
  564. var opr_getAllResponseHeaders = this.getAllResponseHeaders = function(){
  565. checkScriptRights();
  566. resetFunctionsCall();
  567. if( !isCrossDomain() ){
  568. return XMLHttpRequest_getAllResponseHeaders.call(request);
  569. };
  570. if( sent && this.readyState > 2 ){
  571. var s = '';
  572. for(var k=0; k<responseHeaders.length ;k++)
  573. s += responseHeaders[k].name+': '+responseHeaders[k].value+'\n';
  574. return s;
  575. }else{
  576. throw new Error("INVALID_STATE_ERR: XHR::getAllResponseHeaders()");
  577. };
  578. };
  579. allRequestsData[ts].getResponseListener = function(ev){
  580. function u(o){ return o == 'undefined' ? undefined : o; }
  581. var data = String_split.call(ev.data,'\n');
  582. if( requestAborted )
  583. return;
  584. if( data.length==3 && data[1]=='ERROR' ){ throw data[2]; return; }
  585. this_xmlhttp.readyState = parseInt(data[1]);
  586. this_xmlhttp.responseText = this_xmlhttp.readyState<3?'':unescape(data[2]);
  587. try{
  588. if( this_xmlhttp.readyState<4 ){
  589. this_xmlhttp.responseXML = null;
  590. }
  591. else{
  592. this_xmlhttp.responseXML = parseDOM(this_xmlhttp.responseText,true);
  593. if( !this_xmlhttp.responseXML ){
  594. if(ifr)ifr.location.href = 'data:text/html,'+encodeURIComponent(this_xmlhttp.responseText);
  595. this_xmlhttp.responseXML = ifr.contentDocument;
  596. }
  597. }
  598. }catch(ex){
  599. this_xmlhttp.responseXML = null;
  600. }
  601. this_xmlhttp.status = parseInt(u(data[3])||0);
  602. this_xmlhttp.statusText = u(data[4])||'';
  603. responseHeaders = deSerializeRequestHeaders(data[5]);
  604. sent = true
  605. callWrapped( this_xmlhttp, 'onreadystatechange' );
  606. if( this_xmlhttp.readyState == 4 ){
  607. callWrapped( this_xmlhttp, 'onload' );
  608. if(ifr)ifr.style.display = 'none';
  609. };
  610. };
  611. this.abort = function(){
  612. checkScriptRights();
  613. resetFunctionsCall();
  614. if( isCrossDomain() ){
  615. requestAborted = true;
  616. }
  617. else{
  618. XMLHttpRequest_abort.call(request);
  619. };
  620. };
  621. this.send = function(args){
  622. checkScriptRights();
  623. resetFunctionsCall();
  624. if( !isCrossDomain() ){
  625. copyXMLHttpObjProperties(this,request);
  626. return XMLHttpRequest_send.call(request,args);
  627. }
  628. if( protocol != 'http:' && protocol != 'https:' )
  629. throw new Error("Unsupported protocol");
  630. var canTimeout = true;
  631. var self = this;
  632. allRequestsData[ts].acknowledgeListener = function(ev){
  633. canTimeout = false;
  634. opr_getAllResponseHeaders.call = Function_call;
  635. postMessage.call( ev.source,
  636. crossDocRequest+ts+'\n'+method+'\n'+uri+'\n'+
  637. username+'\n'+password+'\n'+escape(args||'')+'\n'+
  638. serializeRequestHeaders( requestHeaders )
  639. );
  640. }
  641. function sendRequest(){
  642. resetFunctionsCall();
  643. //these actions need the document to be able to append nodes
  644. var ifr = parseDOM('<iframe xmlns="http://www.w3.org/1999/xhtml" '+
  645. 'frameborder="0" style="width:0px;height:0px;visibility:hidden;position:absolute;left:-999em;"></iframe>');
  646. Node_appendChild.call(document.body||document.documentElement,ifr);
  647. ifr.src = uri+urlToken+ts;
  648. setTimeout(function(){
  649. if( canTimeout )
  650. callWrapped( this_xmlhttp, 'ontimeout' );
  651. },this_xmlhttp.timeout||10000);
  652. }
  653. if( documentLoaded )
  654. sendRequest();
  655. else
  656. window_addEventListener.call(window,DOMLoadedEventType,sendRequest,false);
  657. };
  658. }
  659. opera.XMLHttpRequest = XMLHttpRequestCD;
  660. }
  661. }) (window, window.opera, document, document.implementation);
  662. //
  663. // Ubuiquity.js
  664. //
  665. (function (opera) {
  666. if (! opera) return;
  667. // -----------------------------------------------
  668. //
  669. // Firefox Ubiquity emulation layer
  670. //
  671. // -----------------------------------------------
  672. //
  673. // CmdUtils
  674. //
  675. if (CmdUtils == undefined) var CmdUtils = {}
  676. noun_arb_text = 1;
  677. CmdUtils.VERSION = 0.01;
  678. CmdUtils.CommandList = new Array ();
  679. CmdUtils.CreateCommand = function CreateCommand (args) {
  680. var cmd_name = args['name'];
  681. var cmd_list = CmdUtils.CommandList;
  682. if (cmd_name in cmd_list) {
  683. return;
  684. }
  685. CmdUtils.CommandList.push(args);
  686. }
  687. CmdUtils.closeWindow = function closeWindow () { CmdUtils.getWindow().close(); }
  688. CmdUtils.getDocument = function getDocument () { return document; }
  689. CmdUtils.getLocation = function getLocation () { return CmdUtils.getDocument().location; }
  690. CmdUtils.getWindow = function getWindow () { return window; }
  691. CmdUtils.openWindow = function openWindow (url,name) {
  692. if (!name) {
  693. CmdUtils.getWindow().open(url);
  694. } else {
  695. CmdUtils.getWindow().open(url, name);
  696. }
  697. }
  698. // 2nd order function
  699. CmdUtils.SimpleUrlBasedCommand = function SimpleUrlBasedCommand (url) {
  700. if (! url) return;
  701. var search_func = function (directObj) {
  702. if (! directObj) return;
  703. var text = directObj.text;
  704. text = encodeURIComponent(text);
  705. url = url.replace('{text}', text);
  706. url = url.replace('{location}', CmdUtils.getLocation());
  707. CmdUtils.toggleUbiquityWindow();
  708. Utils.openUrlInBrowser(url);
  709. };
  710. return search_func;
  711. }
  712. CmdUtils.toggleUbiquityWindow = function toggleUbiquityWindow (w) {
  713. if (!w) w = ubiq_window;
  714. var vis = w.style.visibility;
  715. vis = (vis=='hidden') ? 'visible' : 'hidden';
  716. w.style.visibility=vis;
  717. return;
  718. }
  719. //
  720. // Utils
  721. //
  722. if (Utils==undefined) var Utils = {}
  723. Utils.openUrlInBrowser = function(url) {
  724. window.open(url);
  725. };
  726. //
  727. // Application
  728. //
  729. if (Application==undefined) var Application = {
  730. activeWindow: {
  731. activeTab: window
  732. }
  733. }
  734. var ubiq_window;
  735. var ubiq_selection;
  736. var ubiq_element;
  737. var ubiq_remote_server = 'http://people.opera.com/cosimo/ubiquity';
  738. var ubiq_selected_command;
  739. var ubiq_first_match;
  740. // Used to get css url of images and other resources
  741. function ubiq_url_for (path) {
  742. var url = 'url(';
  743. url += ubiq_remote_server;
  744. url += '/';
  745. url += path;
  746. url += ')';
  747. return url;
  748. }
  749. function ubiq_create_window () {
  750. var doc = window.document;
  751. var wnd = document.createElement('div');
  752. var stl = wnd.style;
  753. wnd.setAttribute('id', 'ubiq_window');
  754. stl.position='fixed';
  755. stl.left=1;
  756. stl.top=1;
  757. stl.visibility='hidden';
  758. stl.width='810px';
  759. stl.height='561px';
  760. stl.border='0';
  761. stl.padding='0';
  762. // Our window should appear on top of everything
  763. stl.zIndex='99999';
  764. stl.background = ubiq_url_for('ubiq_background.png');
  765. wnd.innerHTML = ubiq_start_mode();
  766. doc.body.appendChild(wnd);
  767. return wnd;
  768. }
  769. function ubiq_start_mode () {
  770. var input_style =
  771. 'border:0; padding:0; height:32px; margin-top:16px;'
  772. + 'margin-left:10px; background:none; color:black;'
  773. + 'font-family: Trebuchet MS, Arial, Helvetica; font-size: 28px;';
  774. var div_style = 'border:0; display:block; float:left; margin:0;';
  775. var results_panel_style = div_style +
  776. 'clear:both; text-align: left; padding-top:2px; font-size: 19px; '
  777. + 'font-weight: normal; color:white; height: 502px;';
  778. var html =
  779. '<div id="ubiq-input-panel" style="' + div_style + ';width:99%;height:55px">'
  780. + '<form id="ubiq1" onsubmit="return false">'
  781. + '<input autocomplete="off" id="ubiq_input" style="' + input_style +'" type="text" size="60" maxlength="500">'
  782. + '</form>'
  783. + '</div>'
  784. + '<br/>'
  785. + '<div id="ubiq-results-panel" style="width:100%;' + results_panel_style + '">'
  786. + ubiq_help()
  787. + '</div>'
  788. + '<div id="ubiq-command-tip" style="position:absolute;left:310px;top:65px;display:block;border:0;color:#ddd;font-family:Helvetica,Arial;font-style:italic;font-size:11pt"></div>'
  789. + '<div id="ubiq-command-preview" style="position:absolute;left:310px;top:85px;display:block;overflow:auto;border:0;color:#ddd;"></div>'
  790. ;
  791. return html;
  792. }
  793. function ubiq_show_preview (cmd) {
  794. var el = document.getElementById('ubiq-command-preview');
  795. if (! el) return;
  796. if (! cmd) {
  797. el.innerHTML = '';
  798. return;
  799. }
  800. preview_func = CmdUtils.CommandList[cmd]['preview'];
  801. if (typeof preview_func == 'string') {
  802. el.innerHTML = preview_func;
  803. }
  804. else {
  805. var directObj = {
  806. text: ubiq_command(),
  807. };
  808. preview_func(el, directObj);
  809. }
  810. return;
  811. }
  812. // ubiq_xml_http(url, function(ajax){
  813. // if (! ajax) return;
  814. // var text=ajax.responseText;
  815. // if (! text) return;
  816. // var preview_block=document.getElementById('ubiq-command-preview');
  817. // if (! preview_block) return;
  818. // preview_block.innerHTML=text;
  819. // });
  820. function ubiq_show_tip (tip) {
  821. var el = document.getElementById('ubiq-command-tip');
  822. if (! el) return;
  823. if (! tip) {
  824. el.innerHTML = '';
  825. return;
  826. }
  827. tip = CmdUtils.CommandList[tip]['description'];
  828. el.innerHTML = tip;
  829. return;
  830. }
  831. function ubiq_execute () {
  832. var cmd = ubiq_command();
  833. if (! cmd) return false;
  834. ubiq_dispatch_command(cmd);
  835. return false;
  836. }
  837. function ubiq_dispatch_command(line) {
  838. var words = line.split(' ');
  839. var cmd = words[0];
  840. var text;
  841. if (ubiq_selection) {
  842. text = ubiq_selection;
  843. } else {
  844. words.shift();
  845. text=words.join(' ');
  846. }
  847. // Expand match (typing 'go' will expand to 'google')
  848. cmd = ubiq_match_first_command(cmd);
  849. ubiq_replace_first_word(cmd);
  850. // Find command element
  851. var cmd_struct;
  852. for (var c in CmdUtils.CommandList) {
  853. var cmd_name = CmdUtils.CommandList[c]['name'];
  854. if (cmd_name == cmd) {
  855. cmd_struct = CmdUtils.CommandList[c];
  856. break;
  857. }
  858. }
  859. if (! cmd_struct) {
  860. return;
  861. }
  862. // Create a fake Ubiquity-like object, to pass to
  863. // command's "execute" function
  864. var cmd_func = cmd_struct['execute'];
  865. var direct_obj = { "text": text };
  866. // Run command's "execute" function
  867. cmd_func(direct_obj);
  868. return;
  869. }
  870. function ubiq_display_results (text) {
  871. var div=document.getElementById('ubiq-results-panel');
  872. if (! div) alert('no div!');
  873. div.innerHTML = text;
  874. div.style.visibility='show';
  875. }
  876. function ubiq_help () {
  877. var style = 'font-size:17px; padding:8px; font-weight:normal';
  878. var html = '<p style="' + style + '">Type the name of a command and press enter to execute it, or <b>help</b> for assistance.</p>';
  879. return html;
  880. }
  881. function ubiq_get_selection () {
  882. var str = '';
  883. if (document.getSelection) {
  884. str = document.getSelection();
  885. } else if (document.selection && document.selection.createRange) {
  886. var range = document.selection.createRange();
  887. str = range.text;
  888. }
  889. return (ubiq_selection = str);
  890. }
  891. function ubiq_toggle_window (w) {
  892. if (!w) w = ubiq_window;
  893. var vis = w.style.visibility;
  894. vis = (vis=='hidden') ? 'visible' : 'hidden';
  895. w.style.visibility=vis;
  896. return;
  897. }
  898. function ubiq_focus() {
  899. line = 'ubiq_input';
  900. el=document.getElementById(line);
  901. if(el.createTextRange){
  902. var oRange=el.createTextRange();
  903. oRange.moveStart("character", 0);
  904. oRange.moveEnd("character", el.value.length);
  905. oRange.select();
  906. }
  907. else if (el.setSelectionRange){
  908. el.setSelectionRange(0, el.value.length);
  909. }
  910. el.focus();
  911. }
  912. function ubiq_enabled () {
  913. var wnd = ubiq_window;
  914. if (! wnd) return;
  915. var vis = wnd.style.visibility;
  916. if (vis=='hidden') return false;
  917. return true;
  918. }
  919. function ubiq_command () {
  920. var cmd = document.getElementById('ubiq_input');
  921. if (! cmd) {
  922. ubiq_selected_command = -1;
  923. return '';
  924. }
  925. return cmd.value;
  926. }
  927. // Gets current selection element
  928. function ubiq_get_current_element () {
  929. var el;
  930. if (document.selection && document.selection.createRange) {
  931. var range = document.selection.createRange();
  932. el = range.parentElement();
  933. }
  934. return (ubiq_element = el);
  935. }
  936. function ubiq_match_first_command(text) {
  937. if (! text) text = ubiq_command();
  938. var first_match = '';
  939. // Command selected through cursor UP/DOWN
  940. if (ubiq_first_match) {
  941. return ubiq_first_match;
  942. }
  943. if (text.length > 0) {
  944. for (var c in CmdUtils.CommandList) {
  945. c = CmdUtils.CommandList[c]['name'];
  946. if (c.match('^' + text)) {
  947. first_match = c;
  948. break;
  949. }
  950. }
  951. }
  952. return first_match;
  953. }
  954. function ubiq_command_icon(c) {
  955. var icon = CmdUtils.CommandList[c]['icon'];
  956. if (!icon) {
  957. icon = 'http://people.opera.com/cosimo/ubiquity/spacer.png';
  958. }
  959. icon = '<img src="' + icon + '" width="16" height="16" border="0" alt="" align="absmiddle"> ';
  960. return icon;
  961. }
  962. function ubiq_command_name(c) {
  963. return CmdUtils.CommandList[c]['name'];
  964. }
  965. function ubiq_replace_first_word(w) {
  966. if (!w) return;
  967. var text = ubiq_command();
  968. var words = text.split(' ');
  969. words[0] = w;
  970. var cmd_line = document.getElementById('ubiq_input');
  971. if (! cmd_line) return;
  972. cmd_line.value = words.join(' ');
  973. return;
  974. }
  975. function ubiq_show_matching_commands (text) {
  976. if (! text) text = ubiq_command();
  977. // Always consider 1st word only
  978. text = text.split(' ')[0];
  979. ubiq_first_match = null;
  980. var show_all = text == '*all';
  981. var matches = new Array();
  982. var substr_matches = new Array();
  983. if (text.length > 0) {
  984. for (var c in CmdUtils.CommandList) {
  985. var cmd = CmdUtils.CommandList[c]['name'];
  986. // Starting match only /^command/
  987. if (show_all || cmd.match('^' + text)) {
  988. matches.push(c);
  989. }
  990. // Substring matching as well, in a separate list
  991. else if (cmd.match(text)) {
  992. substr_matches.push(c);
  993. }
  994. }
  995. }
  996. // Some substring matches found, append to list of matches
  997. if (substr_matches.length > 0) {
  998. var full_matches = matches.length;
  999. for (m in substr_matches) {
  1000. matches.push(substr_matches[m]);
  1001. // Too long lists overflow from the layer
  1002. if ((parseInt(m) + full_matches) > 11) {
  1003. matches.push('...');
  1004. break;
  1005. }
  1006. }
  1007. }
  1008. // Where to show the results
  1009. var results_panel = document.getElementById('ubiq-results-panel');
  1010. // Don't navigate outside boundaries of the list of matches
  1011. if (ubiq_selected_command >= matches.length) {
  1012. ubiq_selected_command = matches.length - 1;
  1013. }
  1014. else if (ubiq_selected_command == -1) {
  1015. ubiq_selected_command = 0;
  1016. }
  1017. // We have matches, show a list
  1018. if (matches.length > 0) {
  1019. var suggestions_div = document.createElement('div');
  1020. var suggestions_list = document.createElement('ul');
  1021. suggestions_list.style = 'padding:0; margin:0';
  1022. ubiq_show_tip(matches[ubiq_selected_command]);
  1023. //ubiq_show_preview(matches[ubiq_selected_command]);
  1024. for (var c in matches) {
  1025. var is_selected = (c == ubiq_selected_command);
  1026. var li=document.createElement('li');
  1027. var li_bg=ubiq_url_for(is_selected ? 'selected_background.png' : 'command_background.png');
  1028. c = matches[c];
  1029. if (c == '...') {
  1030. li.innerHTML = c;
  1031. }
  1032. else {
  1033. var icon = ubiq_command_icon(c);
  1034. var cmd = ubiq_command_name(c);
  1035. if (is_selected) ubiq_first_match = cmd;
  1036. li.innerHTML=icon + cmd;
  1037. }
  1038. li.style = 'color: black; list-style: none; margin:0; padding-top:8px; padding-left:12px;'
  1039. + 'font-family: Helvetica,Arial; font-size: 14px; height:26px;'
  1040. + 'background-image:'+li_bg+'; background-repeat: no-repeat;';
  1041. suggestions_list.appendChild(li);
  1042. }
  1043. suggestions_div.appendChild(suggestions_list);
  1044. results_panel.innerHTML = suggestions_div.innerHTML;
  1045. }
  1046. else {
  1047. ubiq_selected_command = -1;
  1048. ubiq_show_tip(null);
  1049. results_panel.innerHTML = ubiq_help();
  1050. }
  1051. return;
  1052. }
  1053. function ubiq_key_handler (userjs_event) {
  1054. if (!userjs_event) return;
  1055. var ev = userjs_event.event;
  1056. var kc = ev.keyCode;
  1057. // afterEvent.keyUp ctrlKey is always false on Opera 9.63 on Linux (?)
  1058. var ctrl_space_pressed = (kc==32) && (ev.ctrlKey || ev.metaKey);
  1059. // If we're in the background (or not created), return immediately
  1060. // Otherwise, activate only on CTRL + Space
  1061. if (! ubiq_enabled()) {
  1062. // Create our window if not already done
  1063. if (! ubiq_window) {
  1064. ubiq_window = ubiq_create_window();
  1065. }
  1066. if (ctrl_space_pressed) {
  1067. // Get text selection before switching window focus
  1068. ubiq_get_selection();
  1069. ubiq_get_current_element();
  1070. ubiq_toggle_window();
  1071. ubiq_focus();
  1072. }
  1073. }
  1074. else {
  1075. if (ctrl_space_pressed) {
  1076. ubiq_toggle_window();
  1077. return;
  1078. }
  1079. // On ENTER, execute the given command
  1080. if (kc==13) {
  1081. ubiq_execute();
  1082. return;
  1083. }
  1084. // ESC, hide the Ubiquity window
  1085. if (kc==27) {
  1086. ubiq_toggle_window();
  1087. }
  1088. // Cursor up
  1089. if (kc==38) {
  1090. ubiq_select_prev_command();
  1091. }
  1092. // Cursor Down
  1093. else if (kc==40) {
  1094. ubiq_select_next_command();
  1095. }
  1096. ubiq_show_matching_commands();
  1097. }
  1098. }
  1099. function ubiq_select_prev_command () {
  1100. if (ubiq_selected_command > 0) {
  1101. ubiq_selected_command--;
  1102. }
  1103. }
  1104. function ubiq_select_next_command () {
  1105. ubiq_selected_command++;
  1106. }
  1107. function ubiq_xml(node){
  1108. return (node && node.nodeType) ? new XMLSerializer().serializeToString(node):'('+node+')';
  1109. }
  1110. function ubiq_xml_http (url,callback) {
  1111. var xmlhttp = new opera.XMLHttpRequest();
  1112. xmlhttp.onreadystatechange = function(){
  1113. var s = ''+this+'\n';
  1114. s += 'status: '+this.status+'\n';
  1115. s += 'statusText: '+this.statusText+'\n\n';
  1116. s += 'allheaders: '+this.getAllResponseHeaders()+'\n\n';
  1117. s += 'responseText: '+this.responseText+'\n\n';
  1118. s += 'responseXML: '+(ubiq_xml(this.responseXML))+'\n\n';
  1119. var obj = {
  1120. status: this.status,
  1121. statusText: this.statusText,
  1122. allheaders: this.getAllResponseHeaders(),
  1123. responseText: this.responseText,
  1124. responseXML: ubiq_xml(this.responseXML),
  1125. };
  1126. callback(obj);
  1127. }
  1128. xmlhttp.onload = function(){};
  1129. //
  1130. // var obj = document.getElementById(elem);
  1131. // if (! obj) return;
  1132. // obj.innerHTML='';
  1133. // obj.style.display='';
  1134. //}
  1135. xmlhttp.open('GET', url, true);
  1136. xmlhttp.send('a=b&c=d');
  1137. }
  1138. //--------------------------------------------------------
  1139. //
  1140. // Command definitions
  1141. //
  1142. //--------------------------------------------------------
  1143. CmdUtils.CreateCommand({
  1144. name: "amazon-search",
  1145. takes: {"search_string": noun_arb_text},
  1146. description: "Search Amazon for books matching:",
  1147. author: {},
  1148. icon: "http://www.amazon.com/favicon.ico",
  1149. homepage: "",
  1150. license: "",
  1151. preview: "Search Amazon for books matching:",
  1152. execute: CmdUtils.SimpleUrlBasedCommand(
  1153. 'http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&field-keywords={text}'
  1154. )
  1155. });
  1156. CmdUtils.CreateCommand({
  1157. name: "answers-search",
  1158. takes: {"search_string": noun_arb_text},
  1159. description: "Search Answers.com for:",
  1160. author: {},
  1161. icon: "http://www.answers.com/favicon.ico",
  1162. homepage: "",
  1163. license: "",
  1164. preview: "Search Answers.com for:",
  1165. execute: CmdUtils.SimpleUrlBasedCommand('http://www.answers.com/{text}')
  1166. });
  1167. CmdUtils.CreateCommand({
  1168. name: "ask-search",
  1169. takes: {"search_string": noun_arb_text},
  1170. description: "Search Ask.com for the given words",
  1171. author: {},
  1172. icon: "http://www.ask.com/favicon.ico",
  1173. homepage: "",
  1174. license: "",
  1175. preview: "Search Ask.com for the given words:",
  1176. execute: CmdUtils.SimpleUrlBasedCommand('http://www.ask.com/web?q={text}')
  1177. });
  1178. CmdUtils.CreateCommand({
  1179. name: "back",
  1180. takes: {"pages": noun_arb_text}, // FIXME SHOULD BE INTEGER SOMETHING
  1181. description: "Go back in browser history",
  1182. author: {},
  1183. icon: "",
  1184. homepage: "",
  1185. license: "",
  1186. preview: "Go back {text} steps in history",
  1187. execute: function (directObj) {
  1188. var steps = parseInt (directObj.text);
  1189. steps = - steps - 1;
  1190. history.go(steps);
  1191. CmdUtils.toggleUbiquityWindow();
  1192. }
  1193. });
  1194. CmdUtils.CreateCommand({
  1195. name: "bing",
  1196. takes: {"expr": noun_arb_text},
  1197. description: "Search the web with Microsoft Bing",
  1198. author: {},
  1199. icon: "http://www.bing.com/favicon.ico",
  1200. homepage: "",
  1201. license: "",
  1202. preview: "Search the web with Microsoft Bing",
  1203. execute: CmdUtils.SimpleUrlBasedCommand(
  1204. "http://www.bing.com/search?q={text}&form=OPRTSD&pc=OPER"
  1205. )
  1206. });
  1207. CmdUtils.CreateCommand({
  1208. name: "bugzilla",
  1209. takes: {"search_string": noun_arb_text},
  1210. description: "Perform a bugzilla search for",
  1211. author: {},
  1212. icon: "http://www.mozilla.org/favicon.ico",
  1213. homepage: "",
  1214. license: "",
  1215. preview: "Perform a bugzilla search for",
  1216. execute: CmdUtils.SimpleUrlBasedCommand(
  1217. "https://bugzilla.mozilla.org/buglist.cgi?query_format=specific&order=relevance+desc&bug_status=__open__&content={text}"
  1218. )
  1219. });
  1220. CmdUtils.CreateCommand({
  1221. name: "close",
  1222. takes: {},
  1223. description: "Close the current window",
  1224. author: {},
  1225. icon: "",
  1226. homepage: "",
  1227. license: "",
  1228. preview: "Close the current window",
  1229. execute: function (directObj) {
  1230. CmdUtils.toggleUbiquityWindow();
  1231. CmdUtils.closeWindow();
  1232. }
  1233. });
  1234. CmdUtils.CreateCommand({
  1235. name: "clusty",
  1236. takes: {"search_string": noun_arb_text},
  1237. description: "Perform a clustered search through clusty.com",
  1238. author: {},
  1239. icon: "http://clusty.com/images/clusty-favicon.ico",
  1240. homepage: "",
  1241. license: "",
  1242. preview: "Perform a clustered search through clusty.com",
  1243. execute: CmdUtils.SimpleUrlBasedCommand(
  1244. "http://clusty.com/search?query={text}"
  1245. )
  1246. });
  1247. CmdUtils.CreateCommand({
  1248. name: "code-search",
  1249. takes: {"search_string": noun_arb_text},
  1250. description: "Search any source code for the given string",
  1251. author: { name: "Cosimo Streppone", email: "cosimo@cpan.org" },
  1252. icon: "http://www.google.com/favicon.ico",
  1253. homepage: "http://codesearch.google.com",
  1254. license: "",
  1255. preview: "Search any source code for the given string",
  1256. execute: CmdUtils.SimpleUrlBasedCommand(
  1257. 'http://www.google.com/codesearch?client=opera&sourceid=opera&q={text}'
  1258. )
  1259. });
  1260. CmdUtils.CreateCommand({
  1261. name: "command-list",
  1262. takes: {},
  1263. description: "Shows the list of Ubiquity commands and what they do",
  1264. author: {},
  1265. icon: "",
  1266. homepage: "",
  1267. license: "",
  1268. preview: "Shows the list of Ubiquity commands and what they do",
  1269. execute: function (directObj) {
  1270. ubiq_show_matching_commands('*all');
  1271. }
  1272. });
  1273. CmdUtils.CreateCommand({
  1274. name: "cpan",
  1275. icon: "http://search.cpan.org/favicon.ico",
  1276. description: "Search for a CPAN package information",
  1277. homepage: "",
  1278. author: { name: "Cosimo Streppone", email: "cosimo@cpan.org"},
  1279. license: "",
  1280. takes: {"package_name": noun_arb_text},
  1281. preview: "Search for a CPAN package information",
  1282. execute: CmdUtils.SimpleUrlBasedCommand(
  1283. "http://search.cpan.org/dist/{text}"
  1284. )
  1285. });
  1286. CmdUtils.CreateCommand({
  1287. name: "currency-converter",
  1288. takes: {"currency_spec": noun_arb_text},
  1289. description: "Convert currency using xe.com converter service.<br/><i>Ex.: 5000 NOK to EUR</i>",
  1290. author: { name: "Cosimo Streppone", email: "cosimo@cpan.org" },
  1291. icon: "http://www.xe.com/favicon.ico",
  1292. homepage: "http://xe.com/ucc/",
  1293. license: "",
  1294. preview: "Convert currency values using xe.com converter service.",
  1295. execute: function( directObj ) {
  1296. var currency_spec = directObj.text;
  1297. var matches = currency_spec.match(/^([\d\.]+)\s+(\w+)\s+to\s+(\w+)$/);
  1298. var amount = matches[1];
  1299. var curr_from = matches[2].toUpperCase();
  1300. var curr_to = matches[3].toUpperCase();
  1301. var xe_url = "http://www.xe.com/ucc/convert.cgi?Amount=" + escape(amount)
  1302. + "&From=" + escape(curr_from) + "&To=" + escape(curr_to);
  1303. Utils.openUrlInBrowser(xe_url);
  1304. }
  1305. });
  1306. CmdUtils.CreateCommand({
  1307. name: "dictionary",
  1308. description: "Gives the meaning of a word.",
  1309. author: { name: "Isidoros Passadis", email: "isidoros.passadis@gmail.com"},
  1310. help: "Try issuing &quot;dictionary ubiquity&quot;",
  1311. license: "MPL",
  1312. icon: "http://dictionary.reference.com/favicon.ico",
  1313. takes: {"word": noun_arb_text},
  1314. execute: function( directObj ) {
  1315. var word = directObj.text;
  1316. Utils.openUrlInBrowser( "http://dictionary.reference.com/search?q=" + escape(word) );
  1317. },
  1318. preview: "Gives the meaning of a word.",
  1319. });
  1320. CmdUtils.CreateCommand({
  1321. name: "dramatic-chipmunk",
  1322. takes: {},
  1323. description: "Prepare for a dramatic moment of your life",
  1324. author: {},
  1325. icon: "http://www.youtube.com/favicon.ico",
  1326. homepage: "",
  1327. license: "",
  1328. preview: "Prepare for a dramatic moment of your life",
  1329. execute: CmdUtils.SimpleUrlBasedCommand(
  1330. "http://www.youtube.com/watch?v=a1Y73sPHKxw"
  1331. )
  1332. });
  1333. CmdUtils.CreateCommand({
  1334. name: "duckduckgo",
  1335. takes: {"search_string": noun_arb_text},
  1336. description: "Search on DuckDuckGo for the given words",
  1337. author: {},
  1338. icon: "http://duckduckgo.com/favicon.ico",
  1339. homepage: "http://duckduckgo.com",
  1340. license: "",
  1341. preview: "Search on DuckDuckGo for the given words",
  1342. execute: CmdUtils.SimpleUrlBasedCommand(
  1343. "http://duckduckgo.com/?client=opera&q={text}&sourceid=opera&ie=utf-8&oe=utf-8"
  1344. )
  1345. });
  1346. CmdUtils.CreateCommand({
  1347. name: "ebay-search",
  1348. takes: {"search_string": noun_arb_text},
  1349. description: "Search ebay for the given words",
  1350. author: {},
  1351. icon: "http://ebay.com/favicon.ico",
  1352. homepage: "",
  1353. license: "",
  1354. preview: "Search ebay for the given words",
  1355. execute: CmdUtils.SimpleUrlBasedCommand(
  1356. "http://search.ebay.com/search/search.dll?satitle={text}"
  1357. )
  1358. });
  1359. CmdUtils.CreateCommand({
  1360. name: "fizy",
  1361. icon: "http://www.fizy.com/favicon.ico",
  1362. description: "Search Music and Video",
  1363. preview: "Search Music and Video on fizy.com:",
  1364. execute: CmdUtils.SimpleUrlBasedCommand(
  1365. "http://fizy.com/?q={text}&type=&quality=&duration=&x=0&y=0"
  1366. )
  1367. });
  1368. CmdUtils.CreateCommand({
  1369. name: "flickr",
  1370. takes: {"search_string": noun_arb_text},
  1371. description: "Search photos on Flickr",
  1372. author: {},
  1373. icon: "http://flickr.com/favicon.ico",
  1374. homepage: "",
  1375. license: "",
  1376. preview: "Search photos on Flickr",
  1377. execute: CmdUtils.SimpleUrlBasedCommand(
  1378. "http://www.flickr.com/search/?q={text}&w=all"
  1379. )
  1380. });
  1381. CmdUtils.CreateCommand({
  1382. name: "gcalculate",
  1383. takes: {"expression": noun_arb_text}, // FIXME a different type?
  1384. description: "Examples: 3^4/sqrt(2)-pi, 3 inch in cm, speed of light, 0xAF in decimal (<a href=\"http://www.googleguide.com/calculator.html\">Command list</a>)",
  1385. author: {},
  1386. icon: "http://www.google.com/favicon.ico",
  1387. homepage: "",
  1388. license: "",
  1389. preview: "Examples: 3^4/sqrt(2)-pi, 3 inch in cm, speed of light, 0xAF in decimal (<a href=\"http://www.googleguide.com/calculator.html\">Command list</a>)",
  1390. execute: CmdUtils.SimpleUrlBasedCommand(
  1391. "http://www.google.com/search?client=opera&num=1&q={text}&sourceid=opera&ie=utf-8&oe=utf-8"
  1392. )
  1393. });
  1394. CmdUtils.CreateCommand({
  1395. name: "google-search",
  1396. takes: {"search_string": noun_arb_text},
  1397. description: "Search on Google for the given words",
  1398. author: {},
  1399. icon: "http://www.google.com/favicon.ico",
  1400. homepage: "",
  1401. license: "",
  1402. preview: "Search on Google for the given words",
  1403. execute: CmdUtils.SimpleUrlBasedCommand(
  1404. "http://www.google.com/search?client=opera&q={text}&sourceid=opera&ie=utf-8&oe=utf-8"
  1405. )
  1406. });
  1407. CmdUtils.CreateCommand({
  1408. name: "help",
  1409. takes: {},
  1410. description: "Provides basic help on using Ubiquity for Opera",
  1411. author: {},
  1412. icon: "",
  1413. homepage: "",
  1414. license: "",
  1415. preview: "Provides basic help on using Ubiquity for Opera",
  1416. execute: CmdUtils.SimpleUrlBasedCommand(
  1417. "http://people.opera.com/cosimo/ubiquity/help.html"
  1418. )
  1419. });
  1420. CmdUtils.CreateCommand({
  1421. name: "image-search",
  1422. takes: {"search_string": noun_arb_text},
  1423. description: "Search on Google for images",
  1424. author: {},
  1425. icon: "http://www.google.com/favicon.ico",
  1426. homepage: "",
  1427. license: "",
  1428. preview: "Search on Google for images",
  1429. execute: CmdUtils.SimpleUrlBasedCommand(
  1430. "http://images.google.com/images?hl=en&q={text}&client=opera&sourceid=opera"
  1431. )
  1432. });
  1433. CmdUtils.CreateCommand({
  1434. name: "imdb",
  1435. takes: {"search_string": noun_arb_text},
  1436. description: "Searches for movies on IMDb",
  1437. author: {},
  1438. icon: "http://www.imdb.com/favicon.ico",
  1439. homepage: "",
  1440. license: "",
  1441. preview: "Searches for movies on IMDb",
  1442. execute: CmdUtils.SimpleUrlBasedCommand(
  1443. "http://www.imdb.com/find?s=all&q={text}&x=0&y=0"
  1444. )
  1445. });
  1446. CmdUtils.CreateCommand({
  1447. name: "instant-rimshot",
  1448. takes: {},
  1449. description: "Instant Rimshot at your fingertips!",
  1450. author: {},
  1451. icon: "",
  1452. homepage: "http://instantrimshot.com",
  1453. license: "",
  1454. preview: "Instant Rimshot at your fingertips!",
  1455. execute: CmdUtils.SimpleUrlBasedCommand(
  1456. "http://instantrimshot.com/rimshot.swf"
  1457. )
  1458. });
  1459. CmdUtils.CreateCommand({
  1460. name: "icon-search",
  1461. takes: {"search_string": noun_arb_text},
  1462. description: "IconFinder icon search:",
  1463. author: {},
  1464. icon: "http://cdn.iconfinder.net/design/images/favicon.ico",
  1465. homepage: "",
  1466. license: "",
  1467. preview: "",
  1468. execute: CmdUtils.SimpleUrlBasedCommand(
  1469. 'http://www.iconfinder.com/search/?q={text}'
  1470. )
  1471. });
  1472. //
  1473. // From Ubiquity feed:
  1474. // https://ubiquity.mozilla.com/herd/all-feeds/9b0b1de981e80b6fcfee0659ffdbb478d9abc317-4742/
  1475. //
  1476. // Modified to get the current window domain
  1477. //
  1478. CmdUtils.CreateCommand({
  1479. name: "isdown",
  1480. icon: "http://downforeveryoneorjustme.com/favicon.ico",
  1481. description: "Check if selected/typed URL is down",
  1482. homepage: "http://www.andyfilms.net",
  1483. author: { name: "Andy Jarosz", email: "andyfilms1@yahoo.com"},
  1484. license: "GPL",
  1485. takes: {URL: noun_arb_text},
  1486. preview: function(pblock, directObject) {
  1487. //ubiq_show_preview(urlString);
  1488. //searchText = jQuery.trim(directObject.text);
  1489. searchText = directObject.text;
  1490. var words = searchText.split(' ');
  1491. var host = words[1];
  1492. if(searchText.length < 1) {
  1493. pblock.innerHTML = "Checks if URL is down";
  1494. return;
  1495. }
  1496. var previewTemplate = "Checks if <b>" + host + "</b> is down";
  1497. pblock.innerHTML = previewTemplate;
  1498. },
  1499. execute: function(directObject) {
  1500. var url = "http://downforeveryoneorjustme.com/{QUERY}"
  1501. var query = directObject.text;
  1502. // Get the hostname from url
  1503. if (! query) {
  1504. var host = window.location.href;
  1505. var url_comp = host.split('/');
  1506. query = url_comp[2];
  1507. }
  1508. var urlString = url.replace("{QUERY}", query);
  1509. //Utils.openUrlInBrowser(urlString);
  1510. ubiq_xml_http(urlString, function (ajax) {
  1511. if (! ajax) return;
  1512. var text = ajax.responseText;
  1513. if (! text) return;
  1514. var pblock = document.getElementById('ubiq-command-preview');
  1515. if (text.match('is up.')) {
  1516. pblock.innerHTML = '<br/><p style="font-size: 18px;">It\'s just you. The site is <b>up!</b></p>';
  1517. } else {
  1518. pblock.innerHTML = '<br/><p style="font-size: 18px;">It\'s <b>not</b> just you. The site is <b>down!</b></p>';
  1519. }
  1520. });
  1521. }
  1522. });
  1523. CmdUtils.CreateCommand({
  1524. name: "lastfm",
  1525. takes: {"search_string": noun_arb_text},
  1526. description: "Listen to some artist radio on Last.fm",
  1527. author: {},
  1528. icon: "http://last.fm/favicon.ico",
  1529. homepage: "",
  1530. license: "",
  1531. preview: "Listen to some artist radio on Last.fm",
  1532. execute: CmdUtils.SimpleUrlBasedCommand(
  1533. "http://www.lastfm.com/listen/artist/{text}/similarartists"
  1534. )
  1535. });
  1536. CmdUtils.CreateCommand({
  1537. name: "maps",
  1538. takes: {"address": noun_arb_text},
  1539. description: "Shows a location on the map",
  1540. author: {},
  1541. icon: "http://www.google.com/favicon.ico",
  1542. homepage: "",
  1543. license: "",
  1544. preview: "Shows a location on the map",
  1545. execute: CmdUtils.SimpleUrlBasedCommand(
  1546. "http://maps.google.com/maps?q={text}"
  1547. )
  1548. });
  1549. CmdUtils.CreateCommand({
  1550. name: "msn-search",
  1551. takes: {"search_string": noun_arb_text},
  1552. description: "Search MSN for the given words",
  1553. author: {},
  1554. icon: "http://www.msn.com/favicon.ico",
  1555. homepage: "",
  1556. license: "",
  1557. preview: "Searches MSN for the given words",
  1558. execute: CmdUtils.SimpleUrlBasedCommand(
  1559. "http://search.msn.com/results.aspx?q={text}"
  1560. )
  1561. });
  1562. CmdUtils.CreateCommand({
  1563. name: "myopera-blog-search",
  1564. takes: {"search_string": noun_arb_text},
  1565. description: "Search for blogs on the My Opera Community",
  1566. author: { name: "Cosimo Streppone", email: "cosimo@cpan.org" },
  1567. icon: "http://static.myopera.com/community/favicon.ico",
  1568. homepage: "http://my.opera.com",
  1569. license: "",
  1570. preview: "Search for blogs on the My Opera Community",
  1571. execute: CmdUtils.SimpleUrlBasedCommand(
  1572. "http://my.opera.com/community/blogs/?search={text}"
  1573. )
  1574. });
  1575. CmdUtils.CreateCommand({
  1576. name: "myopera-photo-search",
  1577. takes: {"search_string": noun_arb_text},
  1578. description: "Search for photos on the My Opera Community",
  1579. author: { name: "Cosimo Streppone", email: "cosimo@cpan.org" },
  1580. icon: "http://static.myopera.com/community/favicon.ico",
  1581. homepage: "http://my.opera.com",
  1582. license: "",
  1583. preview: "Search for photos on the My Opera Community",
  1584. execute: CmdUtils.SimpleUrlBasedCommand(
  1585. "http://my.opera.com/community/photos/?search={text}"
  1586. )
  1587. });
  1588. CmdUtils.CreateCommand({
  1589. name: "new-tab",
  1590. takes: {"URL": noun_arb_text}, // FIXME URL type??
  1591. description: "Open a new tab (or window) with the specified URL",
  1592. author: {},
  1593. icon: "",
  1594. homepage: "",
  1595. license: "",
  1596. preview: "Open a new tab (or window) with the specified URL",
  1597. execute: function (directObj) {
  1598. var url = 'about:';
  1599. if (directObj) {
  1600. url = directObj.text;
  1601. }
  1602. CmdUtils.toggleUbiquityWindow();
  1603. window.open(url);
  1604. }
  1605. });
  1606. CmdUtils.CreateCommand({
  1607. name: "opera-cache",
  1608. takes: {},
  1609. description: "Show Opera browser cache contents",
  1610. author: { name: "Cosimo Streppone", email: "cosimo@cpan.org" },
  1611. icon: "http://www.opera.com/favicon.ico",
  1612. homepage: "http://www.opera.com",
  1613. license: "",
  1614. preview: "Show Opera browser cache contents",
  1615. execute: CmdUtils.SimpleUrlBasedCommand("opera:cache")
  1616. });
  1617. CmdUtils.CreateCommand({
  1618. name: "opera-config",
  1619. takes: { "config_option": noun_arb_text },
  1620. description: "Show Opera browser preferences (filtered by given words)",
  1621. author: { name: "Cosimo Streppone", email: "cosimo@cpan.org" },
  1622. icon: "http://www.opera.com/favicon.ico",
  1623. homepage: "http://www.opera.com",
  1624. license: "",
  1625. preview: "Show Opera browser preferences (filtered by given words)",
  1626. execute: CmdUtils.SimpleUrlBasedCommand(
  1627. "opera:config#{text}"
  1628. )
  1629. });
  1630. CmdUtils.CreateCommand({
  1631. name: "opera-skins",
  1632. takes: {"search_string": noun_arb_text},
  1633. description: "Search for Opera browser skins on the My Opera Community",
  1634. author: { name: "Cosimo Streppone", email: "cosimo@cpan.org" },
  1635. icon: "http://static.myopera.com/community/favicon.ico",
  1636. homepage: "http://my.opera.com/community/customize/skins/",
  1637. license: "",
  1638. preview: "Search for Opera browser skins on the My Opera Community",
  1639. execute: CmdUtils.SimpleUrlBasedCommand(
  1640. "http://my.opera.com/community/customize/skins/?search={text}"
  1641. )
  1642. });
  1643. CmdUtils.CreateCommand({
  1644. name: "print",
  1645. takes: {},
  1646. description: "Print the current page",
  1647. author: {},
  1648. icon: "",
  1649. homepage: "",
  1650. license: "",
  1651. preview: "Print the current page",
  1652. execute: function (directObj) {
  1653. CmdUtils.toggleUbiquityWindow();
  1654. window.print();
  1655. }
  1656. });
  1657. CmdUtils.CreateCommand({
  1658. name: "refresh",
  1659. takes: {},
  1660. description: "Reloads the current document",
  1661. author: {},
  1662. icon: "",
  1663. homepage: "",
  1664. license: "",
  1665. preview: "Reloads the current document",
  1666. execute: function (directObj) {
  1667. CmdUtils.toggleUbiquityWindow();
  1668. CmdUtils.getLocation().reload();
  1669. }
  1670. });
  1671. CmdUtils.CreateCommand({
  1672. name: "scan",
  1673. icon: "http://safeweb.norton.com/favicon.ico",
  1674. description: "Scan site with Norton Safeweb",
  1675. preview: "Scan site with Norton Safeweb:",
  1676. execute: CmdUtils.SimpleUrlBasedCommand(
  1677. "http://safeweb.norton.com/report/show?url={location}&x=0&y=0"
  1678. )
  1679. });
  1680. CmdUtils.CreateCommand({
  1681. name: "search",
  1682. takes: {"search_string": noun_arb_text},
  1683. description: "Search on Google for the given words",
  1684. author: {},
  1685. icon: "http://www.google.com/favicon.ico",
  1686. homepage: "",
  1687. license: "",
  1688. preview: "Search on Google for the given words",
  1689. execute: CmdUtils.SimpleUrlBasedCommand(
  1690. "http://www.google.com/search?client=opera&q={text}&sourceid=opera&ie=utf-8&oe=utf-8"
  1691. )
  1692. });
  1693. var bitly_api_user = "ubiquityopera";
  1694. var bitly_api_key = "R_59da9e09c96797371d258f102a690eab";
  1695. CmdUtils.CreateCommand({
  1696. name: "shorten-url",
  1697. icon: "http://bit.ly/static/images/favicon.ico",
  1698. description: "Shorten your URLs with the least possible keystrokes",
  1699. homepage: "http://bit.ly",
  1700. author: {name: "Cosimo Streppone", email: "cosimo@cpan.org"},
  1701. license: "GPL",
  1702. takes: {URL: noun_arb_text},
  1703. preview: function(pblock, directObject) {
  1704. var searchText = directObject.text;
  1705. var words = searchText.split(' ');
  1706. var host = words[1];
  1707. if(searchText.length < 1) {
  1708. pblock.innerHTML = "Shortens an URL (or the current tab) with bit.ly";
  1709. return;
  1710. }
  1711. var previewTemplate = "Shortens the URL '" + host + "' with bit.ly";
  1712. pblock.innerHTML = previewTemplate;
  1713. },
  1714. execute: function(directObject) {
  1715. var url = "http://api.bit.ly/shorten?version=2.0.1&longUrl={QUERY}&login="
  1716. + bitly_api_user + "&apiKey=" + bitly_api_key;
  1717. var query = directObject.text;
  1718. // Get the url from current open tab if none specified
  1719. if (! query || query == "") query = window.location.href;
  1720. var urlString = url.replace("{QUERY}", query);
  1721. ubiq_xml_http(urlString, function (ajax) {
  1722. if (! ajax) return;
  1723. var api_response = ajax.responseText;
  1724. if (! api_response) return;
  1725. var pblock = document.getElementById('ubiq-command-preview');
  1726. var err_code = api_response.errorCode;
  1727. var err_msg = api_response.errorMessage;
  1728. // Received an error from bit.ly API?
  1729. if (err_code > 0 || err_msg) {
  1730. pblock.innerHTML = '<br/><p style="font-size: 18px; color:orange">'
  1731. + 'Bit.ly API error ' + err_code + ': ' + err_msg + '</p>';
  1732. return;
  1733. }
  1734. // API successful. URL has been shortened
  1735. eval('api_response='+api_response);
  1736. var short_url = api_response.results[query].shortUrl;
  1737. pblock.innerHTML = '<br/><p style="font-size: 24px; font-weight: bold; color: #ddf">'
  1738. + '&rarr; <a href="' + short_url + '">' + short_url + '</a>'
  1739. + '</p>';
  1740. });
  1741. }
  1742. });
  1743. CmdUtils.CreateCommand({
  1744. name: "slideshare",
  1745. icon: "http://www.slideshare.com/favicon.ico",
  1746. description: "Search for online presentations on SlideShare",
  1747. homepage: "",
  1748. author: { name: "Cosimo Streppone", email: "cosimo@cpan.org"},
  1749. license: "",
  1750. takes: {"search_term": noun_arb_text},
  1751. preview: "Search for online presentations on SlideShare",
  1752. execute: CmdUtils.SimpleUrlBasedCommand(
  1753. "http://www.slideshare.net/search/slideshow?q={text}&submit=post&searchfrom=header&x=0&y=0"
  1754. )
  1755. });
  1756. CmdUtils.CreateCommand({
  1757. name: "stackoverflow-search",
  1758. takes: {"search_string": noun_arb_text},
  1759. description: "Searches questions and answers on stackoverflow.com",
  1760. author: { name: "Cosimo Streppone", email: "cosimo@cpan.org" },
  1761. icon: "http://stackoverflow.com/favicon.ico",
  1762. homepage: "",
  1763. license: "",
  1764. preview: "Searches questions and answers on stackoverflow.com",
  1765. execute: CmdUtils.SimpleUrlBasedCommand(
  1766. "http://stackoverflow.com/search?q={text}"
  1767. )
  1768. });
  1769. CmdUtils.CreateCommand({
  1770. name: "torrent-search",
  1771. takes: { "search_string": noun_arb_text },
  1772. description: "Search PirateBay, Isohunt, and Torrentz in new tabs.",
  1773. author: { name: "Axel Boldt", email: "axelboldt@yahoo.com"},
  1774. homepage: "http://math-www.uni-paderborn.de/~axel/",
  1775. license: "Public domain",
  1776. preview: "Search for torrent on PirateBay, Isohunt and Torrentz.",
  1777. execute: function( directObj ) {
  1778. var search_string = encodeURIComponent(directObj.text);
  1779. Utils.openUrlInBrowser( "http://thepiratebay.org/search.php?q=" + search_string);
  1780. Utils.openUrlInBrowser( "http://isohunt.com/torrents/?ihq=" + search_string);
  1781. Utils.openUrlInBrowser( "http://www.torrentz.com/search?q=" + search_string);
  1782. }
  1783. });
  1784. CmdUtils.CreateCommand({
  1785. name: "translate",
  1786. takes: { "words": noun_arb_text },
  1787. description: "Translates the given words (or text selection, or the current window) to English",
  1788. author: {},
  1789. icon: "http://www.google.com/favicon.ico",
  1790. homepage: "",
  1791. license: "",
  1792. preview: "Translates the given words (or text selection, or the current window) to English",
  1793. execute: function (directObj) {
  1794. CmdUtils.toggleUbiquityWindow();
  1795. var text = directObj.text;
  1796. // HARD !!!
  1797. //alert(ubiq_element.innerHTML);
  1798. //var html = ubiq_element.innerHTML.replace(text, 'blah blah blah');
  1799. //ubiq_element.innerHTML = html;
  1800. var words = text.split(/\s+/);
  1801. var dest = 'en';
  1802. // Detect the destination language ("translate ... to it")
  1803. if (words.length >= 3 && words[words.length - 2].toLowerCase()=='to') {
  1804. // Get destination language
  1805. dest = words.pop();
  1806. // Remove the 'to'
  1807. words.pop();
  1808. // Update the text to be translated
  1809. text = words.join('');
  1810. }
  1811. // Translate text or current URL
  1812. var url = 'http://translate.google.com/translate_t?#auto|'+dest+'|';
  1813. if (! text || text.length == 0 || text.match('^https?://')) {
  1814. if (! text) text = CmdUtils.getLocation();
  1815. url = 'http://translate.google.com/translate?prev=_t&ie=UTF-8&sl=auto&tl='+dest+'&history_state0=&u=';
  1816. }
  1817. CmdUtils.openWindow(url+text);
  1818. }
  1819. });
  1820. CmdUtils.CreateCommand({
  1821. name: "validate",
  1822. icon: "http://www.imageboo.com/files/uhee2ii315oxd8akq0nm.ico",
  1823. description: "Checks the markup validity of the current Web document",
  1824. preview: "Sends this page to the W3C validator",
  1825. execute: CmdUtils.SimpleUrlBasedCommand(
  1826. "http://validator.w3.org/check?uri={location}"
  1827. )
  1828. });
  1829. CmdUtils.CreateCommand({
  1830. name: "wayback",
  1831. homepage: "http://www.pendor.com.ar/ubiquity",
  1832. author: { name: "Juan Pablo Zapata", email: "admin@pendor.com.ar" },
  1833. description: "Search old versions of a site using the Wayback Machine (archive.org)",
  1834. help: "wayback <i>sitio a buscar</i>",
  1835. icon: "http://web.archive.org/favicon.ico",
  1836. takes: {"Site to search": noun_arb_text},
  1837. preview: function(pblock, theShout) {
  1838. pblock.innerHTML = "Buscar versiones antiguas del sitio <b>" + theShout.text + "</b>"
  1839. },
  1840. execute: function (directObj) {
  1841. CmdUtils.toggleUbiquityWindow();
  1842. var url = directObj.text;
  1843. if (! url) url = CmdUtils.getLocation();
  1844. var wayback_machine = "http://web.archive.org/web/*/" + url;
  1845. // Take me back!
  1846. CmdUtils.openWindow(wayback_machine);
  1847. }
  1848. });
  1849. CmdUtils.CreateCommand({
  1850. name: "weather",
  1851. takes: {"location": noun_arb_text},
  1852. description: "Show the weather forecast for",
  1853. author: {},
  1854. icon: "http://www.accuweather.com/favicon.ico",
  1855. homepage: "",
  1856. license: "",
  1857. preview: "Show the weather forecast for",
  1858. execute: CmdUtils.SimpleUrlBasedCommand(
  1859. "http://www.wunderground.com/cgi-bin/findweather/getForecast?query={text}"
  1860. )
  1861. });
  1862. CmdUtils.CreateCommand({
  1863. name: "whois",
  1864. icon: "http://www.who.is/favicon.ico",
  1865. description: "Query a domain name owner",
  1866. preview: "Whois query on who.is:",
  1867. execute: CmdUtils.SimpleUrlBasedCommand(
  1868. "http://who.is/whois/{text}"
  1869. )
  1870. });
  1871. CmdUtils.CreateCommand({
  1872. name: "wikipedia",
  1873. takes: {"search_string": noun_arb_text},
  1874. description: "Search Wikipedia for the given words",
  1875. author: {},
  1876. icon: "http://en.wikipedia.org/favicon.ico",
  1877. homepage: "",
  1878. license: "",
  1879. preview: "Search Wikipedia for the given words",
  1880. execute: CmdUtils.SimpleUrlBasedCommand(
  1881. "http://en.wikipedia.org/wiki/Special:Search?search={text}"
  1882. )
  1883. });
  1884. CmdUtils.CreateCommand({
  1885. name: "yahoo-answers",
  1886. takes: {"question": noun_arb_text},
  1887. description: "Search Yahoo! Answers for",
  1888. author: {},
  1889. icon: "http://l.yimg.com/a/i/us/sch/gr/answers_favicon.ico",
  1890. homepage: "",
  1891. license: "",
  1892. preview: "Search Yahoo! Answers for",
  1893. execute: CmdUtils.SimpleUrlBasedCommand(
  1894. "http://answers.yahoo.com/search/search_result;_ylv=3?p={text}"
  1895. )
  1896. });
  1897. CmdUtils.CreateCommand({
  1898. name: "yahoo-search",
  1899. takes: {"search_string": noun_arb_text},
  1900. description: "Search Yahoo! for",
  1901. author: {},
  1902. icon: "http://www.yahoo.com/favicon.ico",
  1903. homepage: "",
  1904. license: "",
  1905. preview: "Search Yahoo! for",
  1906. execute: CmdUtils.SimpleUrlBasedCommand(
  1907. "http://search.yahoo.com/search?p={text}&ei=UTF-8"
  1908. )
  1909. });
  1910. CmdUtils.CreateCommand({
  1911. name: "youtube",
  1912. takes: {"videos": noun_arb_text},
  1913. description: "Search for videos on YouTube",
  1914. author: {},
  1915. icon: "http://www.youtube.com/favicon.ico",
  1916. homepage: "",
  1917. license: "",
  1918. preview: "Search for videos on YouTube",
  1919. execute: CmdUtils.SimpleUrlBasedCommand(
  1920. "http://www.youtube.com/results?search_type=search_videos&search_sort=relevance&search_query={text}&search=Search"
  1921. )
  1922. });
  1923. // Add event handler to window
  1924. opera.addEventListener('afterEvent.keyup', ubiq_key_handler, false);
  1925. }) (opera);
  1926. // vim: ts=4 sw=4 tw=0 et