gist: 9332 Download_button fork
public
Public Clone URL: git://gist.github.com/9332.git
colourlovers-ubiquity-palette-search
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
  }
});

Owner

davidwparker

Revisions