Skip to content

Commit

Permalink
0.1.0.29 various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rostok committed Jan 8, 2021
1 parent c00804c commit e30c2f4
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Use ```CmdUtils.CreateCommand()``` and provide object with ```name``` string and
The ```args``` object properties for ```execute``` command are as follows:

* text: text passed as argument
* _selection: currently selected text on tab
* _selection: true if text is a current selection
* _cmd: current command structure
* _opt_idx: selected option (optional), -1 by default
* _opt_val: value of option element set in data-option-value attribute
Expand Down
8 changes: 5 additions & 3 deletions cmdutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ CmdUtils.CreateCommand = function CreateCommand(args) {
CmdUtils.makeSearchCommand = function makeSearchCommand(args) {
args.execute_org = function(a) {
var url = args.url
url = url.replace(/\{QUERY\}/g, encodeURIComponent(a.text));
url = url.replace(/\{text\}/g, encodeURIComponent(a.text));
url = url.replace(/\{text\}/g, "{QUERY}").replace(/\{QUERY\}/g, encodeURIComponent(a.text));
url = url.replace(/\{location\}/g, encodeURIComponent(CmdUtils.getLocation()));
CmdUtils.addTab(url);
}
Expand Down Expand Up @@ -147,7 +146,7 @@ CmdUtils._searchCommandPreview = function _searchCommandPreview( pblock, {text:
return;
}
if (!this.prevAttrs) this.prevAttrs = {};
var url = (this.prevAttrs.url || this.url).replace(/\{QUERY\}/g, encodeURIComponent(q));
var url = (this.prevAttrs.url || this.url).replace(/\{text\}/g, "{QUERY}").replace(/\{QUERY\}/g, encodeURIComponent(q));
// hash-anchor:
var hashanch = null;
if (this.prevAttrs.anchor != null) {
Expand Down Expand Up @@ -517,13 +516,16 @@ CmdUtils.notify = function (message, title) {
$.fn.blankify = function( url ) { return this.find("a").attr("target", "_blank"); };
}( jQuery ));

// returns domain/hostname from url
// https://stackoverflow.com/questions/8498592/extract-hostname-name-from-string
function url_domain(data) {
var a = document.createElement('a');
a.href = data;
return a.hostname;
}

CmdUtils.url_domain = url_domain;

// loads absolute urls
(function ( $ ) {
$.fn.loadAbs = function( url, complete ) {
Expand Down
19 changes: 6 additions & 13 deletions commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,14 @@ CmdUtils.CreateCommand({
},
help: "Try issuing "dictionary ubiquity"",
license: "MPL",
icon: "http://dictionary.reference.com/favicon.ico",
icon: "https://www.dictionary.com/assets/favicon-d73532382d3943b0fef5b78554e2ee9a.png",
execute: function ({text: text}) {
CmdUtils.addTab("https://dictionary.reference.com/search?q=" + escape(text));
CmdUtils.addTab("https://www.dictionary.com/browse/" + escape(text));
},
preview: async function define_preview(pblock, {text: text}) {
pblock.innerHTML = "Gives the meaning of a word.";
var doc = await CmdUtils.get("https://dictionary.reference.com/search?q="+encodeURIComponent(text)+"&s=tt&ref_=fn_al_tt_mr" );
doc = jQuery("div.source-box", doc)
.find("button", doc).remove().end()
.find("ul.headword-bar-list").remove().end()
.find(".deep-link-synonyms").remove().end()
.html();
pblock.innerHTML = doc;
var doc = await CmdUtils.get("https://www.dictionary.com/browse/"+encodeURIComponent(text));
pblock.innerHTML = $("section#top-definitions-section", doc).parent("div").html();
},
});

Expand Down Expand Up @@ -258,9 +253,8 @@ CmdUtils.CreateCommand({

CmdUtils.CreateCommand({
names: ["debug-popup"],
description: "Open popup in window",
description: "Opens UbiChr popup in a tab",
icon: "res/icon-128.png",
preview: "lists all avaiable commands",
execute: CmdUtils.SimpleUrlBasedCommand("popup.html")
});

Expand Down Expand Up @@ -1655,7 +1649,7 @@ CmdUtils.CreateCommand({
oReq.open("GET", l, true);
oReq.responseType = "blob";//"arraybuffer";
oReq.onprogress = (e)=>{
CmdUtils.popupWindow.console.log(e);
// CmdUtils.popupWindow.console.log(e);
_cmd.progress[e.currentTarget.responseURL] = {loaded:e.loaded, total:e.total};
var lt = Object.values(_cmd.progress).reduce( (acc, cur)=>{console.log("a",acc,"c",cur); return {loaded:acc.loaded+cur.loaded,total:acc.total+cur.total}});
if (CmdUtils.popupWindow.ubiq_match_first_command()==_cmd.name) {
Expand Down Expand Up @@ -1822,7 +1816,6 @@ CmdUtils.CreateCommand({
},
});


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
19 changes: 15 additions & 4 deletions help.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
body {
background:#777;
color:black;
background: #777;
color: black;
font-size: 12pt;
font-family: Calibri, Helvetica, Arial;
}

#builtin, #custom {
#builtin,
#custom {
width: 40%;
display: inline-block;
vertical-align: top;
top: 0px;
}
}

span.texticon {
display: inline-block;
font-size: 1em;
height: 22pt;
width: 12pt;
vertical-align: middle;
text-align: center;
margin: 0px
}
5 changes: 3 additions & 2 deletions help.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ function showHelp(type) {
r += "<!-- "+c.name+" -->";
var i = c.icon || "";
if (i.length>3)
i = "<img height='16px' src='"+c.icon+"'/>";
i = "<img class='icon' height='16px' src='"+c.icon+"' />";
else
i = "<span style='font-size:1em; height:16px;vertical-align:middle;margin:0px'>"+i+"</span>"
i = "<span class='texticon'>"+i+"</span>"
r += "<td>"+i+"</td>";
r += "<td>"+(c.builtIn?"":"<b>")+c.names.join(", ")+(c.builtIn?"":"</b>")+"</td>";
r += "<td>"+c.description+"</td>";
Expand All @@ -28,6 +28,7 @@ function showHelp(type) {
function help() {
$("#builtin").html( showHelp(true) );
$("#custom").html( showHelp(false) );
$(".icon").on("error", function(){ $(this).attr('src', 'res/spacer.png'); });
}

help();
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name": "UbiChr",
"homepage_url": "https://github.com/rostok/ubichr",
"author": "rostok",
"version": "0.1.0.28",
"version": "0.1.0.29",
"description": "Revived Ubiquity for Chrome",
"content_security_policy": "script-src 'self' 'unsafe-eval' https://maps.googleapis.com https://cdnjs.cloudflare.com; object-src 'self'",
"manifest_version": 2,
Expand Down
12 changes: 11 additions & 1 deletion options.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ CmdUtils.CreateCommand({
CmdUtils.makeSearchCommand({
name: ["3example"],
description: "Searches quant.com",
icon: "🔎",
author: {name: "Your Name", email: "[email protected]"},
icon: "https://www.qwant.com/favicon-152.png?1503916917494",
url: "https://www.qwant.com/?q={QUERY}&t=all",
Expand Down Expand Up @@ -76,7 +77,16 @@ function saveScripts() {
CmdUtils.unloadCustomScripts();
CmdUtils.loadCustomScripts();
} catch (e) {
$("#info").html("<span style='background-color:red'>"+e.message+"</span>");
var m = e.message;
var l = /anonymous\>:(\d+)\:/.exec(e.stack);
if (l != null) {
l = l[1];
m += " <a href=# id=linerror>LINE:"+l+"</a>";
}
console.log(e)
console.log(l);
$("#info").html("<span style='background-color:red'>"+m+"</span>");
if (l != null) $("a#linerror").click( ()=>{ editor.setCursor({line:l,ch:0}); });
}

// download link
Expand Down
10 changes: 10 additions & 0 deletions popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,13 @@ body {
/* border-collapse: collapse; */
/* border:1px solid red; */
}

span.texticon {
display: inline-block;
font-size: 1em;
height: 22pt;
width: 22pt;
vertical-align: middle;
text-align: center;
margin: 0px
}
13 changes: 6 additions & 7 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,11 @@ function ubiq_match_first_command(text) {
return first_match;
}

function _ubiq_image_error(elm) {
elm.src = 'res/spacer.png';
}

function ubiq_command_icon(c) {
var icon = CmdUtils.CommandList[c].icon || "";
if (icon.length>0 && icon.length < 3) return icon; // emojis/unicode
if (icon.length>0 && icon.length < 3) return `<span class='texticon'>${icon}</span>`; // emojis/unicode
if (icon=="") icon = 'res/spacer.png';
icon = '<img src="' + icon + '" border="0" alt="" onerror="_ubiq_image_error(this);" align="absmiddle"> ';
icon = `<span class="texticon"><img class="icon" src="${icon}" border="0" alt="" align="absmiddle"></span>`;
return icon;
}

Expand Down Expand Up @@ -379,7 +375,7 @@ function ubiq_show_matching_commands(text) {
var suggestions_list = document.createElement('ul');
var selcmdidx = matches[ubiq_selected_command][0];
ubiq_clear();
ubiq_set_preview( CmdUtils.CommandList[ selcmdidx ].description );
if (CmdUtils.CommandList[ selcmdidx ] !== undefined ) ubiq_set_preview( CmdUtils.CommandList[ selcmdidx ].description );
ubiq_selected_option = -1;
ubiq_show_preview(selcmdidx);

Expand Down Expand Up @@ -417,6 +413,8 @@ function ubiq_show_matching_commands(text) {
if (text.length)
ubiq_set_result( 'no commands found for <b>'+ ubiq_html_encode(text) +'</b>', true );
}
// replace missing icons
$(".icon").on("error", function(){ $(this).attr('src', 'res/spacer.png'); });
return;
}

Expand Down Expand Up @@ -492,6 +490,7 @@ function ubiq_keydown_handler(evt) {
// Cursor Down
else if (kc == 40) {
ubiq_selected_command++;
ubiq_selected_command = Math.min(ubiq_selected_command, 14);
lcmd = "";
evt.preventDefault();
}
Expand Down

0 comments on commit e30c2f4

Please sign in to comment.