There are loads of feature requests on Meta for adding specific 'magic links' to comments. (links that expand, eg. [edit] -> [edit](/posts/id/edit)).

So I made a userscript that allows you to create your own magic links to expand to your own custom URLs.

Usage

At the top of the script, before the -------------------------------------- add either:

  • magicLinks['COMMAND LINK TEXT'] = 'URL'; or
  • magicLinksCustomText['COMMAND'] = "URL";

The difference is that the first one acts as the standard ones do (ie a simple [command]) but the second one allows you to have custom text (something that SE doesn't have). Note the syntax for this is different, as seen in the example below.

There are few placeholder variables you can use:

  • $ANSWERID - the current answer's ID
  • $QUESTIONID - the current question's ID
  • $BASEURL$ - the base URL of the site (eg. http://stackapps.com)
  • $METABASEURL$ - the meta base URL of the site (eg. http://meta.stackapps.com)

Examples

  • magicLinks['edit/q Edit Question'] = '$BASEURL$/posts/$QUESTIONID$/edit';
    • [edit/q] --> [Edit Question](https://stackapps.com/posts/3421/edit)
  • magicLinksCustomText['edit/q'] = '$BASEURL$/posts/$QUESTIONID$/edit';
    • [Edit the question to add extra info][edit/q] --> [Edit the question to add extra info](https://stackapps.com/posts/3421/edit)

Installation

Install the script from Github Gist or view the source here.

Note: To install, you must first have a userscript management extension installed. The popular ones are Greasemonkey (for Firefox) and Tampemonkey (for Chrome). Once they are installed, simply clicking the 'install from Github gist' link above will install the script - the extension will handle everything else. More info on userscripts and their usage over here

Notes

  • As this is client-side and only acting as a shortcut for bigger chunks of text: the character count will look at the expanded text and not the shortened one :(
  • This looks potentially very useful. Unfortunately the installation instructions are insufficient for me. You wrote,: install the script from Github Gist but I don't see where or how I'm supposed to install it to. Can you explain, please? – roaima Nov 18 '15 at 0:01
  • 2
    @roaima you'll need to have userscripts enabled in your browser. In Firefox, use Greasemonkey. In Chrome, it may be natively enabled or it might require the Tampermonkey extension. Instructions for this are probably available elsewhere on the site. Either way, once your browser is set up to handle userscripts, just click on the Gist link and follow the prompts that pop up. – David Z Nov 18 '15 at 4:38
  • 1
    @roaima I'm glad it may be of use to you! :) To install, do exactly what David says! So: 1. Install the Tampermonkey extension 2. Click on the 'install from github gist link'. Tampermonkey will handle the rest for you :) – ᔕᖺᘎᕊ Nov 18 '15 at 7:15
  • Thank you. (Am I allowed to say that here? :-) ). Could you briefly extend your instructions to include the reference to greasemonkey, etc.? At least that way I'd know what to search for – roaima Nov 18 '15 at 9:09
  • @roaima done :) – ᔕᖺᘎᕊ Nov 18 '15 at 22:10

I believe you should swap the order of replacing magicLinksCustomText and magicLinks in magicLink to allow for those of us who wish to have the option of using the same magic link for both syntaxes. I've tested, and it works fine that way, but not otherwise.

Here's my current setup that necessitates this:

magicLinks['edit/q Edit Question'] = '$BASEURL$/posts/$QUESTIONID$/edit';
magicLinksCustomText['edit/q'] =     "$BASEURL$/posts/$QUESTIONID$/edit";
magicLinks['edit/a Edit Answer'] = '$BASEURL$/posts/$ANSWERID$/edit';
magicLinksCustomText['edit/a'] =   "$BASEURL$/posts/$ANSWERID$/edit";
  • 1
    I did have a reason to do it as it is now.... but I've forgotten it :/ So if I can't remember (I'll test and check), I'll push the update :) – ᔕᖺᘎᕊ Dec 1 '15 at 8:22

For requests like this, it would seem essential to have a way to fill in placeholders for sites by SE subdomain (and have a shortlist of other domains SE also manages, of course). Any plans to add that?

  • So, basically, add some placeholders for so, su, etc...? Because then you can just do something like magicLinks['so/help'] = '$so$/help'; – ᔕᖺᘎᕊ Dec 1 '15 at 8:24
  • @ᔕᖺᘎᕊ: Yeah, but also in the style of [CodeReview.se/help/on-topic]. – Nathan Tuggy Dec 1 '15 at 8:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .