-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcommands.js
2534 lines (2387 loc) · 99.9 KB
/
commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// BuildIn CmdUtils command definitions
// jshint esversion: 6
// tinyurl
// https://tinyurl.com/api-create.php?url=https://admin.google.com/ac/users/4349123432/profile
// runs ubichr unit tests
CmdUtils.CreateCommand({
name: "unittests",
description: "perform UbiChr unit tests for builtin commands",
icon: "res/icon-128.png",
execute: function execute(args) {
CmdUtils.addTab("tests.html");
},
});
// exceptions are stored in CmdUtils.lastError
CmdUtils.CreateCommand({
name: "lasterror",
icon: "res/icon-128.png",
description: "show last UbiChr error, clear on execute",
execute: function (args) {
CmdUtils.lastError = "";
},
preview: function preview(pblock, args) {
CmdUtils.setTip(args._cmd.description);
pblock.innerHTML = (CmdUtils.lastError || "").replace("\n", "<br>");
if (pblock.innerHTML != "") window.setTimeout(() => {
CmdUtils.setResult("");
CmdUtils.setTip("");
}, 125);
},
});
// shows command source in preview
CmdUtils.CreateCommand({
name: "command-source",
description: "dumps command source",
icon: "res/icon-128.png",
execute: (args) => {
var d = CmdUtils.dump(args.text);
CmdUtils.setClipboard(d);
CmdUtils.setTip("copied");
},
preview: (pblock, args) => {
var d = CmdUtils.dump(args.text);
d = new Option(d).innerHTML;
$(pblock).css('font-size','0.7em');
pblock.innerHTML = `<pre>${d}</pre>`;
},
});
// fills gist.github.com form without submitting
// injects code via new script element https://stackoverflow.com/a/9517879/2451546
CmdUtils.CreateCommand({
name: "command-gist",
description: "prefill gist form with a command source without submitting",
icon: "res/icon-128.png",
execute: (args) => {
var c = CmdUtils.getcmdpart(args.text);
if (!c) return;
var d = CmdUtils.dump(args.text);
d = JSON.stringify(d);
d = JSON.stringify(`
var i = setInterval( ()=>{
var cm = document.getElementsByClassName("CodeMirror")[0];
if (cm && cm.CodeMirror) {
cm.CodeMirror.setValue(${d});
document.querySelector("input[name='gist[description]']").value = "${c.name} command for UbiChr";
document.querySelector("input[name='gist[contents][][name]']").value = "${c.name}.ubichr.js";
clearInterval(i);
}
}, 500);
`);
CmdUtils.gist_command_callback = (tab) => {
if (tab.pendingUrl!='https://gist.github.com/') return;
chrome.tabs.onCreated.removeListener( CmdUtils.gist_command_callback );
CmdUtils.gist_command_callback = null;
chrome.tabs.executeScript( tab.id, { code: `
var script = document.createElement('script');
script.textContent = ${d};
(document.head || document.documentElement).append(script);
script.remove();
`});
};
chrome.tabs.onCreated.addListener( CmdUtils.gist_command_callback );
CmdUtils.addTab("https://gist.github.com/");
},
preview: (pblock, args) => {
CmdUtils.setTip("execute to paste this into gist.github.com");
var d = CmdUtils.dump(args.text);
d = new Option(d).innerHTML;
$(pblock).css('font-size','0.7em');
pblock.innerHTML = `<pre>${d}</pre>`;
},
});
CmdUtils.CreateCommand({
name: "amazon-search",
description: "Search Amazon for books matching:",
author: {},
icon: "http://www.amazon.com/favicon.ico",
homepage: "",
license: "",
preview: "Search Amazon for books matching:",
execute: CmdUtils.SimpleUrlBasedCommand('https://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&field-keywords={text}')
});
CmdUtils.CreateCommand({
name: "answers-search",
description: "Search Answers.com for:",
author: {},
icon: "http://www.answers.com/favicon.ico",
homepage: "",
license: "",
preview: "Search Answers.com for:",
execute: CmdUtils.SimpleUrlBasedCommand('https://www.answers.com/search?q={text}')
});
CmdUtils.CreateCommand({
name: "ask-search",
description: "Search Ask.com for the given words",
author: {},
icon: "http://www.ask.com/favicon.ico",
homepage: "",
license: "",
preview: "Search Ask.com for the given words:",
execute: CmdUtils.SimpleUrlBasedCommand('https://www.ask.com/web?q={text}')
});
CmdUtils.CreateCommand({
name: "bugzilla",
description: "Perform a bugzilla search for",
author: {},
icon: "http://www.mozilla.org/favicon.ico",
homepage: "",
license: "",
preview: "Perform a bugzilla search for",
execute: CmdUtils.SimpleUrlBasedCommand("https://bugzilla.mozilla.org/buglist.cgi?query_format=specific&order=relevance+desc&bug_status=__open__&content={text}")
});
CmdUtils.CreateCommand({
icon: "⮽",
name: "close",
takes: {},
description: "Close the current tab",
author: {},
homepage: "",
license: "",
preview: "Close the current tab",
execute: function (directObj) {
CmdUtils.closeTab();
}
});
CmdUtils.CreateCommand({
name: "code-search",
description: "Search any source code for the given string",
icon: "https://searchcode.com/static/favicon.ico",
homepage: "https://searchcode.com/",
license: "",
preview: "Search any source code for the given string",
execute: CmdUtils.SimpleUrlBasedCommand(
'https://searchcode.com/?q={text}'
)
});
CmdUtils.CreateCommand({
name: "cpan",
icon: "https://metacpan.org/favicon.ico",
description: "Search for a CPAN package information",
homepage: "",
author: {
name: "Cosimo Streppone",
email: "[email protected]"
},
license: "",
preview: "Search for a CPAN package information",
execute: CmdUtils.SimpleUrlBasedCommand(
"https://metacpan.org/search?q={text}"
)
});
CmdUtils.CreateCommand({
name: "currency-converter",
description: "Convert currency using x-rates.com",
help: "Convert currency using x-rates.com<br>Example arguments:<br><br>5000 NOK to EUR<br>5000 NOKEUR<br>NOKEUR 5000",
author: "rostok",
icon: "https://www.x-rates.com/favicon.ico",
license: "",
preview: function (pblock, directObj) {
var curr_from, curr_to;
var currency_spec = directObj.text.trim().toUpperCase();
var matches = currency_spec.match(/^([\d\.]+)\s+(\w+)\s+TO\s+(\w+)$/);
var amount;
if (matches && matches.length>=4) {
amount = matches[1];
curr_from = matches[2];
curr_to = matches[3];
} else {
matches = currency_spec.match(/^([\d\.\+\-\\\/\*]+)\s+(\w{6})$/);
if (matches && matches.length>=3) {
amount = matches[1];
curr_from = matches[2].substring(0,3);
curr_to = matches[2].substring(3);
} else {
matches = currency_spec.match(/^(\w{6})\s+([\d\.]+)$/);
if (!matches || matches.length<3) return;
amount = matches[2];
curr_from = matches[1].substring(0,3);
curr_to = matches[1].substring(3);
}
}
try {
amount = eval(amount);
} catch (e) {
amount = parseFloat(amount) || 0;
}
jQuery(pblock).loadAbs(`https://www.x-rates.com/calculator/?from=${curr_from}&to=${curr_to}&amount=${amount} `+" span.ccOutputRslt", ()=>{
jQuery(pblock).html(amount+" "+curr_from+" = " + jQuery(pblock).text());
});
},
execute: function (directObj) {
var curr_from, curr_to;
var currency_spec = directObj.text.trim().toUpperCase();
var matches = currency_spec.match(/^([\d\.]+)\s+(\w+)\s+TO\s+(\w+)$/);
var amount;
if (matches && matches.length>=4) {
amount = matches[1];
curr_from = matches[2];
curr_to = matches[3];
} else {
matches = currency_spec.match(/^([\d\.]+)\s+(\w{6})$/);
if (matches && matches.length>=3) {
amount = matches[1];
curr_from = matches[2].substring(0,3);
curr_to = matches[2].substring(3);
} else {
matches = currency_spec.match(/^(\w{6})\s+([\d\.]+)$/);
if (!matches || matches.length<3) return;
amount = matches[2];
curr_from = matches[1].substring(0,3);
curr_to = matches[1].substring(3);
}
}
CmdUtils.addTab(`https://www.x-rates.com/calculator/?from=${curr_from}&to=${curr_to}&amount=${amount}`);
}
});
CmdUtils.CreateCommand({
name: "dictionary",
description: "Gives the meaning of a word.",
author: {
name: "Isidoros Passadis",
email: "[email protected]"
},
help: "Try issuing "dictionary ubiquity"",
license: "MPL",
icon: "https://www.dictionary.com/assets/favicon-d73532382d3943b0fef5b78554e2ee9a.png",
timeout: 250,
execute: function ({text: text}) {
CmdUtils.addTab("https://www.dictionary.com/browse/" + escape(text));
},
preview: async function define_preview(pblock, {text: text}) {
var doc = await CmdUtils.get("https://www.dictionary.com/browse/"+encodeURIComponent(text));
CmdUtils.setPreview("");
$("section[data-type*=-dictionary-]", doc).appendTo(pblock).find("a[href*=thesaurus],button").remove();
$("div[data-type=pronunciation-toggle]",pblock).remove()
},
});
CmdUtils.CreateCommand({
name: "ebay-search",
description: "Search ebay for the given words",
author: {},
icon: "http://ebay.com/favicon.ico",
homepage: "",
license: "",
preview: "Search ebay for the given words",
execute: CmdUtils.SimpleUrlBasedCommand(
"https://www.ebay.com/sch/i.html?_nkw={text}"
)
});
CmdUtils.CreateCommand({
name: "flickr",
description: "Search photos on Flickr",
author: {},
icon: "http://flickr.com/favicon.ico",
homepage: "",
license: "",
preview: "Search photos on Flickr",
execute: CmdUtils.SimpleUrlBasedCommand(
"https://www.flickr.com/search/?q={text}&w=all"
)
});
CmdUtils.CreateCommand({
name: "gcalculate",
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>)",
author: {},
icon: "http://www.google.com/favicon.ico",
homepage: "",
license: "",
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>)",
execute: CmdUtils.SimpleUrlBasedCommand(
"https://www.google.com/search?q={text}&ie=utf-8&oe=utf-8"
)
});
CmdUtils.CreateCommand({
names: ["help", "command-list"],
description: "execute to list all commands<br>or type <pre>help command-name</pre> for specific command help",
help: "Congratulations! Now you know how to help yourself!",
icon: "res/icon-128.png",
preview: function preview(pblock, {text, _cmd}) {
pblock.innerHTML = this.description;
var c = CmdUtils.getcmdpart(text.trim());
if (c!=null) {
var o = "";
o += c.names.join(", ");
o += "<hr>";
o += (c.help || c.description)+"<br>";
if (c.external) o += "WARNING! this command relies on external script!<br>";
o += "<br><br>";
if (typeof c.author !== 'undefined') o += "author: "+(c.author.name||c.author)+"<br>";
if (typeof c.homepage !== 'undefined' && c.homepage!="") o += "homepage : <a target=_blank href="+c.homepage+">"+c.homepage +"</a><br>";
pblock.innerHTML = o;
}
},
execute: CmdUtils.SimpleUrlBasedCommand("help.html")
});
CmdUtils.CreateCommand({
names: ["debug-popup"],
description: "Opens UbiChr popup in a tab",
icon: "res/icon-128.png",
execute: CmdUtils.SimpleUrlBasedCommand("popup.html")
});
CmdUtils.CreateCommand({
names: ["debug-popup-editor","debug-sandbox"],
description: "Opens UbiChr popup in a tab and with commands editor",
icon: "res/icon-128.png",
execute: CmdUtils.SimpleUrlBasedCommand("debugpopup.html")
});
CmdUtils.CreateCommand({
names: ["reload-ubiquity", "restart-ubiquity"],
description: "Reloads Ubiquity extension",
icon: "res/icon-128.png",
preview: "reloads Ubiquity extension",
execute: ()=>{
chrome.runtime.reload();
}
});
CmdUtils.makeSearchCommand({
name: ["image-search","gimages"],
timeout: 1000,
author: {name: "Federico Parodi", email: "[email protected]"},
contributor: "satyr,rostok",
homepage: "http://www.jimmy2k.it/getimagescommand",
license: "MPL",
icon: "https://support.google.com/favicon.ico",
description: "Browse pictures from Google Images.",
url: "https://www.google.com/search?tbm=isch&q={QUERY}",
preview: function gi_preview(pblock, args) {
if (!args.text) { pblock.innerText = 'no args'; return; }
pblock.innerHTML = "";
var options = {
data: {q: args.text, start: 0, count:10, searchType:"image", key:args._cmd.key, cx:args._cmd.cx},
url: "https://customsearch.googleapis.com/customsearch/v1",
error: xhr => {
pblock.innerHTML += `<a target=_blank href='${options.url}/?q=${options.data.q}&start=${options.data.start}&searchType=${options.data.searchType}&key=${options.data.key}&cx=${options.data.cx}'>link</a>`;
pblock.innerHTML += `<em class=error>${xhr.status} ${xhr.statusText}</em>`;
pblock.innerHTML += `<em class=error><div><pre>${JSON.stringify(xhr.responseJSON,0,4)}</pre></div></em>`;
pblock.innerHTML += JSON.stringify(options,0,4);
},
success: (json, status, xhr) => {
var info = "";
json
.items.sort((a,b)=>a.image.thumbnailHeight-b.image.thumbnailHeight)
.forEach(item => {
info += `<a target=_blank href='${item.link}'><img width=102 src='${item.image.thumbnailLink}'></a>`;
});
// info = "<pre>"+JSON.stringify(json.items,0,4);
pblock.innerHTML += info;
$(pblock).on('scroll', (e)=>{
var elem = $(e.currentTarget);
if (options.data.start<240 && CmdUtils.popupWindow.ubiq_last_preview_cmd==args._cmd && elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight()) {
options.data.start+=10;
CmdUtils.jQuery.ajax(options);
}
});
},
};
if (args._cmd.key !== undefined && args._cmd.cx !== undefined) {
for (options.data.start=0; options.data.start<30; options.data.start+=10) CmdUtils.jQuery.ajax(options);
} else {
pblock.innerHTML = `
To get the preview you need to obtain key/cx API credentials here:<p>
<a target=_blank href="https://developers.google.com/custom-search/v1/introduction">google_cse_api_key</a><br>
<a target=_blank href="https://support.google.com/programmable-search/answer/2649143">google_cse_api_id</a><p>
Afterward paste them using 'edit' command like this:
<pre> CmdUtils.getcmd("gimages").key = "your-key";\n CmdUtils.getcmd("gimages").cx = "your-search-engine-id";</pre>
`;
}
}
});
CmdUtils.CreateCommand({
name: ["imdb", "imdb-movies"],
description: "Searches for movies on IMDB. Dots are replaced with spaces, if last word is a year (may be in brackets) it narrows down results",
author: {},
icon: "http://www.imdb.com/favicon.ico",
homepage: "",
license: "",
timeout: 250,
preview: async function define_preview(pblock, args) {
pblock.innerHTML = "Searches for movies on IMDB";
args.text = args.text.replace(/[\.\\\/\s]+/g," ").trim();
year = parseInt(args.text.replace(/[(\s)]/g," ").trim().split(/\s+/).slice(-1));
var release_date = "";
if(year>1900 && year<2050) {
args.text = args.text.split(/[(\s]+/).slice(0,-1).join(" ");
release_date = "&release_date="+year;
}
if (args.text.trim()!="") {
jQuery(pblock).loadAbs("https://www.imdb.com/search/title?title="+encodeURIComponent(args.text)+release_date+" ul.ipc-metadata-list > *", ()=>{
jQuery(pblock).find("li").each((i,e)=>{
var link = jQuery(e).find("a").first().attr("href");
var img = "<img style='margin:0 10px 10px 0; float:left' height=96 width=65 aling=bottom src='"+jQuery(e).find(".ipc-image").first().attr("src")+"'>";
var title = "<a href='"+jQuery(e).find("a").first().attr("href")+"'>"+jQuery(e).find("h3").text().trim()+"</a> ";
var info = "<span>"
+ jQuery(e).find(".dli-title-metadata").find("span:nth(0)").text()+" | "
+ jQuery(e).find(".dli-title-metadata").find("span:nth(1)").text()+" | "
+ "<span style='color:yellow'>"+jQuery(e).find(".ipc-rating-star").text().split(/\s+/).shift()+"</span>"
+ "</span>";
var syno = "<br><span>"+jQuery(e).find(".ipc-html-content-inner-div").text()+"</span>";
jQuery(e).replaceWith("<div data-option='' data-option-value='"+link+"'><div style='clear:both;overflow-y:auto;'>"+img+"<div style=''>"+ title + info + syno + "</div></div></div>");
});
});
}
},
execute: function execute(args) {
args.text = args.text.replace(/[\.\\\/\s]+/g," ").trim();
var release_date = "";
year = parseInt(args.text.replace(/[(\s)]/g," ").trim().split(/\s+/).slice(-1));
if(year>1900 && year<2050) {
args.text = args.text.split(/[(\s]+/).slice(0,-1).join(" ");
release_date = "&release_date="+year;
}
var opt = args._opt_val || "";
if(opt.includes("://"))
CmdUtils.addTab(opt);
else
CmdUtils.addTab("https://www.imdb.com/search/title?title="+encodeURIComponent(args.text)+release_date);
}
});
//
// From Ubiquity feed:
// https://ubiquity.mozilla.com/herd/all-feeds/9b0b1de981e80b6fcfee0659ffdbb478d9abc317-4742/
//
// Modified to get the current window domain
//
CmdUtils.CreateCommand({
name: "isdown",
icon: "http://downforeveryoneorjustme.com/favicon.ico",
description: "Check if selected/typed URL is down",
url : "https://downforeveryoneorjustme.com/api/httpcheck/{QUERY}",
preview: async function (pblock, {text:text}) {
if (text=="") text = CmdUtils.getLocation();
if (text.indexOf("://")<0) text = "https://"+text;
text = CmdUtils.getLocationOrigin(text.trim())
if (text=="") return pblock.innerHTML = "pass argument or run inside tab";
pblock.innerHTML = "checking if <b>" + text + "</b> is down...";
var urlString = this.url.replace("{QUERY}", text);
ajax = await CmdUtils.get(urlString);
{
if (!ajax) return;
if (ajax.isDown) {
pblock.innerHTML = `It\'s <b>not</b> just you.<br><br><span style=background-color:red>The site <u>${text}</u> is <b>down!</b></span>`;
} else {
pblock.innerHTML = `It\'s just you.<br><br><span style=background-color:green>The site <u>${text}</u> is <b>up!</b></span>`;
}
};
}
});
CmdUtils.CreateCommand({
name: "lastfm",
description: "Listen to some artist radio on Last.fm",
author: {},
icon: "https://www.last.fm/static/images/favicon.ico",
homepage: "",
license: "",
preview: "Listen to some artist radio on Last.fm",
execute: CmdUtils.SimpleUrlBasedCommand("https://www.last.fm/music/{text}/+similar")
});
/// since June 2018 Google Maps no longer work without license key
CmdUtils.CreateCommand({
name: "maps",
description: "Shows a location on the map, iframe version",
icon: "http://www.google.com/favicon.ico",
execute: function({text}) {
if (text.substr(-2)=="-l") text = text.slice(0,-2);
CmdUtils.addTab("https://maps.google.com/maps?q="+encodeURIComponent(text));
},
preview: function preview(pblock, {text}) {
if (text=="") {
pblock.innerHTML = "show objects or routes on google maps.<p>syntax: <pre>\tmaps [place]\n\tmaps [start] to [finish]</pre>";
return;
}
pblock.innerHTML = `
<div class="mapouter">
<div class="gmap_canvas">
<iframe width="540" height="505" id="gmap_canvas" src="https://maps.google.com/maps?q=${encodeURIComponent(text)}&t=&z=13&ie=UTF8&iwloc=&output=embed"
frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>
</div>
<style>
.mapouter{text-align:right;height:505px;width:540px;}
.gmap_canvas {overflow:hidden;background:none!important;height:504px;width:540px;}
</style>
</div>`;
},
});
CmdUtils.CreateCommand({
name: "msn-search",
description: "Search MSN for the given words",
author: {},
icon: "http://www.msn.com/favicon.ico",
homepage: "",
license: "",
preview: "Searches MSN for the given words",
execute: CmdUtils.SimpleUrlBasedCommand(
"https://www.bing.com/search?q={text}"
)
});
CmdUtils.CreateCommand({
icon: "🗔",
name: "new-tab",
description: "Open a new tab (or window) with the specified URL",
author: {},
homepage: "",
license: "",
preview: "Open a new tab (or window) with the specified URL",
execute: function ({text}) {
if (!text.match('^https?://')) text = "https://"+text;
CmdUtils.addTab(text);
}
});
CmdUtils.CreateCommand({
icon: "🖨️",
name: "print",
description: "Print the current page",
preview: "Print the current page",
execute: function (directObj) {
chrome.tabs.executeScript( { code:"window.print();" } );
}
});
CmdUtils.CreateCommand({
names: ["search", "google-search"],
description: "Search on Google for the given words",
author: {},
icon: "http://www.google.com/favicon.ico",
homepage: "",
license: "",
preview: async function define_preview(pblock, {text: text}) {
text = text.trim();
pblock.innerHTML = "Search on Google for "+text;
if (text!="") {
var doc = await CmdUtils.get("https://www.google.pl/search?q="+encodeURIComponent(text) );
doc = jQuery("div#rso", doc)
.find("a").each(function() { $(this).attr("target", "_blank")}).end()
.find("cite").remove().end()
.find(".action-menu").remove().end()
.html();
pblock.innerHTML = doc;
}
},
execute: CmdUtils.SimpleUrlBasedCommand(
"https://www.google.com/search?q={text}&ie=utf-8&oe=utf-8"
)
});
// the old command for url shorteing with bit.ly is replaced with tinyurl one
CmdUtils.CreateCommand({
names: ["shorten-url", "tiny-url"],
icon: "https://tinyurl.com/favicon.ico",
description: "Shorten your URLs with the least possible keystrokes",
preview: async function (pblock, {text}) {
var words = text.split(/\s+/);
if (text.trim()=='') words[0]=CmdUtils.getLocation();
pblock.innerHTML = "Shorten URL for:<br>"+words.join("<br>");
},
execute: function (args) {
var pblock = args.pblock;
var words = args.text.split(/\s+/);
if (args.text.trim()=='') words[0]=CmdUtils.getLocation();
$(pblock).empty();
words.forEach(w=>{
CmdUtils.get(`https://tinyurl.com/api-create.php?url=${w}`, (r)=>{
$(pblock).append(r +"<br>");
CmdUtils.setClipboard($(pblock).text());
CmdUtils.setTip("copied!");
});
});
}
});
CmdUtils.CreateCommand({
name: "slideshare",
icon: "http://www.slideshare.com/favicon.ico",
description: "Search for online presentations on SlideShare",
homepage: "",
author: {
name: "Cosimo Streppone",
email: "[email protected]"
},
license: "",
preview: "Search for online presentations on SlideShare",
execute: CmdUtils.SimpleUrlBasedCommand(
"https://www.slideshare.net/search/slideshow?q={text}&submit=post&searchfrom=header&x=0&y=0"
)
});
CmdUtils.CreateCommand({
name: "stackoverflow-search",
description: "Searches questions and answers on stackoverflow.com",
author: {
name: "Cosimo Streppone",
email: "[email protected]"
},
icon: "http://stackoverflow.com/favicon.ico",
homepage: "",
license: "",
preview: "Searches questions and answers on stackoverflow.com",
execute: CmdUtils.SimpleUrlBasedCommand(
"https://stackoverflow.com/search?q={text}"
)
});
CmdUtils.CreateCommand({
name: "torrent-search",
description: "Search PirateBay, RARBG, 1337x, torrentz2",
icon: "https://thepiratebay.org/favicon.ico",
author: {
name: "Axel Boldt",
email: "[email protected]"
},
homepage: "http://math-www.uni-paderborn.de/~axel/",
license: "Public domain",
preview: "Search for torrent on PirateBay, RARBG, 1337x, torrentz2",
execute: function (directObj) {
var search_string = encodeURIComponent(directObj.text);
CmdUtils.addTab("https://thepiratebay.org/search.php?q=" + search_string);
CmdUtils.addTab("https://rarbgmirror.org/torrents.php?search=" + search_string);
CmdUtils.addTab("https://1337x.to/search/" + search_string + '/test/');
CmdUtils.addTab("https://isohunt.nz/torrent/?ihq=" + search_string);
}
});
// -----------------------------------------------------------------
// TRANSLATE COMMANDS
// -----------------------------------------------------------------
const MS_TRANSLATOR_LIMIT = 1e4,
MS_LANGS = {},
MS_LANGS_REV = {
ar: "Arabic",
bg: "Bulgarian",
ca: "Catalan",
cs: "Czech",
da: "Danish",
nl: "Dutch",
en: "English",
et: "Estonian",
fi: "Finnish",
fr: "French",
de: "German",
el: "Greek",
he: "Hebrew",
hi: "Hindi",
hu: "Hungarian",
id: "Indonesian",
it: "Italian",
ja: "Japanese",
ko: "Korean",
lv: "Latvian",
lt: "Lithuanian",
no: "Norwegian",
pl: "Polish",
pt: "Portuguese",
ro: "Romanian",
ru: "Russian",
sk: "Slovak",
sl: "Slovenian",
es: "Spanish",
sv: "Swedish",
th: "Thai",
tr: "Turkish",
uk: "Ukrainian",
vi: "Vietnamese",
"zh-CN": "Chinese Simplified",
"zh-TW": "Chinese Traditional"
};
for (let code in MS_LANGS_REV) MS_LANGS[code] = MS_LANGS_REV[code];
function msTranslator(method, params, back) {
params.to = params.to || "en";
params.appId = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + new Date % 10;
return CmdUtils.jQuery.ajax({
url: "https://api.microsofttranslator.com/V2/Ajax.svc/" + method,
data: params,
});
}
CmdUtils.CreateCommand({
name: "translate",
description: "Translates from one language to another.",
icon: "http://www.microsoft.com/en-us/translator/wp-content/themes/ro-translator/img/banner-app-icon.png",
help: '\
You can specify the language to translate to,\
and the language to translate from.\
For example, try issuing "translate mother from english to chinese".\
If you leave out the languages, it will try to guess what you want.\
It works on selected text in any web page,\
but there's a limit (a couple of paragraphs)\
to how much it can translate a selection at once.\
If you want to translate a lot of text, leave out the input and\
it will load\
<a href="https://www.microsofttranslator.com">Bing Translator</a> toolbar.\
',
author: "based on original ubiquity translate command",
execute: async function translate_execute({text: text, _selection: _selection}) {
var words = text.split(/\s+/);
var dest = 'en';
if (words.length >= 3 && words[words.length - 2].toLowerCase() == 'to') {
dest = words.pop();
words.pop();
text = words.join('');
}
if (text && text.length <= MS_TRANSLATOR_LIMIT) {
var T = await msTranslator("Translate", {
contentType: "text/html",
text: text,
from: "",
to: dest
});
T = JSON.parse(T);
if (typeof isSelected !== 'undefined' && _selection == true) {
CmdUtils.setSelection(T);
CmdUtils.closePopup();
}
} else {
pblock.innerHTML = "text is too short or too long. try translating <a target=_blank href=https://www.bing.com/translator/>manually</a>";
}
},
preview: async function translate_preview(pblock, {text: text}) {
var words = text.split(/\s+/);
var dest = 'en';
if (words.length >= 3 && words[words.length - 2].toLowerCase() == 'to') {
dest = words.pop();
words.pop();
text = words.join(' ');
}
if (text && text.length <= MS_TRANSLATOR_LIMIT) {
var T = await msTranslator("Translate", {
contentType: "text/html",
text: text,
from: "",
to: dest
});
T = JSON.parse(T);
pblock.innerHTML = T;
} else {
pblock.innerHTML = "text is too short or too long<BR><BR>[" + text + "]";
}
},
});
CmdUtils.CreateCommand({
name: "validate",
icon: "https://validator.w3.org/images/favicon.ico",
description: "Checks the markup validity of the current Web document",
preview: async function(pblock, args) {
jQuery(pblock).load("https://validator.w3.org/check?uri="+encodeURI(CmdUtils.getLocation())+" div#results");
},
execute: CmdUtils.SimpleUrlBasedCommand("https://validator.w3.org/check?uri={location}")
});
CmdUtils.CreateCommand({
name: "wayback",
homepage: "http://www.pendor.com.ar/ubiquity",
author: {
name: "Juan Pablo Zapata",
email: "[email protected]"
},
description: "Search old versions of a site using the Wayback Machine (archive.org)",
help: "wayback <i>sitio a buscar</i>",
icon: "http://archive.org/favicon.ico",
preview: function (pblock, theShout) {
pblock.innerHTML = "Buscar versiones antiguas del sitio <b>" + theShout.text + "</b>";
},
execute: function (directObj) {
CmdUtils.closePopup();
var url = directObj.text;
if (!url) url = CmdUtils.getLocation();
var wayback_machine = "https://web.archive.org/web/*/" + url;
// Take me back!
CmdUtils.addTab(wayback_machine);
}
});
CmdUtils.CreateCommand({
name: "weather",
description: "Show the weather forecast for",
author: {},
icon: "http://www.accuweather.com/favicon.ico",
homepage: "",
license: "",
preview: "Show the weather forecast",
execute: CmdUtils.SimpleUrlBasedCommand("https://www.wunderground.com/weather/pl/{text}")
});
CmdUtils.CreateCommand({
name: "wikipedia",
description: "Search Wikipedia for the given words",
author: {},
icon: "http://en.wikipedia.org/favicon.ico",
homepage: "",
license: "",
preview: function wikipedia_preview(previewBlock, args) {
var args_format_html = "English";
var searchText = args.text.trim();
if (!searchText) {
previewBlock.innerHTML = "Searches Wikipedia in " + args_format_html + ".";
return;
}
previewBlock.innerHTML = "Searching Wikipedia for <b>" + args.text + "</b> ...";
function onerror() {
previewBlock.innerHTML =
"<p class='error'>" + "Error searching Wikipedia" + "</p>";
}
var langCode = "en";
var apiUrl = "https://" + langCode + ".wikipedia.org/w/api.php";
CmdUtils.ajaxGetJSON("https://" + langCode + ".wikipedia.org/w/api.php?action=query&list=search&srsearch="+searchText+"&srlimit=5&format=json", function (resp) {
function generateWikipediaLink(title) {
return "https://" + langCode + ".wikipedia.org/wiki/" +title.replace(/ /g, "_");
}
function wikiAnchor(title) {
return "<a target=_blank href='"+generateWikipediaLink(title)+"'>"+title+"</a>";
}
previewBlock.innerHTML = "";
for (var i = 0; i < resp.query.search.length; i++) {
previewBlock.innerHTML += "<p>"+wikiAnchor(resp.query.search[i].title) + "<br>"+resp.query.search[i].snippet+"</p>";
}
jQuery(previewBlock).find("p").each((i,e)=>{
jQuery(e).attr("data-option","");
jQuery(e).attr("data-option-value", jQuery(e).find("a").first().attr("href"));
});
});
},
execute: function execute(args) {
var opt = args._opt_val || "";
if(opt.includes("://"))
CmdUtils.addTab(opt);
else {
var old = CmdUtils.SimpleUrlBasedCommand("https://en.wikipedia.org/wiki/Special:Search?search={text}");
old(args);
}
},
old_execute: CmdUtils.SimpleUrlBasedCommand("https://en.wikipedia.org/wiki/Special:Search?search={text}")
});
CmdUtils.CreateCommand({
name: "yahoo-search",
description: "Search Yahoo! for",
author: {},
icon: "https://s.yimg.com/rz/l/favicon.ico",
homepage: "",
license: "",
preview: "Search Yahoo! for",
execute: CmdUtils.SimpleUrlBasedCommand(
"https://search.yahoo.com/search?p={text}&ei=UTF-8"
)
});
CmdUtils.CreateCommand({
name: "youtube",
description: "Search for videos on YouTube",
author: {},
icon: "http://www.youtube.com/favicon.ico",
homepage: "",
license: "",
preview: "Search for videos on YouTube",
execute: CmdUtils.SimpleUrlBasedCommand(
"https://www.youtube.com/results?search=Search&search_query={text}"
)
});
CmdUtils.CreateCommand({
name: ["calc","sum"],
description: "evals math expressions, white-space separated expressions are added",
icon: "➕",
external: true,
require: "https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.20.1/math.min.js",
preview: pr = function preview(previewBlock, {text}) {
if (text.trim()=="") text = CmdUtils.getClipboard();
if (text.trim()!='') {
var m = new math.parser();
text = text.trim().replace(/,/g,"."); // commas are dots
text = text.replace(/(\d)(\s+)/g,"$1+"); // blanks are replaced with sum
try {
console.log(text);
previewBlock.innerHTML = m.eval(text);
} catch (e) {
previewBlock.innerHTML = "eval error:"+e; // catching all errors as mathjs likes to throw them around
}
//CmdUtils.ajaxGet("http://api.mathjs.org/v1/?expr="+encodeURIComponent(args.text), (r)=>{ previewBlock.innerHTML = r; });
}
else
previewBlock.innerHTML = this.description;
return previewBlock.innerText;
},
execute: function ({text}) {
if (text.trim()!='') {
var m = new math.parser();
text = text.trim().replace(/,/g,"."); // commas are dots
text = text.replace(/(\d)(\s+)(\d)/g,"$1+$3"); // blanks are replaced with sum
try {
text = m.eval(text);
CmdUtils.setSelection(text);
CmdUtils.popupWindow.ubiq_set_input("calc "+text, false);
} catch (e) {
CmdUtils.setResult("eval error:"+e);
}
}
}
});
CmdUtils.CreateCommand({
name: "edit-ubiquity-commands",
icon: "res/icon-128.png",
description: "Takes you to the Ubiquity command <a href=options.html target=_blank>editor page</a>.",
execute: function () {
chrome.runtime.openOptionsPage();
}
});
CmdUtils.CreateCommand({
name: "define",
description: "Gives the meaning of a word, using wordnik.com.",
help: "Try issuing "define aglet"",
icon: "https://wordnik.com/img/favicon.png",
execute: CmdUtils.SimpleUrlBasedCommand(
"https://wordnik.com/words/{text}"
),
preview: function define_preview(pblock, {text: text}) {
if (text.trim()=="") return pblock.innerHTML = this.description;
pblock.innerHTML = "Gives the definition of the word "+text;
$(pblock).loadAbs(`https://wordnik.com/words/${encodeURI(text)} div#define > div.active`, ()=>{
});
}
});
CmdUtils.CreateCommand({
names: ["base64decode","b64d","atob"],
description: "base64decode",
author: {
name: "rostok",
},
license: "GPL",
execute: function execute({text}) {
if (text.trim()=="") text = CmdUtils.getClipboard();
try{
CmdUtils.setSelection(window.atob(text));
} catch (e) {
}
},
preview: function preview(pblock, {text}) {