diff --git a/content/commands.js b/content/commands.js index ad770533..f425e2b2 100644 --- a/content/commands.js +++ b/content/commands.js @@ -41,7 +41,11 @@ function Command(specs, description, action, extraInfo) //{{{ // 'abc', 'abcdef' function parseSpecs(specs) { - let shortNames = longNames = names = []; + // Whoever wrote the following should be ashamed. :( + // let shortNames = longNames = names = []; + let names = []; + let longNames = []; + let shortNames = []; for (let [,spec] in Iterator(specs)) { @@ -247,14 +251,11 @@ function Commands() //{{{ if (!command) return false; - for (let i = 0; i < exCommands.length; i++) + if (exCommands.some(function (c) c.name == command.name)) { - if (exCommands[i].name == command.name) - { - // never replace for now - liberator.log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1); - return false; - } + // never replace for now + liberator.log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1); + return false; } exCommands.push(command); diff --git a/content/liberator.js b/content/liberator.js index af9be989..7c592383 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -82,26 +82,22 @@ const liberator = (function () //{{{ { setter: function (value) { - var guioptions = config.guioptions || {}; - - for (let option in guioptions) + for (let [opt, ids] in Iterator(config.guioptions || {})) { - if (option in guioptions) + ids.forEach(function (id) { - guioptions[option].forEach(function (elem) { - try - { - document.getElementById(elem).collapsed = (value.indexOf(option.toString()) < 0); - } - catch (e) {} - }); - } + try + { + document.getElementById(id).collapsed = (value.indexOf(opt) < 0); + } + catch (e) {} + }); } let classes = tabopts.filter(function (o) value.indexOf(o[0]) == -1) .map(function (a) a[3]) if (!classes.length) { - storage.styles.removeSheet("taboptions", null, null, null, true); + styles.removeSheet("taboptions", null, null, null, true); } else { @@ -652,7 +648,7 @@ const liberator = (function () //{{{ message = util.objectToString(message); else message += "\n"; - dump(config.name.toLowerCase() + ": " + message); + dump(("config" in modules && config.name.toLowerCase()) + ": " + message); }, dumpStack: function (msg) diff --git a/content/mappings.js b/content/mappings.js index 158b9b9a..8db1afa0 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -170,7 +170,7 @@ function Mappings() //{{{ { flags: Mappings.flags.COUNT, rhs: rhs, - noremap: noremap, + noremap: !!noremap, silent: "" in args }); } diff --git a/content/style.js b/content/style.js index 55b7a542..731c1c9f 100644 --- a/content/style.js +++ b/content/style.js @@ -86,22 +86,24 @@ function Highlights(name, store, serial) Highlight.defaultValue("value", function () this.default); Highlight.prototype.toString = function () [k + ": " + util.escapeString(v || "undefined") for ([k, v] in this)].join(", "); - this.__iterator__ = function () (v for ([k,v] in Iterator(highlight))); + function keys() [k for ([k, v] in Iterator(highlight))].sort(); + this.__iterator__ = function () (highlight[v] for ([k,v] in Iterator(keys()))); this.get = function (k) highlight[k]; - this.set = function (key, newStyle, force) + this.set = function (key, newStyle, force, append) { let [, class, selectors] = key.match(/^([a-zA-Z_-]+)(.*)/); if (!(class in highlight)) return "Unknown highlight keyword"; + let style = highlight[key] || new Highlight(key); + styles.removeSheet(style.selector, null, null, null, true); + + if (append) + newStyle = (style.value || "").replace(/;?\s*$/, "; " + newStyle); if (/^\s*$/.test(newStyle)) newStyle = null; - - let style = highlight[key] || new Highlight(key); - styles.removeSheet(style.selector, null, null, true); - if (newStyle == null) { if (style.default == null) @@ -175,7 +177,7 @@ function Styles(name, store, serial) let sheet = sheets.filter(function (s) s.sites.join(",") == filter && s.css == css)[0]; if (!sheet) - sheet = new Sheet(name, filter.split(","), css, null); + sheet = new Sheet(name, filter.split(",").filter(function (s) s), css, null); if (sheet.ref == null) // Not registered yet { @@ -204,7 +206,7 @@ function Styles(name, store, serial) let names = system ? systemNames : userNames; // Grossly inefficient. - let matches = [k for ([k, v] in sheets)]; + let matches = [k for ([k, v] in Iterator(sheets))]; if (index) matches = String(index).split(",").filter(function (i) i in sheets); if (name) @@ -213,8 +215,8 @@ function Styles(name, store, serial) matches = matches.filter(function (i) sheets[i].css == css); if (filter) matches = matches.filter(function (i) sheets[i].sites.indexOf(filter) >= 0); - return matches; - }, + return matches.map(function (i) [i, sheets[i]]); + }; this.removeSheet = function (name, filter, css, index, system) { @@ -233,9 +235,8 @@ function Styles(name, store, serial) if (matches.length == 0) return; - for (let [,i] in Iterator(matches.reverse())) + for (let [,[i, sheet]] in Iterator(matches.reverse())) { - let sheet = sheets[i]; if (name) { sheet.ref.splice(sheet.ref.indexOf(name)); @@ -247,6 +248,7 @@ function Styles(name, store, serial) this.unregisterSheet(cssUri(wrapCSS(sheet))); } // Filter out the given site, and re-add if there are any left + // This could have unintended consequences if (filter) { let sites = sheet.sites.filter(function (f) f != filter); @@ -381,6 +383,15 @@ liberator.registerObserver("load_commands", function () } else { + if ("-append" in args) + { + let sheet = styles.findSheets(name, null, null, null, false)[0]; + if (sheet) + { + filter = sheet[1].sites.concat(filter).join(","); + css = sheet[1].css.replace(/;?\s*$/, "; " + css); + } + } let err = styles.addSheet(name, filter, css, false, special); if (err) liberator.echoerr(err); @@ -402,7 +413,8 @@ liberator.registerObserver("load_commands", function () bang: true, hereDoc: true, literal: true, - options: [[["-name", "-n"], commands.OPTION_STRING]], + options: [[["-name", "-n"], commands.OPTION_STRING], + [["-append", "-a"], commands.OPTION_NOARG]], serial: function () [ { command: this.name, @@ -437,6 +449,7 @@ liberator.registerObserver("load_commands", function () function (args, special) { let style =