Could someone explain this notation to me?

I’m looking at a Chrome addon that does pretty much what I want, and there is some notation that they are using to invoke context menus and prompts.

It invokes a function x (thank you for one letter non-descriptive names) using the following

x(A, "[b]", "[b]{{a}}");
x(A, "[i]", "[i]{{a}}");
x(A, "[url]", "[url]{{a}}");
x(A, "[url=sel]prompt", "[url={{a}}]{{b}}", "Description of the link");
x(A, "[url=prompt]sel", "[url={{b}}]{{a}}", "URL of the link");

There are either 3 or 4 variables, with the 4th variable being a title of a pop up asking for text.

Item 1 is the parent menu, Item 3 is a description, but Item 2 is completely incomprehensible to me as to how it works.

The text is straightforward, but I do not understand how the double curly brace terms parse, though I know that {{a}} is the selected text, and {{b}} is a request for information from a popup.

It seems to me that this notation is clean and elegant, but I don’t get it.

FWIW, here is function x():

function x(d, e, f, k) {
    k = q(k);
    var s = g({
        title: e,
        contexts: ["editable"],
        parentId: d,
        onclick: v
    });
    b[c(s)] = {
        a: f,
        b: k,
        c: e.replace(/^.*?(?=CTRL)/, "").replace(/CTRL\+/g, ""),
        d: c(d)
    }
}

And here is the initial variable declaration:

var a = {},
    b = {},
    c = JSON.stringify,
    g = chrome.contextMenus.create,
    h = chrome.contextMenus.remove,
    l = "title:",
    m = "template:",
    n = "prompt:";

I am rather confused here.

From time to time I’ve seen a JavaScript “de-obfuscator” but I can’t recall using any particular ones. Perhaps you can find one that will un-minify the code so it’s more readable.

EDIT

Without seeing what ultimately happens to f we perhaps could guess that {{a}} and {{b}} in these literal strings are placeholders indicating these values should be derived from objects a and b. As far as I can tell, the use of {{key}} is a convention of some libraries and not any kind of standard.

References:

That looks like minified code.
If the extension in question is open source, its actual source code will be available somewhere.
If it is not, you are probably not allowed to reverse engineer the code, out at least you wouldn’t be allowed to publish it (and probably also not to discuss it publicly).

Thanks for the insight on the minified code. (It means that I am a bit less dense than I had thought)

I don’t intend to publish this, though I did manage to get it to run locally on my machine using Chrome Store Foxified plus a minor change to the manifest,JSON file,* but the basic functionality is something that I lost when the old addons went away, and I want to look at the solutions. (plus handling clipboard text, which this does not).

As to reverse engineering the software, that doesn’t violate copyright, and since there is no license attached, it cannot violate that, so I figure that I am on OK legal ground there.

The addon is published on the Chrome Store (link).

  • The change to the manifest.JSON file to get the options page, which includes custom tags, working is to replace:

"options_page": "options.html",

with

"options_ui": { "page": "options.html", "browser_style": true

That’s what I found about the {{}} notation, only this addon calls no libraries.

Did some more digging, and I’ve figured out the notation.

Basically the argument is passed as a single text variable, like:

"[url={{a}}]{{b}}"

And somewhere (still not sure where) this text is parsed, and the “{{}}”" is used to signify a token which corresponds to an action (a= selection, b= popup dialogue, etc.)

Sorry if I am thinking out loud here.

This will of course depend on the applicable copyright and content-creation laws (and even finding out whose nations laws apply could be difficult).
But locenses are (partial) wavers of right reserved to the creator by law, so the absence of a license is the most restrictive “license” there is. It grants you nothing.
And yes AFAIK reverse engenneering is ok under most legislations, as long as you keep the results to yourself (and besides, who could know anyway). But publishing the results could very well be considered copyright infringement.
What you do here is publishing such results and/or asking others to do so.

So while there probably won’t be anybody who minds, what you are doing here is most likely not legal.

1 Like

I should be clear here: I am trying to recreat as closely as possible bbCodExtra, which the author is not taking to WebExtensions.

This is under MPL 2.0, and the author has told people who want to do this to, “Go for it.”

Any “reverse engineering” that I am doing has to do with learning techniques from other people’s code.

That doesn’t really affect anything of what I said (the license of the extension you want to recreate is completely irrelevant, the one of the extension you are reading matters):

If the extension in question is open source, its actual source code will be available somewhere.

(And if you can only find the license but not the source code, you can of cause use the minified code under the terms of the license as well.)

Any “reverse engineering” that I am doing has to do with learning techniques from other people’s code.

Sure. You can do that for yourself, and you can also ask general questions about reverse engineering JS code, but you can’t publish any of the results or ask other people to do so.


This is obviously just may understainding of the topic. I am neither a lawyer or a judge, I only had a few classes/lectures on (primarily German) copyright law in school and at university (engineering).