Created
September 7, 2008 23:26
-
-
Save davidwparker/9332 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cs_pa = ["colors","palettes"] | |
var noun_type_cs_pa = new CmdUtils.NounType( "colors or palettes", cs_pa ); | |
CmdUtils.CreateCommand({ | |
name: "color", | |
description: "Find colors and palettes on Colour Lover. Search by colors or search by colors or hex for palettes.", | |
help: "Try issuing "color blue" or "color #005F6B" by palettes", | |
icon: "http://colourlovers.com.s3.amazonaws.com/favicon.ico", | |
takes: {"color or hex": noun_arb_text}, | |
modifiers: { "by": noun_type_cs_pa}, | |
execute: function( directObj, modifier) { | |
var value = directObj.text; | |
var by = modifier.by.text; | |
var url = "http://www.colourlovers.com/colors/search?hsv=&sortType=rank&sortBy=asc&query={QUERY}"; | |
if (value){ | |
if (by){ | |
if (by.indexOf("palettes") > -1){ | |
url = url.replace(/colors/g, "palettes"); | |
url = url + "&hex={HEX}"; | |
} | |
} | |
if (value.indexOf("#") > -1){ | |
value = value.replace("#",""); | |
url = url.replace("{HEX}", value); | |
url = url.replace("{QUERY}", ""); | |
} | |
else{ | |
url = url.replace("{HEX}", ""); | |
url = url.replace("{QUERY}", value); | |
} | |
url = url.replace("{QUERY}", value); | |
} | |
Utils.openUrlInBrowser(url); | |
}, | |
preview: function( pblock, directObj, modifier) { | |
var value = directObj.text; | |
var by = modifier.by.text; | |
var message = "Searches Colour Lover Colors by color and search Palettes by color/hex."; | |
if (value.length > 2){ | |
if (by){ | |
if (by.indexOf("palettes") > -1){ | |
message = message.replace("Lover Colors", "Lover Palettes"); | |
if (value) { | |
if (value.indexOf("#") > -1){ | |
message = message.replace("by color and search Palettes by color/hex", "by the hex value: " + value); | |
} | |
else{ | |
message = message.replace("by color and search Palettes by color/hex", "by the color: " + value); | |
} | |
} | |
} | |
} | |
else{ | |
if (value){ | |
if (value.indexOf("#") > -1){ | |
message = "Colour Lovers cannot search Colors by hex."; | |
} | |
else { | |
message = message.replace("by color and search Palettes by color/hex", "by the color: " + value); | |
} | |
} | |
} | |
} | |
pblock.innerHTML = message; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment