From e30c2f417a3404ad07f7b22e7f1f54c9a13bc001 Mon Sep 17 00:00:00 2001 From: rostok Date: Fri, 8 Jan 2021 21:39:48 +0100 Subject: [PATCH] 0.1.0.29 various fixes --- README.md | 2 +- cmdutils.js | 8 +++++--- commands.js | 19 ++++++------------- help.css | 19 +++++++++++++++---- help.js | 5 +++-- manifest.json | 2 +- options.js | 12 +++++++++++- popup.css | 10 ++++++++++ popup.js | 13 ++++++------- 9 files changed, 58 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 93fdda1..3fce47f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmdutils.js b/cmdutils.js index 50f4bb8..6332ab6 100644 --- a/cmdutils.js +++ b/cmdutils.js @@ -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); } @@ -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) { @@ -517,6 +516,7 @@ 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'); @@ -524,6 +524,8 @@ function url_domain(data) { return a.hostname; } +CmdUtils.url_domain = url_domain; + // loads absolute urls (function ( $ ) { $.fn.loadAbs = function( url, complete ) { diff --git a/commands.js b/commands.js index de6a382..c38660b 100644 --- a/commands.js +++ b/commands.js @@ -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(); }, }); @@ -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") }); @@ -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) { @@ -1822,7 +1816,6 @@ CmdUtils.CreateCommand({ }, }); - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/help.css b/help.css index dd70fb8..8ed7b5c 100644 --- a/help.css +++ b/help.css @@ -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; -} \ No newline at end of file +} + +span.texticon { + display: inline-block; + font-size: 1em; + height: 22pt; + width: 12pt; + vertical-align: middle; + text-align: center; + margin: 0px +} \ No newline at end of file diff --git a/help.js b/help.js index 30a1448..1127b53 100644 --- a/help.js +++ b/help.js @@ -8,9 +8,9 @@ function showHelp(type) { r += ""; var i = c.icon || ""; if (i.length>3) - i = ""; + i = ""; else - i = ""+i+"" + i = ""+i+"" r += ""+i+""; r += ""+(c.builtIn?"":"")+c.names.join(", ")+(c.builtIn?"":"")+""; r += ""+c.description+""; @@ -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(); diff --git a/manifest.json b/manifest.json index e0f8e06..276c589 100644 --- a/manifest.json +++ b/manifest.json @@ -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, diff --git a/options.js b/options.js index c8cabc1..1f590e0 100644 --- a/options.js +++ b/options.js @@ -43,6 +43,7 @@ CmdUtils.CreateCommand({ CmdUtils.makeSearchCommand({ name: ["3example"], description: "Searches quant.com", + icon: "🔎", author: {name: "Your Name", email: "your-mail@example.com"}, icon: "https://www.qwant.com/favicon-152.png?1503916917494", url: "https://www.qwant.com/?q={QUERY}&t=all", @@ -76,7 +77,16 @@ function saveScripts() { CmdUtils.unloadCustomScripts(); CmdUtils.loadCustomScripts(); } catch (e) { - $("#info").html(""+e.message+""); + var m = e.message; + var l = /anonymous\>:(\d+)\:/.exec(e.stack); + if (l != null) { + l = l[1]; + m += " LINE:"+l+""; + } + console.log(e) + console.log(l); + $("#info").html(""+m+""); + if (l != null) $("a#linerror").click( ()=>{ editor.setCursor({line:l,ch:0}); }); } // download link diff --git a/popup.css b/popup.css index b49c4b9..4f58dba 100644 --- a/popup.css +++ b/popup.css @@ -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 +} \ No newline at end of file diff --git a/popup.js b/popup.js index 82d3dff..39d3ca3 100644 --- a/popup.js +++ b/popup.js @@ -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 `${icon}`; // emojis/unicode if (icon=="") icon = 'res/spacer.png'; - icon = ' '; + icon = ``; return icon; } @@ -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); @@ -417,6 +413,8 @@ function ubiq_show_matching_commands(text) { if (text.length) ubiq_set_result( 'no commands found for '+ ubiq_html_encode(text) +'', true ); } + // replace missing icons + $(".icon").on("error", function(){ $(this).attr('src', 'res/spacer.png'); }); return; } @@ -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(); }