Skip to content

Instantly share code, notes, and snippets.

@yoshimov
Created April 20, 2011 04:08
Show Gist options
  • Select an option

  • Save yoshimov/930319 to your computer and use it in GitHub Desktop.

Select an option

Save yoshimov/930319 to your computer and use it in GitHub Desktop.
conver as wiki link
CmdUtils.CreateCommand({
names: ["convert as wiki"],
description: "Convert current url into wiki enabled link.",
help: "Open the target url and execute covert as wiki command.",
author: {
name: "Yoshimov",
email: "yoshimov@pobox.com",
homepage: "http://yoshimov.com/",
},
license: "GPL",
homepage: "http://yoshimov.com/",
icon: "http://yoshimov.com/favicon.ico",
execute: function execute(args) {
var text = this._convert_url(CmdUtils.getDocument().location.href);
CmdUtils.copyToClipboard(text);
displayMessage("Converted url was copied to clipboard.");
},
preview: function preview(pblock, args) {
pblock.innerHTML = "Converted url: " + this._convert_url(CmdUtils.getDocument().location.href);
},
_convert_url: function(text) {
return text.replace(/{/g, "%7b").replace(/}/g, "%7d").replace(/\|/g, "%7c").replace(/\[/g, "%5b").replace(/\]/g, "%5d");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment