├── extension ├── icon128.png ├── screenshot1.png ├── background.html ├── examples │ ├── gcd.js │ ├── rand.js │ └── bin.js ├── manifest.json ├── cmd.js ├── index.html └── js │ ├── main.js │ ├── complete.ly.1.0.1.js │ └── system.js ├── Makefile ├── examples ├── gcd.js ├── rand.js └── bin.js ├── osd.xml ├── LICENSE ├── README.md ├── index.html └── js ├── main.js ├── complete.ly.1.0.1.js └── system.js /extension/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellowtw/urlcmd/HEAD/extension/icon128.png -------------------------------------------------------------------------------- /extension/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellowtw/urlcmd/HEAD/extension/screenshot1.png -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | serve: 2 | python -m SimpleHTTPServer || python -m http.server 3 | 4 | extension: 5 | cp -r css examples js index.html extension 6 | zip -r extension.zip extension 7 | 8 | -------------------------------------------------------------------------------- /extension/background.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | URL Command 4 | 5 | 6 | 7 | Nothing to see here 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/gcd.js: -------------------------------------------------------------------------------- 1 | function gcd(name, utils) { 2 | return { 3 | "desc": "Calculate the gcd of two numbers", 4 | "example": name + " 5 6 -> 1", 5 | "usage": name + " x y", 6 | "gen":function(a,b) { 7 | function gcd(a,b){ 8 | if (a > b ) { 9 | return gcd(b,a); 10 | } 11 | if (b%a == 0) { 12 | return a; 13 | } 14 | return gcd(b % a, a); 15 | } 16 | 17 | return { 18 | "text": gcd(a,b) 19 | }; 20 | }, 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /extension/examples/gcd.js: -------------------------------------------------------------------------------- 1 | function gcd(name, utils) { 2 | return { 3 | "desc": "Calculate the gcd of two numbers", 4 | "example": name + " 5 6 -> 1", 5 | "usage": name + " x y", 6 | "gen":function(a,b) { 7 | function gcd(a,b){ 8 | if (a > b ) { 9 | return gcd(b,a); 10 | } 11 | if (b%a == 0) { 12 | return a; 13 | } 14 | return gcd(b % a, a); 15 | } 16 | 17 | return { 18 | "text": gcd(a,b) 19 | }; 20 | }, 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /osd.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | URL command 4 | A customizable URL command bar 5 | URL command 6 | UTF-8 7 | https://daniellowtw.github.io/urlcmd 8 | 9 | 10 | 12 | en 13 | UTF-8 14 | UTF-8 15 | -------------------------------------------------------------------------------- /extension/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 2, 3 | "name": "urlcmd", 4 | "short_name": "urlcmd", 5 | "description": "Productivity from your URL bar", 6 | "version": "0.3.0", 7 | "author": "D low", 8 | "homepage_url": "https://github.com/daniellowtw/urlcmd", 9 | "background": { 10 | "page" : "background.html", 11 | "persistent" : false 12 | }, 13 | "icons": { 14 | "16":"icon128.png", 15 | "48":"icon128.png", 16 | "128":"icon128.png" 17 | }, 18 | "omnibox": { "keyword": "url" }, 19 | "commands": { 20 | "shortcut" : { 21 | "suggested_key" : { 22 | "default" : "Alt+G" 23 | }, 24 | "description": "Open the urlcmd page" 25 | } 26 | }, 27 | "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'" 28 | } 29 | -------------------------------------------------------------------------------- /examples/rand.js: -------------------------------------------------------------------------------- 1 | function random(name, utils) { 2 | return { 3 | "desc": "Generate a random number from 1 to n inclusive, optional second argument for generating m numbers", 4 | "example": name + " 6 -> 3
" + name + " 4 2 -> 1 1", 5 | "usage": name + " n [m]", 6 | "gen": function(n, m) { 7 | function random(n, m) { 8 | var nn = parseInt(n, 10) 9 | var mm = (m === undefined) ? 1 : parseInt(m, 10) 10 | if (isNaN(nn) || isNaN(mm)) { 11 | return "cannot parse n or m as integers." 12 | } 13 | var s = "" 14 | for (var i = 0; i < mm; i ++) { 15 | s += Math.ceil(Math.random() * nn) + "
" 16 | } 17 | return s 18 | } 19 | return { 20 | "text": random(n, m) 21 | }; 22 | }, 23 | } 24 | } -------------------------------------------------------------------------------- /extension/examples/rand.js: -------------------------------------------------------------------------------- 1 | function random(name, utils) { 2 | return { 3 | "desc": "Generate a random number from 1 to n inclusive, optional second argument for generating m numbers", 4 | "example": name + " 6 -> 3
" + name + " 4 2 -> 1 1", 5 | "usage": name + " n [m]", 6 | "gen": function(n, m) { 7 | function random(n, m) { 8 | var nn = parseInt(n, 10) 9 | var mm = (m === undefined) ? 1 : parseInt(m, 10) 10 | if (isNaN(nn) || isNaN(mm)) { 11 | return "cannot parse n or m as integers." 12 | } 13 | var s = "" 14 | for (var i = 0; i < mm; i ++) { 15 | s += Math.ceil(Math.random() * nn) + "
" 16 | } 17 | return s 18 | } 19 | return { 20 | "text": random(n, m) 21 | }; 22 | }, 23 | } 24 | } -------------------------------------------------------------------------------- /examples/bin.js: -------------------------------------------------------------------------------- 1 | function gcd(name, utils) { 2 | return { 3 | "desc": "convert between binary and string", 4 | "example": name + " s2b -> 1", 5 | "gen": function(type, s) { 6 | function binaryStringToString(x) { 7 | return x.split(" ").map(function(y) { 8 | return String.fromCharCode(parseInt(y, 2)) 9 | }).join("") 10 | } 11 | 12 | function stringToBinaryString(x) { 13 | return x.split("").map(function(x) { 14 | return x.charCodeAt().toString(2) 15 | }).join(" ") 16 | } 17 | var text = "wrong usage"; 18 | if (type == "b2s") { 19 | text = binaryStringToString(s) 20 | } else if (type == "s2b") { 21 | text = stringToBinaryString(s) 22 | } 23 | return { 24 | "text": text 25 | }; 26 | }, 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /extension/examples/bin.js: -------------------------------------------------------------------------------- 1 | function gcd(name, utils) { 2 | return { 3 | "desc": "convert between binary and string", 4 | "example": name + " s2b -> 1", 5 | "gen": function(type, s) { 6 | function binaryStringToString(x) { 7 | return x.split(" ").map(function(y) { 8 | return String.fromCharCode(parseInt(y, 2)) 9 | }).join("") 10 | } 11 | 12 | function stringToBinaryString(x) { 13 | return x.split("").map(function(x) { 14 | return x.charCodeAt().toString(2) 15 | }).join(" ") 16 | } 17 | var text = "wrong usage"; 18 | if (type == "b2s") { 19 | text = binaryStringToString(s) 20 | } else if (type == "s2b") { 21 | text = stringToBinaryString(s) 22 | } 23 | return { 24 | "text": text 25 | }; 26 | }, 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Daniel Low 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # URL command 2 | 3 | Try it at 4 | 5 | ## Introduction 6 | 7 | This is a productivity tool by hacking the browser's custom search engine and treating the query string as a command with its arguments. It allows you to create aliases (shortcuts) for: 8 | 9 | * Parameterised templated url (e.g. `https://..yourdomain.com`) 10 | * Built-in utility functions (e.g. `secs [timestamp]`) 11 | * Third-party functions (e.g. `import `) 12 | 13 | This allows importing of personal aliases, like a portable `.bashrc`. Bring your keyboard ninja skills to someone else's machine today! 14 | 15 | ## Examples 16 | 17 | The following assumes you've added the keyword `url` for the search engine, and will type the commands in the omnibox. 18 | 19 | * `alias x http://xkcd.com` means typing `url x` will redirect you to `http://xkcd.com`. 20 | * `alias gd https://godoc.org/?q={0}` means typing `url gd atomic` would search for atomic in another search engine. 21 | * `import gcd examples/gcd.js` will import the `gcd` function so that typing `url gcd 14 21` will print `7`. 22 | * `alias x` will remove the alias `x` 23 | 24 | ## Installation 25 | 26 | Webapp: Go to and click on `Install` at the top right. 27 | 28 | Chrome extension : 29 | Alt-G or prefix your command with `url` in the URL bar. 30 | 31 | ## Third party functions 32 | 33 | * Greatest common divisor `import gcd examples/gcd.js` 34 | * Random number generator `import rand examples/rand.js` 35 | * Binary <-> ascii `import bin examples/bin.js` 36 | -------------------------------------------------------------------------------- /extension/cmd.js: -------------------------------------------------------------------------------- 1 | var HISTORY_KEY = 'sbHistory'; 2 | var sbHistory = getHistory(); 3 | 4 | chrome.commands.onCommand.addListener(function(command) { 5 | console.log(1) 6 | chrome.tabs.create({ 7 | url: chrome.extension.getURL('index.html') 8 | }); 9 | }); 10 | 11 | 12 | function parseUserInput(text) { 13 | var res = sbHistory.map(x => { 14 | return { 15 | "content": x.content, 16 | "description": x.description, 17 | } 18 | }) 19 | return res || [] 20 | } 21 | 22 | function setHistory(sbHistory) { 23 | console.log("setting history") 24 | localStorage.setItem(HISTORY_KEY, JSON.stringify(sbHistory)); 25 | } 26 | 27 | function getHistory() { 28 | console.log("getting history") 29 | try { 30 | return JSON.parse(localStorage.getItem(HISTORY_KEY)) || []; 31 | } catch (ex) { 32 | return []; 33 | } 34 | } 35 | 36 | // This is triggered when the input changes 37 | chrome.omnibox.onInputChanged.addListener( 38 | function(text, suggest) { 39 | suggest(parseUserInput(text)); 40 | } 41 | ); 42 | 43 | // This is triggered when entered is pressed 44 | chrome.omnibox.onInputEntered.addListener( 45 | function(text) { 46 | 47 | if (text == "!clear") { 48 | setHistory([]) 49 | sbHistory = [] 50 | return 51 | } 52 | sbHistory.push({ 53 | content: text, 54 | description: text, // TODO 55 | }) 56 | if (sbHistory.length > 15) { 57 | sbHistory.shift() 58 | } 59 | setHistory(sbHistory) 60 | chrome.tabs.update(null, { 61 | url: chrome.extension.getURL(`index.html#${text}`) 62 | }); 63 | } 64 | ); -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | URL Command 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 34 | 35 | 36 | 37 |
38 |
39 | 40 |
41 | 42 |
43 |
44 |

45 | URL Command 46 |

47 |
48 |
49 | 50 |
51 |

Load config

52 |

Install

53 |
54 |
55 |

56 |

57 |

58 |
59 |
60 |
61 |
62 |
63 | 64 | 97 | 98 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /extension/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | URL Command 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 34 | 35 | 36 | 37 |
38 |
39 | 40 |
41 | 42 |
43 |
44 |

45 | URL Command 46 |

47 |
48 |
49 | 50 |
51 |

Load config

52 |

Install

53 |
54 |
55 |

56 |

57 |

58 |
59 |
60 |
61 |
62 |
63 | 64 | 97 | 98 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /js/main.js: -------------------------------------------------------------------------------- 1 | var ALIASES_KEY = "sb"; 2 | 3 | /* 4 | A command has the following properties 5 | 6 | desc - A short description 7 | usage - a short text to describe how to use the command 8 | example - using it in action 9 | gen - execute the function 10 | */ 11 | 12 | 13 | 14 | var utils = { 15 | format: function() { 16 | var newArguments = [].slice.call(arguments, 1) 17 | var args = newArguments; 18 | var s = arguments[0] 19 | return s.replace(/{(\d+)}/g, (match, number) => { 20 | return typeof args[number] != 'undefined' ? args[number] : match; 21 | }); 22 | }, 23 | redirect: function(url) { 24 | window.location.assign(url); 25 | chrome.tabs.query({ 26 | active: true, 27 | currentWindow: true 28 | }, function(tabs) { 29 | chrome.tabs.update(tabs[0].id, { 30 | url: url 31 | }); 32 | }); 33 | } 34 | } 35 | 36 | var baseCommands = { 37 | "secs": { 38 | desc: "Unix timestamp conversion", 39 | gen: function(q) { 40 | if (!q) { 41 | return { 42 | text: parseInt(new Date().getTime() / 1000, 10) 43 | }; 44 | } else { 45 | return { 46 | text: new Date(parseInt(q, 10) * 1000) 47 | } 48 | } 49 | } 50 | }, 51 | "tr": { 52 | desc: "Google Translate", 53 | usage: "tr [[from]:[to]] text", 54 | example: "Example: tr ro:fr buna ziua", 55 | gen: function(q) { 56 | if (!q) { 57 | return { 58 | text: this.example 59 | }; 60 | } 61 | var components = q.match(/^(([a-zA-Z\-]*):([a-zA-Z\-]*)\s+)?(.*$)/); 62 | var from = components[2] || 'auto'; 63 | var to = components[3] || 'en'; 64 | var text = components[4]; 65 | return { 66 | url: "https://translate.google.com/#" + from + "/" + to + "/" + text 67 | }; 68 | } 69 | }, 70 | "notepad" : { 71 | desc: "create a scratch pad", 72 | usage: "notepad", 73 | gen: function() { 74 | return { 75 | url: "data:text/html," 76 | }; 77 | } 78 | } 79 | }; 80 | 81 | var coreCommands = { 82 | "help": { 83 | desc: "List available commands", 84 | gen: function(_unused) { 85 | listAll(); 86 | return true; 87 | } 88 | }, 89 | "alias": { 90 | desc: "Add or remove an alias", 91 | example: "alias hn https://news.ycombinator.com
alias foo http://{0}.{1}.com
", 92 | usage: "alias name target [target if no args]", 93 | 94 | gen: function(q, args) { 95 | var cmdName = args[0].toLowerCase(); 96 | if (cmdName) { 97 | aliases = getAliases(); 98 | if (args.length == 1) { 99 | delete aliases[cmdName]; 100 | } else { 101 | aliases[cmdName] = { 102 | target: args[1].match(/^[a-zA-Z_\-$]+$/) ? args[1] : undefined, // points to another command 103 | url: args[1].match(/^[a-zA-Z_\-$]+$/) ? undefined : args[1], 104 | urlNoArgs: args[2], 105 | desc: "redirects: " + args[1] + "" + (args[2] === undefined ? "" : "
Without args: " + args[2] + ""), 106 | }; 107 | } 108 | setAliases(aliases) 109 | } 110 | return { 111 | text: "Invalid usage", 112 | }; 113 | } 114 | }, 115 | "rm": { 116 | desc: "Remove aliases", 117 | example: "Usage: rm cmd1 cmd2 cmd3
", 118 | gen: function(q, args) { 119 | aliases = getAliases(); 120 | args.forEach(x=> delete aliases[x]); 121 | setAliases(aliases); 122 | return { 123 | text: "Usage: rm cmd1 cmd2 cmd3
" 124 | }; 125 | } 126 | }, 127 | "import": { 128 | "desc": "Import commands/aliases from a url", 129 | "example": "import bar foo.js", 130 | gen: function(q, args) { 131 | if (args.length != 2) { 132 | return { 133 | "text": "Usage: import bar foo.js" 134 | } 135 | } 136 | 137 | var name = args[0]; 138 | var url = args[1]; 139 | importFromURL(name, url).then(cmd => { 140 | aliases = getAliases(); 141 | aliases[name] = cmd; 142 | setAliases(aliases); 143 | }).catch(console.log) 144 | 145 | return { 146 | "text": "Imported as " + name 147 | } 148 | } 149 | }, 150 | "export": { 151 | "desc": "Output the current aliases for sharing", 152 | "usage": "export", 153 | "gen": function(q, args) { 154 | return { 155 | "text": "" 156 | } 157 | } 158 | } 159 | }; 160 | 161 | function importFromURL(name, url) { 162 | return System.import(url).then(m => { 163 | var x = m(name, utils); 164 | x.genString = x.gen.toString() 165 | x.genSrc = true; 166 | return x; 167 | }); 168 | } 169 | 170 | function setAliases(aliases) { 171 | localStorage.setItem(ALIASES_KEY, JSON.stringify(aliases)); 172 | } 173 | 174 | function getAliases() { 175 | try { 176 | return JSON.parse(localStorage.getItem(ALIASES_KEY)) || {}; 177 | } catch (ex) { 178 | return {}; 179 | } 180 | } 181 | 182 | function parseArgs(s) { 183 | if (s.indexOf(s, '"') == -1) { 184 | return s.split(" "); 185 | } 186 | var spaceSeparatedList = s.split(" "); 187 | var res = []; 188 | var currWord = ""; 189 | var currIndex = 0; 190 | do { 191 | currWord = spaceSeparatedList[currIndex]; 192 | currIndex++; 193 | if (currWord[0] == '"') { 194 | currWord= currWord.substr(1) 195 | while((currWord[currWord.length-1] != '"') 196 | && (currIndex < spaceSeparatedList.length)) { 197 | var temp = spaceSeparatedList[currIndex]; 198 | currIndex++; 199 | if (temp === undefined) { 200 | return spaceSeparatedList; 201 | } 202 | currWord += ` ${temp}` 203 | currWord = currWord.substring(0, currWord.length-1) 204 | } 205 | } 206 | res.push(currWord); 207 | } while (currIndex < spaceSeparatedList.length) 208 | return res; 209 | } 210 | 211 | // CommandSetLoader tries to execute the command in the command set that corresponds to the name 212 | function CommandSetLoader(commandSet, opts) { 213 | return { 214 | gen: function(q) { 215 | var components = q.split(" "); 216 | var cmd = components[0].toLowerCase(); 217 | var args = q.substring(components[0].length + 1); 218 | var params = parseArgs(args); 219 | var r = commandSet[cmd]; 220 | if (r && r.target) { 221 | return applyLoader( 222 | r.target + " " + args 223 | ); 224 | } 225 | 226 | if (!r) { 227 | return false; 228 | } 229 | if ((!args || !r.url) && r.urlNoArgs) { 230 | return { 231 | url: r.urlNoArgs 232 | }; 233 | } else if (r.url) { 234 | params.unshift(r.url) 235 | return { 236 | url: utils.format.apply(null, params) 237 | }; 238 | } else if (r.genSrc) { 239 | try { 240 | var x = (new Function("return " + r.genString))(); 241 | } catch (err) { 242 | return { 243 | "text": "bad imported code" + err 244 | } 245 | } 246 | return x.apply(null, params); 247 | } else if (r.gen) { 248 | return r.gen(args, params); 249 | } 250 | return false; 251 | }, 252 | list: function() { 253 | var result = []; 254 | for (var key in commandSet) { 255 | result.push({ 256 | cmd: key, 257 | cmdObject: commandSet[key], 258 | style: (opts || {}).listStyle, 259 | }); 260 | } 261 | return result; 262 | } 263 | }; 264 | } 265 | 266 | function AliasLoader() { 267 | return CommandSetLoader(getAliases(), { 268 | listStyle: "color: red;" 269 | }); 270 | } 271 | 272 | function FallbackLoader(r) { 273 | return { 274 | gen: function(q) { 275 | if (/%s/.test(r.url)) { 276 | return { 277 | url: r.url.replace("%s", encodeURIComponent(q)) 278 | } 279 | } 280 | listAll(); 281 | return true; 282 | } 283 | }; 284 | } 285 | 286 | 287 | var loaders = [ 288 | AliasLoader(), 289 | CommandSetLoader(coreCommands, { 290 | listStyle: "color: navy;" 291 | }), 292 | CommandSetLoader(baseCommands), 293 | FallbackLoader(coreCommands["help"]) 294 | ]; 295 | 296 | var loaderCalls = 0; 297 | 298 | // try and use all the given loaders on the query text. 299 | function applyLoader(text) { 300 | loaderCalls += 1; 301 | if (loaderCalls > 10) { 302 | return { 303 | text: "Invalid alias chain" 304 | }; 305 | } 306 | for (var i = 0; i < loaders.length; i++) { 307 | var r = loaders[i].gen(text); 308 | if (r) { 309 | return r; 310 | } 311 | } 312 | } 313 | 314 | // navigate redirects the browser to the given url 315 | function navigate(url) { 316 | window.location.assign(url); 317 | chrome.tabs.query({ 318 | active: true, 319 | currentWindow: true 320 | }, function(tabs) { 321 | chrome.tabs.update(tabs[0].id, { 322 | url: url 323 | }); 324 | }); 325 | } 326 | 327 | // splitArgs parses the query from the url. It converts ?q=foo%20bar%20car into {"q":"foo bar car"} 328 | function splitArgs(loc) { 329 | var hash = loc.hash.substr(1); 330 | hash = decodeURIComponent(hash) 331 | if (hash !== "") { 332 | return {q:hash} 333 | } 334 | var s = loc.search 335 | var s = decodeURIComponent(s) 336 | var result = {}; 337 | var pairs = s.split(/[&?]/); 338 | for (var i = 0; i < pairs.length; i++) { 339 | if (!pairs[i]) { 340 | continue; 341 | } 342 | var groups = /([^=]*)(=(.*$))?/.exec(pairs[i]); 343 | result[groups[1]] = decodeURIComponent(groups[3].replace(/\+/g, '%20')); 344 | } 345 | return result; 346 | } 347 | 348 | 349 | function listAll() { 350 | var result = []; 351 | var seen = {}; 352 | // hacks to make sure we load latest aliases 353 | loaders[0] = AliasLoader() 354 | for (var i = 0; i < loaders.length; i++) { 355 | if (!loaders[i].list) { 356 | continue; 357 | } 358 | var l = (loaders[i].list || function() { 359 | return []; 360 | })(); 361 | for (var j = 0; j < l.length; j++) { 362 | if (!seen[l[j].cmd]) { 363 | result.push(l[j]); 364 | seen[l[j].cmd] = true; 365 | } 366 | } 367 | }; 368 | 369 | // If updating fails because dom is not loaded, then wait for it to load. 370 | try { 371 | document.getElementById('list-all-content').innerHTML = displayEntries(result); 372 | } catch (e) { 373 | document.addEventListener("DOMContentLoaded", function(event) { 374 | document.getElementById('list-all-content').innerHTML = displayEntries(result); 375 | }); 376 | } 377 | } 378 | 379 | // Writes the given content into the correct div 380 | function displayContent(content) { 381 | // If updating fails because dom is not loaded, then wait for it to load. 382 | try { 383 | document.getElementById('content').innerHTML = content; 384 | } catch (e) { 385 | document.addEventListener("DOMContentLoaded", function(event) { 386 | document.getElementById('content').innerHTML = content; 387 | }); 388 | } 389 | } 390 | 391 | // Entry point, bootstrap and check if requirements are met. 392 | if (supports_html5_storage()) { 393 | executeCmd(); 394 | document.addEventListener("DOMContentLoaded", function(event) { 395 | setUpHelp(); 396 | setUpLoad(); 397 | setUpAutoComplete(); 398 | }); 399 | 400 | } else { 401 | document.write("This app requires Localstorage but it is not supported by your browser. Please use a newer browser.") 402 | } 403 | 404 | // supports_html5_storage checks if the user agent supports localStorage. 405 | function supports_html5_storage() { 406 | try { 407 | return 'localStorage' in window && window['localStorage'] !== null; 408 | } catch (e) { 409 | return false; 410 | } 411 | } 412 | 413 | 414 | /* UI STUFF */ 415 | 416 | // setUpHelp bootstraps the help mechanism. 417 | function setUpHelp() { 418 | var helpEl = document.getElementById('help') 419 | var currentClass = helpEl.className 420 | document.getElementById('helpOpen').onclick = () => { 421 | helpEl.className += " is-active"; 422 | } 423 | helpEl.lastElementChild.onclick = () => { 424 | helpEl.className = currentClass; 425 | } 426 | } 427 | 428 | // setUpLoad bootstraps the load mechanism. 429 | function setUpLoad() { 430 | function importStuff() { 431 | var x = document.getElementById('importContent').value; 432 | try { 433 | var res = JSON.parse(x) 434 | localStorage.setItem(ALIASES_KEY, x); 435 | loadEl.className = currentClass; 436 | displayContent("loaded") 437 | listAll() 438 | } catch (err) { 439 | alert("loading: " + err) 440 | } 441 | } 442 | 443 | var loadEl = document.getElementById('load') 444 | var currentClass = loadEl.className 445 | document.getElementById('loadOpen').onclick = () => { 446 | loadEl.className += " is-active"; 447 | } 448 | // add handler for cancel button 449 | document.getElementById('submitLoadBtn').onclick = importStuff 450 | // add handler for cancel button 451 | document.getElementById('cancelLoadBtn').onclick = () => { 452 | loadEl.className = currentClass; 453 | } 454 | // add handler for top right cross 455 | loadEl.lastElementChild.onclick = () => { 456 | loadEl.className = currentClass; 457 | } 458 | } 459 | 460 | // displayEntries takes a result and returns a html string for representing the result in a table 461 | function displayEntries(result, opts) { 462 | var opts = opts || {}; 463 | if (opts.withSort) { 464 | 465 | result.sort(function(a, b) { 466 | if (a.cmd < b.cmd) { 467 | return -1; 468 | } else if (a.cmd > b.cmd) { 469 | return 1; 470 | } else { 471 | return 0; 472 | } 473 | }); 474 | } 475 | 476 | var res = "" 477 | res += "

Available commands

"; 478 | res += ''; 479 | 480 | for (var i = 0; i < result.length; i++) { 481 | var styleDesc = result[i].style ? 'style="' + result[i].style + '"' : ""; 482 | res += ""; 483 | var cmdObject = result[i].cmdObject; 484 | if (cmdObject.target) { 485 | res += ""; 486 | } else { 487 | res += ""; 488 | } 489 | res += "\n"; 490 | } 491 | 492 | res += "
" + result[i].cmd + " " + cmdObject.target + "" + (cmdObject.desc || "") + (cmdObject.example ? "
" + cmdObject.example : "") + "

"; 493 | res += "General usage is: cmd [query]"; 494 | return res 495 | } 496 | 497 | 498 | function doQuery(text) { 499 | var query = text; 500 | if (query === "") { 501 | var el = document.getElementById("query-text"); 502 | query = el.value; 503 | el.value = ""; 504 | } 505 | window.location.href='index.html#' + query; // Will not trigger refresh 506 | executeCmd(); 507 | } 508 | 509 | function executeCmd() { 510 | displayContent(""); // clear content 511 | var searchQuery = splitArgs(window.location).q; 512 | if (searchQuery) { 513 | document.title = searchQuery; 514 | var r = applyLoader(searchQuery); 515 | if (r) { 516 | if (r.url) { 517 | navigate(r.url); 518 | } else if (r.text) { 519 | displayContent(r.text); 520 | } 521 | } 522 | listAll() 523 | } else { 524 | listAll() 525 | } 526 | } 527 | 528 | function makeList(obj) { 529 | var x = []; 530 | for (var key in obj) { 531 | var temp = obj[key]; // maybe clone 532 | temp.name = key; 533 | x.push(temp); 534 | } 535 | for (var i in baseCommands) { 536 | var temp = baseCommands[i]; // maybe clone 537 | temp.name = i; 538 | x.push(temp); 539 | 540 | } 541 | for (var i in coreCommands) { 542 | var temp = coreCommands[i]; // maybe clone 543 | temp.name = i; 544 | x.push(temp); 545 | } 546 | 547 | return x; 548 | } 549 | 550 | function doSearch(text) { 551 | // TODO: cache this so we don't always update 552 | var list = makeList(getAliases()); 553 | var res = []; 554 | list.forEach(x => { 555 | res.push({"name":x["name"], "usage": x["usage"]||undefined}) 556 | }) 557 | return res; 558 | } 559 | 560 | function setUpAutoComplete() { 561 | var pv = completely(document.getElementById('container-search')); 562 | pv.options = []; 563 | pv.repaint(); 564 | 565 | pv.onChange = function (text) { 566 | if (text.length == 0) { 567 | pv.options = []; 568 | pv.repaint(); 569 | return; 570 | } 571 | var oj = doSearch(text); 572 | pv.options =[]; 573 | for (var i in oj) { pv.options.push(oj[i].usage || oj[i].name); } 574 | pv.repaint(); 575 | pv.input.focus(); 576 | }; 577 | 578 | // Hacks to fix stying of the generated elements 579 | pv.input.className="input" 580 | pv.input.placeholder="Command. Try 'help'" 581 | pv.hint.className="input" 582 | pv.prompt.className="input" 583 | pv.wrapper.className="control has-addons" 584 | 585 | // Trigger search when user enters 586 | pv.onEnter = function(){ 587 | doQuery(pv.input.value); 588 | pv.setText(''); 589 | } 590 | 591 | setTimeout(function() { 592 | pv.input.focus(); 593 | },0); 594 | } -------------------------------------------------------------------------------- /extension/js/main.js: -------------------------------------------------------------------------------- 1 | var ALIASES_KEY = "sb"; 2 | 3 | /* 4 | A command has the following properties 5 | 6 | desc - A short description 7 | usage - a short text to describe how to use the command 8 | example - using it in action 9 | gen - execute the function 10 | */ 11 | 12 | 13 | 14 | var utils = { 15 | format: function() { 16 | var newArguments = [].slice.call(arguments, 1) 17 | var args = newArguments; 18 | var s = arguments[0] 19 | return s.replace(/{(\d+)}/g, (match, number) => { 20 | return typeof args[number] != 'undefined' ? args[number] : match; 21 | }); 22 | }, 23 | redirect: function(url) { 24 | window.location.assign(url); 25 | chrome.tabs.query({ 26 | active: true, 27 | currentWindow: true 28 | }, function(tabs) { 29 | chrome.tabs.update(tabs[0].id, { 30 | url: url 31 | }); 32 | }); 33 | } 34 | } 35 | 36 | var baseCommands = { 37 | "secs": { 38 | desc: "Unix timestamp conversion", 39 | gen: function(q) { 40 | if (!q) { 41 | return { 42 | text: parseInt(new Date().getTime() / 1000, 10) 43 | }; 44 | } else { 45 | return { 46 | text: new Date(parseInt(q, 10) * 1000) 47 | } 48 | } 49 | } 50 | }, 51 | "tr": { 52 | desc: "Google Translate", 53 | usage: "tr [[from]:[to]] text", 54 | example: "Example: tr ro:fr buna ziua", 55 | gen: function(q) { 56 | if (!q) { 57 | return { 58 | text: this.example 59 | }; 60 | } 61 | var components = q.match(/^(([a-zA-Z\-]*):([a-zA-Z\-]*)\s+)?(.*$)/); 62 | var from = components[2] || 'auto'; 63 | var to = components[3] || 'en'; 64 | var text = components[4]; 65 | return { 66 | url: "https://translate.google.com/#" + from + "/" + to + "/" + text 67 | }; 68 | } 69 | }, 70 | "notepad" : { 71 | desc: "create a scratch pad", 72 | usage: "notepad", 73 | gen: function() { 74 | return { 75 | url: "data:text/html," 76 | }; 77 | } 78 | } 79 | }; 80 | 81 | var coreCommands = { 82 | "help": { 83 | desc: "List available commands", 84 | gen: function(_unused) { 85 | listAll(); 86 | return true; 87 | } 88 | }, 89 | "alias": { 90 | desc: "Add or remove an alias", 91 | example: "alias hn https://news.ycombinator.com
alias foo http://{0}.{1}.com
", 92 | usage: "alias name target [target if no args]", 93 | 94 | gen: function(q, args) { 95 | var cmdName = args[0].toLowerCase(); 96 | if (cmdName) { 97 | aliases = getAliases(); 98 | if (args.length == 1) { 99 | delete aliases[cmdName]; 100 | } else { 101 | aliases[cmdName] = { 102 | target: args[1].match(/^[a-zA-Z_\-$]+$/) ? args[1] : undefined, // points to another command 103 | url: args[1].match(/^[a-zA-Z_\-$]+$/) ? undefined : args[1], 104 | urlNoArgs: args[2], 105 | desc: "redirects: " + args[1] + "" + (args[2] === undefined ? "" : "
Without args: " + args[2] + ""), 106 | }; 107 | } 108 | setAliases(aliases) 109 | } 110 | return { 111 | text: "Invalid usage", 112 | }; 113 | } 114 | }, 115 | "rm": { 116 | desc: "Remove aliases", 117 | example: "Usage: rm cmd1 cmd2 cmd3
", 118 | gen: function(q, args) { 119 | aliases = getAliases(); 120 | args.forEach(x=> delete aliases[x]); 121 | setAliases(aliases); 122 | return { 123 | text: "Usage: rm cmd1 cmd2 cmd3
" 124 | }; 125 | } 126 | }, 127 | "import": { 128 | "desc": "Import commands/aliases from a url", 129 | "example": "import bar foo.js", 130 | gen: function(q, args) { 131 | if (args.length != 2) { 132 | return { 133 | "text": "Usage: import bar foo.js" 134 | } 135 | } 136 | 137 | var name = args[0]; 138 | var url = args[1]; 139 | importFromURL(name, url).then(cmd => { 140 | aliases = getAliases(); 141 | aliases[name] = cmd; 142 | setAliases(aliases); 143 | }).catch(console.log) 144 | 145 | return { 146 | "text": "Imported as " + name 147 | } 148 | } 149 | }, 150 | "export": { 151 | "desc": "Output the current aliases for sharing", 152 | "usage": "export", 153 | "gen": function(q, args) { 154 | return { 155 | "text": "" 156 | } 157 | } 158 | } 159 | }; 160 | 161 | function importFromURL(name, url) { 162 | return System.import(url).then(m => { 163 | var x = m(name, utils); 164 | x.genString = x.gen.toString() 165 | x.genSrc = true; 166 | return x; 167 | }); 168 | } 169 | 170 | function setAliases(aliases) { 171 | localStorage.setItem(ALIASES_KEY, JSON.stringify(aliases)); 172 | } 173 | 174 | function getAliases() { 175 | try { 176 | return JSON.parse(localStorage.getItem(ALIASES_KEY)) || {}; 177 | } catch (ex) { 178 | return {}; 179 | } 180 | } 181 | 182 | function parseArgs(s) { 183 | if (s.indexOf(s, '"') == -1) { 184 | return s.split(" "); 185 | } 186 | var spaceSeparatedList = s.split(" "); 187 | var res = []; 188 | var currWord = ""; 189 | var currIndex = 0; 190 | do { 191 | currWord = spaceSeparatedList[currIndex]; 192 | currIndex++; 193 | if (currWord[0] == '"') { 194 | currWord= currWord.substr(1) 195 | while((currWord[currWord.length-1] != '"') 196 | && (currIndex < spaceSeparatedList.length)) { 197 | var temp = spaceSeparatedList[currIndex]; 198 | currIndex++; 199 | if (temp === undefined) { 200 | return spaceSeparatedList; 201 | } 202 | currWord += ` ${temp}` 203 | currWord = currWord.substring(0, currWord.length-1) 204 | } 205 | } 206 | res.push(currWord); 207 | } while (currIndex < spaceSeparatedList.length) 208 | return res; 209 | } 210 | 211 | // CommandSetLoader tries to execute the command in the command set that corresponds to the name 212 | function CommandSetLoader(commandSet, opts) { 213 | return { 214 | gen: function(q) { 215 | var components = q.split(" "); 216 | var cmd = components[0].toLowerCase(); 217 | var args = q.substring(components[0].length + 1); 218 | var params = parseArgs(args); 219 | var r = commandSet[cmd]; 220 | if (r && r.target) { 221 | return applyLoader( 222 | r.target + " " + args 223 | ); 224 | } 225 | 226 | if (!r) { 227 | return false; 228 | } 229 | if ((!args || !r.url) && r.urlNoArgs) { 230 | return { 231 | url: r.urlNoArgs 232 | }; 233 | } else if (r.url) { 234 | params.unshift(r.url) 235 | return { 236 | url: utils.format.apply(null, params) 237 | }; 238 | } else if (r.genSrc) { 239 | try { 240 | var x = (new Function("return " + r.genString))(); 241 | } catch (err) { 242 | return { 243 | "text": "bad imported code" + err 244 | } 245 | } 246 | return x.apply(null, params); 247 | } else if (r.gen) { 248 | return r.gen(args, params); 249 | } 250 | return false; 251 | }, 252 | list: function() { 253 | var result = []; 254 | for (var key in commandSet) { 255 | result.push({ 256 | cmd: key, 257 | cmdObject: commandSet[key], 258 | style: (opts || {}).listStyle, 259 | }); 260 | } 261 | return result; 262 | } 263 | }; 264 | } 265 | 266 | function AliasLoader() { 267 | return CommandSetLoader(getAliases(), { 268 | listStyle: "color: red;" 269 | }); 270 | } 271 | 272 | function FallbackLoader(r) { 273 | return { 274 | gen: function(q) { 275 | if (/%s/.test(r.url)) { 276 | return { 277 | url: r.url.replace("%s", encodeURIComponent(q)) 278 | } 279 | } 280 | listAll(); 281 | return true; 282 | } 283 | }; 284 | } 285 | 286 | 287 | var loaders = [ 288 | AliasLoader(), 289 | CommandSetLoader(coreCommands, { 290 | listStyle: "color: navy;" 291 | }), 292 | CommandSetLoader(baseCommands), 293 | FallbackLoader(coreCommands["help"]) 294 | ]; 295 | 296 | var loaderCalls = 0; 297 | 298 | // try and use all the given loaders on the query text. 299 | function applyLoader(text) { 300 | loaderCalls += 1; 301 | if (loaderCalls > 10) { 302 | return { 303 | text: "Invalid alias chain" 304 | }; 305 | } 306 | for (var i = 0; i < loaders.length; i++) { 307 | var r = loaders[i].gen(text); 308 | if (r) { 309 | return r; 310 | } 311 | } 312 | } 313 | 314 | // navigate redirects the browser to the given url 315 | function navigate(url) { 316 | window.location.assign(url); 317 | chrome.tabs.query({ 318 | active: true, 319 | currentWindow: true 320 | }, function(tabs) { 321 | chrome.tabs.update(tabs[0].id, { 322 | url: url 323 | }); 324 | }); 325 | } 326 | 327 | // splitArgs parses the query from the url. It converts ?q=foo%20bar%20car into {"q":"foo bar car"} 328 | function splitArgs(loc) { 329 | var hash = loc.hash.substr(1); 330 | hash = decodeURIComponent(hash) 331 | if (hash !== "") { 332 | return {q:hash} 333 | } 334 | var s = loc.search 335 | var s = decodeURIComponent(s) 336 | var result = {}; 337 | var pairs = s.split(/[&?]/); 338 | for (var i = 0; i < pairs.length; i++) { 339 | if (!pairs[i]) { 340 | continue; 341 | } 342 | var groups = /([^=]*)(=(.*$))?/.exec(pairs[i]); 343 | result[groups[1]] = decodeURIComponent(groups[3].replace(/\+/g, '%20')); 344 | } 345 | return result; 346 | } 347 | 348 | 349 | function listAll() { 350 | var result = []; 351 | var seen = {}; 352 | // hacks to make sure we load latest aliases 353 | loaders[0] = AliasLoader() 354 | for (var i = 0; i < loaders.length; i++) { 355 | if (!loaders[i].list) { 356 | continue; 357 | } 358 | var l = (loaders[i].list || function() { 359 | return []; 360 | })(); 361 | for (var j = 0; j < l.length; j++) { 362 | if (!seen[l[j].cmd]) { 363 | result.push(l[j]); 364 | seen[l[j].cmd] = true; 365 | } 366 | } 367 | }; 368 | 369 | // If updating fails because dom is not loaded, then wait for it to load. 370 | try { 371 | document.getElementById('list-all-content').innerHTML = displayEntries(result); 372 | } catch (e) { 373 | document.addEventListener("DOMContentLoaded", function(event) { 374 | document.getElementById('list-all-content').innerHTML = displayEntries(result); 375 | }); 376 | } 377 | } 378 | 379 | // Writes the given content into the correct div 380 | function displayContent(content) { 381 | // If updating fails because dom is not loaded, then wait for it to load. 382 | try { 383 | document.getElementById('content').innerHTML = content; 384 | } catch (e) { 385 | document.addEventListener("DOMContentLoaded", function(event) { 386 | document.getElementById('content').innerHTML = content; 387 | }); 388 | } 389 | } 390 | 391 | // Entry point, bootstrap and check if requirements are met. 392 | if (supports_html5_storage()) { 393 | executeCmd(); 394 | document.addEventListener("DOMContentLoaded", function(event) { 395 | setUpHelp(); 396 | setUpLoad(); 397 | setUpAutoComplete(); 398 | }); 399 | 400 | } else { 401 | document.write("This app requires Localstorage but it is not supported by your browser. Please use a newer browser.") 402 | } 403 | 404 | // supports_html5_storage checks if the user agent supports localStorage. 405 | function supports_html5_storage() { 406 | try { 407 | return 'localStorage' in window && window['localStorage'] !== null; 408 | } catch (e) { 409 | return false; 410 | } 411 | } 412 | 413 | 414 | /* UI STUFF */ 415 | 416 | // setUpHelp bootstraps the help mechanism. 417 | function setUpHelp() { 418 | var helpEl = document.getElementById('help') 419 | var currentClass = helpEl.className 420 | document.getElementById('helpOpen').onclick = () => { 421 | helpEl.className += " is-active"; 422 | } 423 | helpEl.lastElementChild.onclick = () => { 424 | helpEl.className = currentClass; 425 | } 426 | } 427 | 428 | // setUpLoad bootstraps the load mechanism. 429 | function setUpLoad() { 430 | function importStuff() { 431 | var x = document.getElementById('importContent').value; 432 | try { 433 | var res = JSON.parse(x) 434 | localStorage.setItem(ALIASES_KEY, x); 435 | loadEl.className = currentClass; 436 | displayContent("loaded") 437 | listAll() 438 | } catch (err) { 439 | alert("loading: " + err) 440 | } 441 | } 442 | 443 | var loadEl = document.getElementById('load') 444 | var currentClass = loadEl.className 445 | document.getElementById('loadOpen').onclick = () => { 446 | loadEl.className += " is-active"; 447 | } 448 | // add handler for cancel button 449 | document.getElementById('submitLoadBtn').onclick = importStuff 450 | // add handler for cancel button 451 | document.getElementById('cancelLoadBtn').onclick = () => { 452 | loadEl.className = currentClass; 453 | } 454 | // add handler for top right cross 455 | loadEl.lastElementChild.onclick = () => { 456 | loadEl.className = currentClass; 457 | } 458 | } 459 | 460 | // displayEntries takes a result and returns a html string for representing the result in a table 461 | function displayEntries(result, opts) { 462 | var opts = opts || {}; 463 | if (opts.withSort) { 464 | 465 | result.sort(function(a, b) { 466 | if (a.cmd < b.cmd) { 467 | return -1; 468 | } else if (a.cmd > b.cmd) { 469 | return 1; 470 | } else { 471 | return 0; 472 | } 473 | }); 474 | } 475 | 476 | var res = "" 477 | res += "

Available commands

"; 478 | res += ''; 479 | 480 | for (var i = 0; i < result.length; i++) { 481 | var styleDesc = result[i].style ? 'style="' + result[i].style + '"' : ""; 482 | res += ""; 483 | var cmdObject = result[i].cmdObject; 484 | if (cmdObject.target) { 485 | res += ""; 486 | } else { 487 | res += ""; 488 | } 489 | res += "\n"; 490 | } 491 | 492 | res += "
" + result[i].cmd + " " + cmdObject.target + "" + (cmdObject.desc || "") + (cmdObject.example ? "
" + cmdObject.example : "") + "

"; 493 | res += "General usage is: cmd [query]"; 494 | return res 495 | } 496 | 497 | 498 | function doQuery(text) { 499 | var query = text; 500 | if (query === "") { 501 | var el = document.getElementById("query-text"); 502 | query = el.value; 503 | el.value = ""; 504 | } 505 | window.location.href='index.html#' + query; // Will not trigger refresh 506 | executeCmd(); 507 | } 508 | 509 | function executeCmd() { 510 | displayContent(""); // clear content 511 | var searchQuery = splitArgs(window.location).q; 512 | if (searchQuery) { 513 | document.title = searchQuery; 514 | var r = applyLoader(searchQuery); 515 | if (r) { 516 | if (r.url) { 517 | navigate(r.url); 518 | } else if (r.text) { 519 | displayContent(r.text); 520 | } 521 | } 522 | listAll() 523 | } else { 524 | listAll() 525 | } 526 | } 527 | 528 | function makeList(obj) { 529 | var x = []; 530 | for (var key in obj) { 531 | var temp = obj[key]; // maybe clone 532 | temp.name = key; 533 | x.push(temp); 534 | } 535 | for (var i in baseCommands) { 536 | var temp = baseCommands[i]; // maybe clone 537 | temp.name = i; 538 | x.push(temp); 539 | 540 | } 541 | for (var i in coreCommands) { 542 | var temp = coreCommands[i]; // maybe clone 543 | temp.name = i; 544 | x.push(temp); 545 | } 546 | 547 | return x; 548 | } 549 | 550 | function doSearch(text) { 551 | // TODO: cache this so we don't always update 552 | var list = makeList(getAliases()); 553 | var res = []; 554 | list.forEach(x => { 555 | res.push({"name":x["name"], "usage": x["usage"]||undefined}) 556 | }) 557 | return res; 558 | } 559 | 560 | function setUpAutoComplete() { 561 | var pv = completely(document.getElementById('container-search')); 562 | pv.options = []; 563 | pv.repaint(); 564 | 565 | pv.onChange = function (text) { 566 | if (text.length == 0) { 567 | pv.options = []; 568 | pv.repaint(); 569 | return; 570 | } 571 | var oj = doSearch(text); 572 | pv.options =[]; 573 | for (var i in oj) { pv.options.push(oj[i].usage || oj[i].name); } 574 | pv.repaint(); 575 | pv.input.focus(); 576 | }; 577 | 578 | // Hacks to fix stying of the generated elements 579 | pv.input.className="input" 580 | pv.input.placeholder="Command. Try 'help'" 581 | pv.hint.className="input" 582 | pv.prompt.className="input" 583 | pv.wrapper.className="control has-addons" 584 | 585 | // Trigger search when user enters 586 | pv.onEnter = function(){ 587 | doQuery(pv.input.value); 588 | pv.setText(''); 589 | } 590 | 591 | setTimeout(function() { 592 | pv.input.focus(); 593 | },0); 594 | } -------------------------------------------------------------------------------- /js/complete.ly.1.0.1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * complete.ly 1.0.0 3 | * MIT Licensing 4 | * Copyright (c) 2013 Lorenzo Puccetti 5 | * 6 | * This Software shall be used for doing good things, not bad things. 7 | * 8 | * Modified 07-08-2016 By Daniel Low 9 | * - Remove some styling overwrites 10 | * - Tab completion stops at spaces 11 | **/ 12 | function completely(container, config) { 13 | config = config || {}; 14 | config.fontSize = config.fontSize || '16px'; 15 | config.fontFamily = config.fontFamily || 'sans-serif'; 16 | config.promptInnerHTML = config.promptInnerHTML || ''; 17 | config.color = config.color || '#333'; 18 | config.hintColor = config.hintColor || '#aaa'; 19 | config.backgroundColor = config.backgroundColor || '#fff'; 20 | config.dropDownBorderColor = config.dropDownBorderColor || '#aaa'; 21 | config.dropDownZIndex = config.dropDownZIndex || '100'; // to ensure we are in front of everybody 22 | config.dropDownOnHoverBackgroundColor = config.dropDownOnHoverBackgroundColor || '#ddd'; 23 | 24 | var txtInput = document.createElement('input'); 25 | txtInput.type ='text'; 26 | txtInput.spellcheck = false; 27 | // txtInput.style.fontSize = config.fontSize; 28 | // txtInput.style.fontFamily = config.fontFamily; 29 | // txtInput.style.color = config.color; 30 | // txtInput.style.backgroundColor = config.backgroundColor; 31 | txtInput.style.width = '100%'; 32 | txtInput.placeHolder = "what"; 33 | // txtInput.style.outline = '0'; 34 | // txtInput.style.border = '0'; 35 | // txtInput.style.margin = '0'; 36 | // txtInput.style.padding = '0'; 37 | 38 | var txtHint = txtInput.cloneNode(); 39 | txtHint.disabled=''; 40 | txtHint.style.position = 'absolute'; 41 | txtHint.style.top = '0'; 42 | txtHint.style.left = '0'; 43 | txtHint.style.borderColor = 'transparent'; 44 | txtHint.style.boxShadow = 'none'; 45 | txtHint.style.color = config.hintColor; 46 | 47 | txtInput.style.backgroundColor ='transparent'; 48 | txtInput.style.verticalAlign = 'top'; 49 | txtInput.style.position = 'relative'; 50 | 51 | var wrapper = document.createElement('div'); 52 | wrapper.style.position = 'relative'; 53 | // wrapper.style.outline = '0'; 54 | // wrapper.style.border = '0'; 55 | // wrapper.style.margin = '0'; 56 | // wrapper.style.padding = '0'; 57 | 58 | var prompt = document.createElement('div'); 59 | prompt.style.position = 'absolute'; 60 | // prompt.style.outline = '0'; 61 | // prompt.style.margin = '0'; 62 | // prompt.style.padding = '0'; 63 | // prompt.style.border = '0'; 64 | // prompt.style.fontSize = config.fontSize; 65 | // prompt.style.fontFamily = config.fontFamily; 66 | // prompt.style.color = config.color; 67 | // prompt.style.backgroundColor = config.backgroundColor; 68 | // prompt.style.top = '0'; 69 | // prompt.style.left = '0'; 70 | prompt.style.overflow = 'hidden'; 71 | prompt.innerHTML = config.promptInnerHTML; 72 | prompt.style.background = 'transparent'; 73 | if (document.body === undefined) { 74 | throw 'document.body is undefined. The library was wired up incorrectly.'; 75 | } 76 | document.body.appendChild(prompt); 77 | var w = 0; 78 | // var w = prompt.getBoundingClientRect().right; // works out the width of the prompt. 79 | wrapper.appendChild(prompt); 80 | prompt.style.visibility = 'visible'; 81 | prompt.style.left = '-'+w+'px'; 82 | wrapper.style.marginLeft= w+'px'; 83 | 84 | wrapper.appendChild(txtHint); 85 | wrapper.appendChild(txtInput); 86 | 87 | var dropDown = document.createElement('div'); 88 | dropDown.style.position = 'absolute'; 89 | dropDown.style.visibility = 'hidden'; 90 | dropDown.style.outline = '0'; 91 | dropDown.style.margin = '0'; 92 | dropDown.style.padding = '0'; 93 | dropDown.style.textAlign = 'left'; 94 | dropDown.style.fontSize = config.fontSize; 95 | dropDown.style.fontFamily = config.fontFamily; 96 | dropDown.style.backgroundColor = config.backgroundColor; 97 | dropDown.style.zIndex = config.dropDownZIndex; 98 | dropDown.style.cursor = 'default'; 99 | dropDown.style.borderStyle = 'solid'; 100 | dropDown.style.borderWidth = '1px'; 101 | dropDown.style.borderColor = config.dropDownBorderColor; 102 | dropDown.style.overflowX= 'hidden'; 103 | dropDown.style.whiteSpace = 'pre'; 104 | dropDown.style.overflowY = 'scroll'; // note: this might be ugly when the scrollbar is not required. however in this way the width of the dropDown takes into account 105 | 106 | 107 | var createDropDownController = function(elem) { 108 | var rows = []; 109 | var ix = 0; 110 | var oldIndex = -1; 111 | 112 | var onMouseOver = function() { this.style.outline = '1px solid #ddd'; } 113 | var onMouseOut = function() { this.style.outline = '0'; } 114 | var onMouseDown = function() { p.hide(); p.onmouseselection(this.__hint); } 115 | 116 | var p = { 117 | hide : function() { elem.style.visibility = 'hidden'; }, 118 | refresh : function(token, array) { 119 | elem.style.visibility = 'hidden'; 120 | ix = 0; 121 | elem.innerHTML =''; 122 | var vph = (window.innerHeight || document.documentElement.clientHeight); 123 | var rect = elem.parentNode.getBoundingClientRect(); 124 | var distanceToTop = rect.top - 6; // heuristic give 6px 125 | var distanceToBottom = vph - rect.bottom -6; // distance from the browser border. 126 | 127 | rows = []; 128 | for (var i=0;i'+array[i].substring(token.length)+''; 137 | rows.push(divRow); 138 | elem.appendChild(divRow); 139 | } 140 | if (rows.length===0) { 141 | return; // nothing to show. 142 | } 143 | if (rows.length===1 && token === rows[0].__hint) { 144 | return; // do not show the dropDown if it has only one element which matches what we have just displayed. 145 | } 146 | 147 | if (rows.length<2) return; 148 | p.highlight(0); 149 | 150 | if (distanceToTop > distanceToBottom*3) { // Heuristic (only when the distance to the to top is 4 times more than distance to the bottom 151 | elem.style.maxHeight = distanceToTop+'px'; // we display the dropDown on the top of the input text 152 | elem.style.top =''; 153 | elem.style.bottom ='100%'; 154 | } else { 155 | elem.style.top = '100%'; 156 | elem.style.bottom = ''; 157 | elem.style.maxHeight = distanceToBottom+'px'; 158 | } 159 | elem.style.visibility = 'visible'; 160 | }, 161 | highlight : function(index) { 162 | if (oldIndex !=-1 && rows[oldIndex]) { 163 | rows[oldIndex].style.backgroundColor = config.backgroundColor; 164 | } 165 | rows[index].style.backgroundColor = config.dropDownOnHoverBackgroundColor; // <-- should be config 166 | oldIndex = index; 167 | }, 168 | move : function(step) { // moves the selection either up or down (unless it's not possible) step is either +1 or -1. 169 | if (elem.style.visibility === 'hidden') return ''; // nothing to move if there is no dropDown. (this happens if the user hits escape and then down or up) 170 | if (ix+step === -1 || ix+step === rows.length) return rows[ix].__hint; // NO CIRCULAR SCROLLING. 171 | ix+=step; 172 | p.highlight(ix); 173 | return rows[ix].__hint;//txtShadow.value = uRows[uIndex].__hint ; 174 | }, 175 | onmouseselection : function() {} // it will be overwritten. 176 | }; 177 | return p; 178 | } 179 | 180 | var dropDownController = createDropDownController(dropDown); 181 | 182 | dropDownController.onmouseselection = function(text) { 183 | txtInput.value = txtHint.value = leftSide+text; 184 | rs.onChange(txtInput.value); // <-- forcing it. 185 | registerOnTextChangeOldValue = txtInput.value; // <-- ensure that mouse down will not show the dropDown now. 186 | setTimeout(function() { txtInput.focus(); },0); // <-- I need to do this for IE 187 | } 188 | 189 | wrapper.appendChild(dropDown); 190 | container.appendChild(wrapper); 191 | 192 | var spacer; 193 | var leftSide; // <-- it will contain the leftSide part of the textfield (the bit that was already autocompleted) 194 | 195 | 196 | function calculateWidthForText(text) { 197 | if (spacer === undefined) { // on first call only. 198 | spacer = document.createElement('span'); 199 | spacer.style.visibility = 'hidden'; 200 | spacer.style.position = 'fixed'; 201 | spacer.style.outline = '0'; 202 | spacer.style.margin = '0'; 203 | spacer.style.padding = '0'; 204 | spacer.style.border = '0'; 205 | spacer.style.left = '0'; 206 | spacer.style.whiteSpace = 'pre'; 207 | spacer.style.fontSize = config.fontSize; 208 | spacer.style.fontFamily = config.fontFamily; 209 | spacer.style.fontWeight = 'normal'; 210 | document.body.appendChild(spacer); 211 | } 212 | 213 | // Used to encode an HTML string into a plain text. 214 | // taken from http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding 215 | spacer.innerHTML = String(text).replace(/&/g, '&') 216 | .replace(/"/g, '"') 217 | .replace(/'/g, ''') 218 | .replace(//g, '>'); 220 | return spacer.getBoundingClientRect().right; 221 | } 222 | 223 | 224 | var rs = { 225 | onArrowDown : function() {}, // defaults to no action. 226 | onArrowUp : function() {}, // defaults to no action. 227 | onEnter : function() {}, // defaults to no action. 228 | onTab : function() {}, // defaults to no action. 229 | onChange: function() { rs.repaint() }, // defaults to repainting. 230 | startFrom: 0, 231 | options: [], 232 | wrapper : wrapper, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) 233 | input : txtInput, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) 234 | hint : txtHint, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) 235 | dropDown : dropDown, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) 236 | prompt : prompt, 237 | setText : function(text) { 238 | txtHint.value = text; 239 | txtInput.value = text; 240 | }, 241 | getText : function() { 242 | return txtInput.value; 243 | }, 244 | hideDropDown : function() { 245 | dropDownController.hide(); 246 | }, 247 | repaint : function() { 248 | var text = txtInput.value; 249 | var startFrom = rs.startFrom; 250 | var options = rs.options; 251 | var optionsLength = options.length; 252 | 253 | // breaking text in leftSide and token. 254 | var token = text.substring(startFrom); 255 | leftSide = text.substring(0,startFrom); 256 | 257 | // updating the hint. 258 | txtHint.value =''; 259 | for (var i=0;i 0) { // if there is a hint 339 | dropDownController.hide(); 340 | // Break at the next space 341 | var remaining = txtHint.value.substr(txtInput.value.length) 342 | var ss = remaining.split(" "); 343 | if (ss.length == 1) { 344 | txtInput.value = txtHint.value; 345 | } else { 346 | txtInput.value += ss[0] + " "; 347 | } 348 | var hasTextChanged = registerOnTextChangeOldValue != txtInput.value 349 | registerOnTextChangeOldValue = txtInput.value; // <-- to avoid dropDown to appear again. 350 | // for example imagine the array contains the following words: bee, beef, beetroot 351 | // user has hit enter to get 'bee' it would be prompted with the dropDown again (as beef and beetroot also match) 352 | if (hasTextChanged) { 353 | rs.onChange(txtInput.value); // <-- forcing it. 354 | } 355 | } 356 | return; 357 | } 358 | 359 | if (keyCode == 13) { // enter (autocomplete triggered) 360 | if (txtHint.value.length == 0) { // if there is a hint 361 | rs.onEnter(); 362 | } else { 363 | var wasDropDownHidden = (dropDown.style.visibility == 'hidden'); 364 | dropDownController.hide(); 365 | 366 | if (wasDropDownHidden) { 367 | txtHint.value = txtInput.value; // ensure that no hint is left. 368 | txtInput.focus(); 369 | rs.onEnter(); 370 | return; 371 | } 372 | 373 | txtInput.value = txtHint.value; 374 | var hasTextChanged = registerOnTextChangeOldValue != txtInput.value 375 | registerOnTextChangeOldValue = txtInput.value; // <-- to avoid dropDown to appear again. 376 | // for example imagine the array contains the following words: bee, beef, beetroot 377 | // user has hit enter to get 'bee' it would be prompted with the dropDown again (as beef and beetroot also match) 378 | if (hasTextChanged) { 379 | rs.onChange(txtInput.value); // <-- forcing it. 380 | } 381 | 382 | } 383 | return; 384 | } 385 | 386 | if (keyCode == 40) { // down 387 | var m = dropDownController.move(+1); 388 | if (m == '') { rs.onArrowDown(); } 389 | txtHint.value = leftSide+m; 390 | return; 391 | } 392 | 393 | if (keyCode == 38 ) { // up 394 | var m = dropDownController.move(-1); 395 | if (m == '') { rs.onArrowUp(); } 396 | txtHint.value = leftSide+m; 397 | e.preventDefault(); 398 | e.stopPropagation(); 399 | return; 400 | } 401 | 402 | // it's important to reset the txtHint on key down. 403 | // think: user presses a letter (e.g. 'x') and never releases... you get (xxxxxxxxxxxxxxxxx) 404 | // and you would see still the hint 405 | txtHint.value =''; // resets the txtHint. (it might be updated onKeyUp) 406 | 407 | }; 408 | 409 | if (txtInput.addEventListener) { 410 | txtInput.addEventListener("keydown", keyDownHandler, false); 411 | } else { // is this a fair assumption: that attachEvent will exist ? 412 | txtInput.attachEvent('onkeydown', keyDownHandler); // IE<9 413 | } 414 | return rs; 415 | } -------------------------------------------------------------------------------- /extension/js/complete.ly.1.0.1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * complete.ly 1.0.0 3 | * MIT Licensing 4 | * Copyright (c) 2013 Lorenzo Puccetti 5 | * 6 | * This Software shall be used for doing good things, not bad things. 7 | * 8 | * Modified 07-08-2016 By Daniel Low 9 | * - Remove some styling overwrites 10 | * - Tab completion stops at spaces 11 | **/ 12 | function completely(container, config) { 13 | config = config || {}; 14 | config.fontSize = config.fontSize || '16px'; 15 | config.fontFamily = config.fontFamily || 'sans-serif'; 16 | config.promptInnerHTML = config.promptInnerHTML || ''; 17 | config.color = config.color || '#333'; 18 | config.hintColor = config.hintColor || '#aaa'; 19 | config.backgroundColor = config.backgroundColor || '#fff'; 20 | config.dropDownBorderColor = config.dropDownBorderColor || '#aaa'; 21 | config.dropDownZIndex = config.dropDownZIndex || '100'; // to ensure we are in front of everybody 22 | config.dropDownOnHoverBackgroundColor = config.dropDownOnHoverBackgroundColor || '#ddd'; 23 | 24 | var txtInput = document.createElement('input'); 25 | txtInput.type ='text'; 26 | txtInput.spellcheck = false; 27 | // txtInput.style.fontSize = config.fontSize; 28 | // txtInput.style.fontFamily = config.fontFamily; 29 | // txtInput.style.color = config.color; 30 | // txtInput.style.backgroundColor = config.backgroundColor; 31 | txtInput.style.width = '100%'; 32 | txtInput.placeHolder = "what"; 33 | // txtInput.style.outline = '0'; 34 | // txtInput.style.border = '0'; 35 | // txtInput.style.margin = '0'; 36 | // txtInput.style.padding = '0'; 37 | 38 | var txtHint = txtInput.cloneNode(); 39 | txtHint.disabled=''; 40 | txtHint.style.position = 'absolute'; 41 | txtHint.style.top = '0'; 42 | txtHint.style.left = '0'; 43 | txtHint.style.borderColor = 'transparent'; 44 | txtHint.style.boxShadow = 'none'; 45 | txtHint.style.color = config.hintColor; 46 | 47 | txtInput.style.backgroundColor ='transparent'; 48 | txtInput.style.verticalAlign = 'top'; 49 | txtInput.style.position = 'relative'; 50 | 51 | var wrapper = document.createElement('div'); 52 | wrapper.style.position = 'relative'; 53 | // wrapper.style.outline = '0'; 54 | // wrapper.style.border = '0'; 55 | // wrapper.style.margin = '0'; 56 | // wrapper.style.padding = '0'; 57 | 58 | var prompt = document.createElement('div'); 59 | prompt.style.position = 'absolute'; 60 | // prompt.style.outline = '0'; 61 | // prompt.style.margin = '0'; 62 | // prompt.style.padding = '0'; 63 | // prompt.style.border = '0'; 64 | // prompt.style.fontSize = config.fontSize; 65 | // prompt.style.fontFamily = config.fontFamily; 66 | // prompt.style.color = config.color; 67 | // prompt.style.backgroundColor = config.backgroundColor; 68 | // prompt.style.top = '0'; 69 | // prompt.style.left = '0'; 70 | prompt.style.overflow = 'hidden'; 71 | prompt.innerHTML = config.promptInnerHTML; 72 | prompt.style.background = 'transparent'; 73 | if (document.body === undefined) { 74 | throw 'document.body is undefined. The library was wired up incorrectly.'; 75 | } 76 | document.body.appendChild(prompt); 77 | var w = 0; 78 | // var w = prompt.getBoundingClientRect().right; // works out the width of the prompt. 79 | wrapper.appendChild(prompt); 80 | prompt.style.visibility = 'visible'; 81 | prompt.style.left = '-'+w+'px'; 82 | wrapper.style.marginLeft= w+'px'; 83 | 84 | wrapper.appendChild(txtHint); 85 | wrapper.appendChild(txtInput); 86 | 87 | var dropDown = document.createElement('div'); 88 | dropDown.style.position = 'absolute'; 89 | dropDown.style.visibility = 'hidden'; 90 | dropDown.style.outline = '0'; 91 | dropDown.style.margin = '0'; 92 | dropDown.style.padding = '0'; 93 | dropDown.style.textAlign = 'left'; 94 | dropDown.style.fontSize = config.fontSize; 95 | dropDown.style.fontFamily = config.fontFamily; 96 | dropDown.style.backgroundColor = config.backgroundColor; 97 | dropDown.style.zIndex = config.dropDownZIndex; 98 | dropDown.style.cursor = 'default'; 99 | dropDown.style.borderStyle = 'solid'; 100 | dropDown.style.borderWidth = '1px'; 101 | dropDown.style.borderColor = config.dropDownBorderColor; 102 | dropDown.style.overflowX= 'hidden'; 103 | dropDown.style.whiteSpace = 'pre'; 104 | dropDown.style.overflowY = 'scroll'; // note: this might be ugly when the scrollbar is not required. however in this way the width of the dropDown takes into account 105 | 106 | 107 | var createDropDownController = function(elem) { 108 | var rows = []; 109 | var ix = 0; 110 | var oldIndex = -1; 111 | 112 | var onMouseOver = function() { this.style.outline = '1px solid #ddd'; } 113 | var onMouseOut = function() { this.style.outline = '0'; } 114 | var onMouseDown = function() { p.hide(); p.onmouseselection(this.__hint); } 115 | 116 | var p = { 117 | hide : function() { elem.style.visibility = 'hidden'; }, 118 | refresh : function(token, array) { 119 | elem.style.visibility = 'hidden'; 120 | ix = 0; 121 | elem.innerHTML =''; 122 | var vph = (window.innerHeight || document.documentElement.clientHeight); 123 | var rect = elem.parentNode.getBoundingClientRect(); 124 | var distanceToTop = rect.top - 6; // heuristic give 6px 125 | var distanceToBottom = vph - rect.bottom -6; // distance from the browser border. 126 | 127 | rows = []; 128 | for (var i=0;i'+array[i].substring(token.length)+''; 137 | rows.push(divRow); 138 | elem.appendChild(divRow); 139 | } 140 | if (rows.length===0) { 141 | return; // nothing to show. 142 | } 143 | if (rows.length===1 && token === rows[0].__hint) { 144 | return; // do not show the dropDown if it has only one element which matches what we have just displayed. 145 | } 146 | 147 | if (rows.length<2) return; 148 | p.highlight(0); 149 | 150 | if (distanceToTop > distanceToBottom*3) { // Heuristic (only when the distance to the to top is 4 times more than distance to the bottom 151 | elem.style.maxHeight = distanceToTop+'px'; // we display the dropDown on the top of the input text 152 | elem.style.top =''; 153 | elem.style.bottom ='100%'; 154 | } else { 155 | elem.style.top = '100%'; 156 | elem.style.bottom = ''; 157 | elem.style.maxHeight = distanceToBottom+'px'; 158 | } 159 | elem.style.visibility = 'visible'; 160 | }, 161 | highlight : function(index) { 162 | if (oldIndex !=-1 && rows[oldIndex]) { 163 | rows[oldIndex].style.backgroundColor = config.backgroundColor; 164 | } 165 | rows[index].style.backgroundColor = config.dropDownOnHoverBackgroundColor; // <-- should be config 166 | oldIndex = index; 167 | }, 168 | move : function(step) { // moves the selection either up or down (unless it's not possible) step is either +1 or -1. 169 | if (elem.style.visibility === 'hidden') return ''; // nothing to move if there is no dropDown. (this happens if the user hits escape and then down or up) 170 | if (ix+step === -1 || ix+step === rows.length) return rows[ix].__hint; // NO CIRCULAR SCROLLING. 171 | ix+=step; 172 | p.highlight(ix); 173 | return rows[ix].__hint;//txtShadow.value = uRows[uIndex].__hint ; 174 | }, 175 | onmouseselection : function() {} // it will be overwritten. 176 | }; 177 | return p; 178 | } 179 | 180 | var dropDownController = createDropDownController(dropDown); 181 | 182 | dropDownController.onmouseselection = function(text) { 183 | txtInput.value = txtHint.value = leftSide+text; 184 | rs.onChange(txtInput.value); // <-- forcing it. 185 | registerOnTextChangeOldValue = txtInput.value; // <-- ensure that mouse down will not show the dropDown now. 186 | setTimeout(function() { txtInput.focus(); },0); // <-- I need to do this for IE 187 | } 188 | 189 | wrapper.appendChild(dropDown); 190 | container.appendChild(wrapper); 191 | 192 | var spacer; 193 | var leftSide; // <-- it will contain the leftSide part of the textfield (the bit that was already autocompleted) 194 | 195 | 196 | function calculateWidthForText(text) { 197 | if (spacer === undefined) { // on first call only. 198 | spacer = document.createElement('span'); 199 | spacer.style.visibility = 'hidden'; 200 | spacer.style.position = 'fixed'; 201 | spacer.style.outline = '0'; 202 | spacer.style.margin = '0'; 203 | spacer.style.padding = '0'; 204 | spacer.style.border = '0'; 205 | spacer.style.left = '0'; 206 | spacer.style.whiteSpace = 'pre'; 207 | spacer.style.fontSize = config.fontSize; 208 | spacer.style.fontFamily = config.fontFamily; 209 | spacer.style.fontWeight = 'normal'; 210 | document.body.appendChild(spacer); 211 | } 212 | 213 | // Used to encode an HTML string into a plain text. 214 | // taken from http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding 215 | spacer.innerHTML = String(text).replace(/&/g, '&') 216 | .replace(/"/g, '"') 217 | .replace(/'/g, ''') 218 | .replace(//g, '>'); 220 | return spacer.getBoundingClientRect().right; 221 | } 222 | 223 | 224 | var rs = { 225 | onArrowDown : function() {}, // defaults to no action. 226 | onArrowUp : function() {}, // defaults to no action. 227 | onEnter : function() {}, // defaults to no action. 228 | onTab : function() {}, // defaults to no action. 229 | onChange: function() { rs.repaint() }, // defaults to repainting. 230 | startFrom: 0, 231 | options: [], 232 | wrapper : wrapper, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) 233 | input : txtInput, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) 234 | hint : txtHint, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) 235 | dropDown : dropDown, // Only to allow easy access to the HTML elements to the final user (possibly for minor customizations) 236 | prompt : prompt, 237 | setText : function(text) { 238 | txtHint.value = text; 239 | txtInput.value = text; 240 | }, 241 | getText : function() { 242 | return txtInput.value; 243 | }, 244 | hideDropDown : function() { 245 | dropDownController.hide(); 246 | }, 247 | repaint : function() { 248 | var text = txtInput.value; 249 | var startFrom = rs.startFrom; 250 | var options = rs.options; 251 | var optionsLength = options.length; 252 | 253 | // breaking text in leftSide and token. 254 | var token = text.substring(startFrom); 255 | leftSide = text.substring(0,startFrom); 256 | 257 | // updating the hint. 258 | txtHint.value =''; 259 | for (var i=0;i 0) { // if there is a hint 339 | dropDownController.hide(); 340 | // Break at the next space 341 | var remaining = txtHint.value.substr(txtInput.value.length) 342 | var ss = remaining.split(" "); 343 | if (ss.length == 1) { 344 | txtInput.value = txtHint.value; 345 | } else { 346 | txtInput.value += ss[0] + " "; 347 | } 348 | var hasTextChanged = registerOnTextChangeOldValue != txtInput.value 349 | registerOnTextChangeOldValue = txtInput.value; // <-- to avoid dropDown to appear again. 350 | // for example imagine the array contains the following words: bee, beef, beetroot 351 | // user has hit enter to get 'bee' it would be prompted with the dropDown again (as beef and beetroot also match) 352 | if (hasTextChanged) { 353 | rs.onChange(txtInput.value); // <-- forcing it. 354 | } 355 | } 356 | return; 357 | } 358 | 359 | if (keyCode == 13) { // enter (autocomplete triggered) 360 | if (txtHint.value.length == 0) { // if there is a hint 361 | rs.onEnter(); 362 | } else { 363 | var wasDropDownHidden = (dropDown.style.visibility == 'hidden'); 364 | dropDownController.hide(); 365 | 366 | if (wasDropDownHidden) { 367 | txtHint.value = txtInput.value; // ensure that no hint is left. 368 | txtInput.focus(); 369 | rs.onEnter(); 370 | return; 371 | } 372 | 373 | txtInput.value = txtHint.value; 374 | var hasTextChanged = registerOnTextChangeOldValue != txtInput.value 375 | registerOnTextChangeOldValue = txtInput.value; // <-- to avoid dropDown to appear again. 376 | // for example imagine the array contains the following words: bee, beef, beetroot 377 | // user has hit enter to get 'bee' it would be prompted with the dropDown again (as beef and beetroot also match) 378 | if (hasTextChanged) { 379 | rs.onChange(txtInput.value); // <-- forcing it. 380 | } 381 | 382 | } 383 | return; 384 | } 385 | 386 | if (keyCode == 40) { // down 387 | var m = dropDownController.move(+1); 388 | if (m == '') { rs.onArrowDown(); } 389 | txtHint.value = leftSide+m; 390 | return; 391 | } 392 | 393 | if (keyCode == 38 ) { // up 394 | var m = dropDownController.move(-1); 395 | if (m == '') { rs.onArrowUp(); } 396 | txtHint.value = leftSide+m; 397 | e.preventDefault(); 398 | e.stopPropagation(); 399 | return; 400 | } 401 | 402 | // it's important to reset the txtHint on key down. 403 | // think: user presses a letter (e.g. 'x') and never releases... you get (xxxxxxxxxxxxxxxxx) 404 | // and you would see still the hint 405 | txtHint.value =''; // resets the txtHint. (it might be updated onKeyUp) 406 | 407 | }; 408 | 409 | if (txtInput.addEventListener) { 410 | txtInput.addEventListener("keydown", keyDownHandler, false); 411 | } else { // is this a fair assumption: that attachEvent will exist ? 412 | txtInput.attachEvent('onkeydown', keyDownHandler); // IE<9 413 | } 414 | return rs; 415 | } -------------------------------------------------------------------------------- /js/system.js: -------------------------------------------------------------------------------- 1 | /* 2 | * SystemJS v0.19.28 3 | */ 4 | !function(){function e(){!function(e){function t(e,r){if("string"!=typeof e)throw new TypeError("URL must be a string");var n=String(e).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);if(!n)throw new RangeError("Invalid URL format");var a=n[1]||"",o=n[2]||"",i=n[3]||"",s=n[4]||"",l=n[5]||"",u=n[6]||"",d=n[7]||"",c=n[8]||"",f=n[9]||"";if(void 0!==r){var m=r instanceof t?r:new t(r),p=!a&&!s&&!o;!p||d||c||(c=m.search),p&&"/"!==d[0]&&(d=d?(!m.host&&!m.username||m.pathname?"":"/")+m.pathname.slice(0,m.pathname.lastIndexOf("/")+1)+d:m.pathname);var h=[];d.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(e){"/.."===e?h.pop():h.push(e)}),d=h.join("").replace(/^\//,"/"===d[0]?"/":""),p&&(u=m.port,l=m.hostname,s=m.host,i=m.password,o=m.username),a||(a=m.protocol)}"file:"==a&&(d=d.replace(/\\/g,"/")),this.origin=s?a+(""!==a||""!==s?"//":"")+s:"",this.href=a+(a&&s||"file:"==a?"//":"")+(""!==o?o+(""!==i?":"+i:"")+"@":"")+s+d+c+f,this.protocol=a,this.username=o,this.password=i,this.host=s,this.hostname=l,this.port=u,this.pathname=d,this.search=c,this.hash=f}e.URLPolyfill=t}("undefined"!=typeof self?self:global),function(e){function t(e,t){if(!e.originalErr)for(var r=(e.stack||e.message||e).split("\n"),n=[],a=0;a2)throw new TypeError("Only one wildcard in a path is permitted");if(1==i.length){if(t==o)return e[o];if(t.substr(0,o.length-1)==o.substr(0,o.length-1)&&(t.lengtho.length?(e[o]&&"/"||"")+t.substr(o.length):"")}else{var s=i[0].length;s>=a&&t.substr(0,i[0].length)==i[0]&&t.substr(t.length-i[1].length)==i[1]&&(a=s,n=o,r=t.substr(i[0].length,t.length-i[1].length-i[0].length))}}var l=e[n];return"string"==typeof r&&(l=l.replace("*",r)),l}function s(){}function l(){o.call(this),W.call(this)}function u(){}function d(e,t){l.prototype[e]=t(l.prototype[e]||function(){})}function c(e){W=e(W||function(){})}function f(e){for(var t=[],r=[],n=0,a=e.length;a>n;n++){var o=D.call(t,e[n]);-1===o?(t.push(e[n]),r.push([n])):r[o].push(n)}return{names:t,indices:r}}function m(t){var r={};if(("object"==typeof t||"function"==typeof t)&&t!==e)if(V)for(var n in t)"default"!==n&&p(r,t,n);else h(r,t);return r["default"]=t,F(r,"__useDefault",{value:!0}),r}function p(e,t,r){try{var n;(n=Object.getOwnPropertyDescriptor(t,r))&&F(e,r,n)}catch(a){return e[r]=t[r],!1}}function h(e,t,r){var n=t&&t.hasOwnProperty;for(var a in t)(!n||t.hasOwnProperty(a))&&(r&&a in e||(e[a]=t[a]));return e}function g(e,t,r){var n=t&&t.hasOwnProperty;for(var a in t)if(!n||t.hasOwnProperty(a)){var o=t[a];a in e?o instanceof Array&&e[a]instanceof Array?e[a]=[].concat(r?o:e[a]).concat(r?e[a]:o):"object"==typeof o&&null!==o&&"object"==typeof e[a]?e[a]=h(h({},e[a]),o,r):r||(e[a]=o):e[a]=o}}function v(e){this.warnings&&"undefined"!=typeof console&&console.warn}function b(e,t){for(var r=e.split(".");r.length;)t=t[r.shift()];return t}function y(){if(te[this.baseURL])return te[this.baseURL];"/"!=this.baseURL[this.baseURL.length-1]&&(this.baseURL+="/");var e=new B(this.baseURL,U);return this.baseURL=e.href,te[this.baseURL]=e}function w(e,t){var r,n=0;for(var a in e)if(t.substr(0,a.length)==a&&(t.length==a.length||"/"==t[a.length])){var o=a.split("/").length;if(n>=o)continue;r=a,n=o}return r}function x(e){this.set("@system-env",Q=this.newModule({browser:L,node:!!this._nodeRequire,production:e,dev:!e,"default":!0}))}function S(e){return("."!=e[0]||!!e[1]&&"/"!=e[1]&&"."!=e[1])&&"/"!=e[0]&&!e.match(ee)}function E(e,t){return t&&(t=t.replace(/#/g,"%05")),new B(e,t||re).href.replace(/%05/g,"#")}function _(e,t){return new B(t,y.call(e)).href}function j(e,t){if(!S(e))return E(e,t);var r=w(this.map,e);if(r&&(e=this.map[r]+e.substr(r.length),!S(e)))return E(e);if(this.has(e))return e;if("@node/"==e.substr(0,6)){if(!this._nodeRequire)throw new TypeError("Error loading "+e+". Can only load node core modules in Node.");if(!S(e.substr(6)))throw new Error("Node module "+e.substr(6)+" can't be loaded as it is not a package require.");return this.set(e,this.newModule(m(this._nodeRequire(e.substr(6))))),e}var n=i(this.paths,e);return n&&!S(n)?E(n):_(this,n||e)}function k(e){var t=e.match(oe);return t&&"System.register"==e.substr(t[0].length,15)}function P(){return{name:null,deps:null,originalIndices:null,declare:null,execute:null,executingRequire:!1,declarative:!1,normalizedDeps:null,groupIndex:null,evaluated:!1,module:null,esModule:null,esmExports:!1}}function R(t){if("string"==typeof t)return b(t,e);if(!(t instanceof Array))throw new Error("Global exports must be a string or array.");for(var r={},n=!0,a=0;at;t++)if(this[t]===e)return t;return-1};!function(){try{Object.defineProperty({},"a",{})&&(F=Object.defineProperty)}catch(e){F=function(e,t,r){try{e[t]=r.value||r.get.call(e)}catch(n){}}}}();var U,q="_"==new Error(0,"_").fileName;if("undefined"!=typeof document&&document.getElementsByTagName){if(U=document.baseURI,!U){var J=document.getElementsByTagName("base");U=J[0]&&J[0].href||window.location.href}U=U.split("#")[0].split("?")[0],U=U.substr(0,U.lastIndexOf("/")+1)}else if("undefined"!=typeof process&&process.cwd)U="file://"+(A?"/":"")+process.cwd()+"/",A&&(U=U.replace(/\\/g,"/"));else{if("undefined"==typeof location)throw new TypeError("No environment baseURI");U=e.location.href}try{var N="test:"==new e.URL("test:///").protocol}catch($){}var B=N?e.URL:e.URLPolyfill;F(n.prototype,"toString",{value:function(){return"Module"}}),function(){function o(e){return{status:"loading",name:e,linkSets:[],dependencies:[],metadata:{}}}function i(e,t,r){return new Promise(c({step:r.address?"fetch":"locate",loader:e,moduleName:t,moduleMetadata:r&&r.metadata||{},moduleSource:r.source,moduleAddress:r.address}))}function s(e,t,r,n){return new Promise(function(a,o){a(e.loaderObj.normalize(t,r,n))}).then(function(t){var r;if(e.modules[t])return r=o(t),r.status="linked",r.module=e.modules[t],r;for(var n=0,a=e.loads.length;a>n;n++)if(r=e.loads[n],r.name==t)return r;return r=o(t),e.loads.push(r),l(e,r),r})}function l(e,t){u(e,t,Promise.resolve().then(function(){return e.loaderObj.locate({name:t.name,metadata:t.metadata})}))}function u(e,t,r){d(e,t,r.then(function(r){return"loading"==t.status?(t.address=r,e.loaderObj.fetch({name:t.name,metadata:t.metadata,address:r})):void 0}))}function d(t,n,a){a.then(function(a){return"loading"==n.status?Promise.resolve(t.loaderObj.translate({name:n.name,metadata:n.metadata,address:n.address,source:a})).then(function(e){return n.source=e,t.loaderObj.instantiate({name:n.name,metadata:n.metadata,address:n.address,source:e})}).then(function(a){if(void 0===a)return n.address=n.address||"",n.isDeclarative=!0,E.call(t.loaderObj,n).then(function(t){var a=e.System,o=a.register;a.register=function(e,t,r){"string"!=typeof e&&(r=t,t=e),n.declare=r,n.depsList=t},r(t,n.address,{}),a.register=o});if("object"!=typeof a)throw TypeError("Invalid instantiate return value");n.depsList=a.deps||[],n.execute=a.execute,n.isDeclarative=!1}).then(function(){n.dependencies=[];for(var e=n.depsList,r=[],a=0,o=e.length;o>a;a++)(function(e,a){r.push(s(t,e,n.name,n.address).then(function(t){if(n.dependencies[a]={key:e,value:t.name},"linked"!=t.status)for(var r=n.linkSets.concat([]),o=0,i=r.length;i>o;o++)m(r[o],t)}))})(e[a],a);return Promise.all(r)}).then(function(){n.status="loaded";for(var e=n.linkSets.concat([]),t=0,r=e.length;r>t;t++)h(e[t],n)}):void 0})["catch"](function(e){n.status="failed",n.exception=e;for(var t=n.linkSets.concat([]),r=0,a=t.length;a>r;r++)g(t[r],n,e)})}function c(e){return function(t,r){var n=e.loader,a=e.moduleName,i=e.step;if(n.modules[a])throw new TypeError('"'+a+'" already exists in the module table');for(var s,c=0,m=n.loads.length;m>c;c++)if(n.loads[c].name==a&&(s=n.loads[c],"translate"!=i||s.source||(s.address=e.moduleAddress,d(n,s,Promise.resolve(e.moduleSource))),s.linkSets.length&&s.linkSets[0].loads[0].name==s.name))return s.linkSets[0].done.then(function(){t(s)});var p=s||o(a);p.metadata=e.moduleMetadata;var h=f(n,p);n.loads.push(p),t(h.done),"locate"==i?l(n,p):"fetch"==i?u(n,p,Promise.resolve(e.moduleAddress)):(p.address=e.moduleAddress,d(n,p,Promise.resolve(e.moduleSource)))}}function f(e,t){var r={loader:e,loads:[],startingLoad:t,loadingCount:0};return r.done=new Promise(function(e,t){r.resolve=e,r.reject=t}),m(r,t),r}function m(e,t){if("failed"!=t.status){for(var r=0,n=e.loads.length;n>r;r++)if(e.loads[r]==t)return;e.loads.push(t),t.linkSets.push(e),"loaded"!=t.status&&e.loadingCount++;for(var a=e.loader,r=0,n=t.dependencies.length;n>r;r++)if(t.dependencies[r]){var o=t.dependencies[r].value;if(!a.modules[o])for(var i=0,s=a.loads.length;s>i;i++)if(a.loads[i].name==o){m(e,a.loads[i]);break}}}}function p(e){var t=!1;try{w(e,function(r,n){g(e,r,n),t=!0})}catch(r){g(e,null,r),t=!0}return t}function h(e,t){if(e.loadingCount--,!(e.loadingCount>0)){var r=e.startingLoad;if(e.loader.loaderObj.execute===!1){for(var n=[].concat(e.loads),a=0,o=n.length;o>a;a++){var t=n[a];t.module=t.isDeclarative?{name:t.name,module:j({}),evaluated:!0}:{module:j({})},t.status="linked",v(e.loader,t)}return e.resolve(r)}var i=p(e);i||e.resolve(r)}}function g(e,r,n){var a=e.loader;e:if(r)if(e.loads[0].name==r.name)n=t(n,"Error loading "+r.name);else{for(var o=0;oo;o++){var r=u[o];a.loaderObj.failed=a.loaderObj.failed||[],-1==D.call(a.loaderObj.failed,r)&&a.loaderObj.failed.push(r);var c=D.call(r.linkSets,e);if(r.linkSets.splice(c,1),0==r.linkSets.length){var f=D.call(e.loader.loads,r);-1!=f&&e.loader.loads.splice(f,1)}}e.reject(n)}function v(e,t){if(e.loaderObj.trace){e.loaderObj.loads||(e.loaderObj.loads={});var r={};t.dependencies.forEach(function(e){r[e.key]=e.value}),e.loaderObj.loads[t.name]={name:t.name,deps:t.dependencies.map(function(e){return e.key}),depMap:r,address:t.address,metadata:t.metadata,source:t.source,kind:t.isDeclarative?"declarative":"dynamic"}}t.name&&(e.modules[t.name]=t.module);var n=D.call(e.loads,t);-1!=n&&e.loads.splice(n,1);for(var a=0,o=t.linkSets.length;o>a;a++)n=D.call(t.linkSets[a].loads,t),-1!=n&&t.linkSets[a].loads.splice(n,1);t.linkSets.splice(0,t.linkSets.length)}function b(e,t,r){try{var a=t.execute()}catch(o){return void r(t,o)}return a&&a instanceof n?a:void r(t,new TypeError("Execution must define a Module instance"))}function y(e,t,r){var n=e._loader.importPromises;return n[t]=r.then(function(e){return n[t]=void 0,e},function(e){throw n[t]=void 0,e})}function w(e,t){var r=e.loader;if(e.loads.length)for(var n=e.loads.concat([]),a=0;a "'+n.paths[o]+'" uses wildcards which are being deprecated for simpler trailing "/" folder paths.')}if(e.defaultJSExtensions&&(n.defaultJSExtensions=e.defaultJSExtensions,v.call(n,"The defaultJSExtensions configuration option is deprecated, use packages configuration instead.")),e.pluginFirst&&(n.pluginFirst=e.pluginFirst),e.map){var i="";for(var o in e.map){var s=e.map[o];if("string"!=typeof s){i+=(i.length?", ":"")+'"'+o+'"';var l=n.defaultJSExtensions&&".js"!=o.substr(o.length-3,3),u=n.decanonicalize(o);l&&".js"==u.substr(u.length-3,3)&&(u=u.substr(0,u.length-3));var d="";for(var c in n.packages)u.substr(0,c.length)==c&&(!u[c.length]||"/"==u[c.length])&&d.split("/").lengtha&&(r=o,a=n));return r}function t(e,t,r,n,a){if(!n||"/"==n[n.length-1]||a||t.defaultExtension===!1)return n;var o=!1;if(t.meta&&p(t.meta,n,function(e,t,r){return 0==r||e.lastIndexOf("*")!=e.length-1?o=!0:void 0}),!o&&e.meta&&p(e.meta,r+"/"+n,function(e,t,r){return 0==r||e.lastIndexOf("*")!=e.length-1?o=!0:void 0}),o)return n;var i="."+(t.defaultExtension||"js");return n.substr(n.length-i.length)!=i?n+i:n}function r(e,r,n,o,i){if(!o){if(!r.main)return n+(e.defaultJSExtensions?".js":"");o="./"==r.main.substr(0,2)?r.main.substr(2):r.main}if(r.map){var s="./"+o,l=w(r.map,s);if(l||(s="./"+t(e,r,n,o,i),s!="./"+o&&(l=w(r.map,s))),l)return a(e,r,n,l,s,i)}return n+"/"+t(e,r,n,o,i)}function n(e,t,r){if("."==e)throw new Error("Package "+r+' has a map entry for "." which is not permitted.');if(t.substr(0,e.length)==e&&"/"!=e[e.length-1]&&"/"==t[e.length])throw new Error("Package "+r+' has a recursive map for "'+e+'" which is not permitted.')}function a(e,r,a,o,i,s){var l=r.map[o];if("object"==typeof l)throw new Error("Synchronous conditional normalization not supported sync normalizing "+o+" in "+a);if(n(o,l,a),"string"!=typeof l&&(l=o=i),n(o,l,a),"."==l)l=a;else if("./"==l.substr(0,2))return a+"/"+t(e,r,a,l.substr(2)+i.substr(o.length),s);return e.normalizeSync(l+i.substr(o.length),a+"/")}function o(e,r,n,a,o){if(!a){if(!r.main)return Promise.resolve(n+(e.defaultJSExtensions?".js":""));a="./"==r.main.substr(0,2)?r.main.substr(2):r.main}var i,l;return r.map&&(i="./"+a,l=w(r.map,i),l||(i="./"+t(e,r,n,a,o),i!="./"+a&&(l=w(r.map,i)))),(l?s(e,r,n,l,i,o):Promise.resolve()).then(function(i){return i?Promise.resolve(i):Promise.resolve(n+"/"+t(e,r,n,a,o))})}function i(e,r,n,a,o,i,s){if("."==o)o=n;else if("./"==o.substr(0,2))return Promise.resolve(n+"/"+t(e,r,n,o.substr(2)+i.substr(a.length),s)).then(function(t){return C.call(e,t,n+"/")});return e.normalize(o+i.substr(a.length),n+"/")}function s(e,t,r,a,o,s){var l=t.map[a];if("string"==typeof l)return n(a,l,r),i(e,t,r,a,l,o,s);if(e.builder)return Promise.resolve(r+"/#:"+o);var u=[],d=[];for(var c in l){var f=O(c);d.push({condition:f,map:l[c]}),u.push(e["import"](f.module,r))}return Promise.all(u).then(function(e){for(var t=0;tl&&(l=r),g(s,t,r&&l>r)}),g(r.metadata,s)}o.format&&!r.metadata.loader&&(r.metadata.format=r.metadata.format||o.format)}return t})}})}(),function(){function t(){if(i&&"interactive"===i.script.readyState)return i.load;for(var e=0;ea;a++){var i=e.normalizedDeps[a],s=r.defined[i];if(s&&!s.evaluated){var l=e.groupIndex+(s.declarative!=e.declarative);if(null===s.groupIndex||s.groupIndex=0;s--){for(var l=a[s],d=0;dn;n++){var i=a.importers[n];if(!i.locked){var l=D.call(i.dependencies,a);i.setters[l](s)}}return a.locked=!1,t},{id:t.name});if(a.setters=l.setters,a.execute=l.execute,!a.setters||!a.execute)throw new TypeError("Invalid System.register form for "+t.name);for(var u=0,d=t.normalizedDeps.length;d>u;u++){var c,f=t.normalizedDeps[u],m=r.defined[f],p=n[f];p?c=p.exports:m&&!m.declarative?c=m.esModule:m?(i(m,r),p=m.module,c=p.exports):c=r.get(f),p&&p.importers?(p.importers.push(a),a.dependencies.push(p)):a.dependencies.push(null);for(var h=t.originalIndices[u],g=0,v=h.length;v>g;++g){var b=h[g];a.setters[b]&&a.setters[b](c)}}}}function s(e,t){var r,n=t.defined[e];if(n)n.declarative?p(e,[],t):n.evaluated||u(n,t),r=n.module.exports;else if(r=t.get(e),!r)throw new Error("Unable to load dependency "+e+".");return(!n||n.declarative)&&r&&r.__useDefault?r["default"]:r}function u(t,r){if(!t.module){var a={},o=t.module={exports:a,id:t.name};if(!t.executingRequire)for(var i=0,l=t.normalizedDeps.length;l>i;i++){var d=t.normalizedDeps[i],c=r.defined[d];c&&u(c,r)}t.evaluated=!0;var f=t.execute.call(e,function(e){for(var n=0,a=t.deps.length;a>n;n++)if(t.deps[n]==e)return s(t.normalizedDeps[n],r);var o=r.normalizeSync(e,t.name);if(-1!=D.call(t.normalizedDeps,o))return s(o,r);throw new Error("Module "+e+" not declared as a dependency of "+t.name)},a,o);f&&(o.exports=f),a=o.exports,a&&(a.__esModule||a instanceof n)?t.esModule=a:t.esmExports&&a!==e?t.esModule=m(a):t.esModule={"default":a}}}function p(t,r,n){var a=n.defined[t];if(a&&!a.evaluated&&a.declarative){r.push(t);for(var o=0,i=a.normalizedDeps.length;i>o;o++){var s=a.normalizedDeps[o];-1==D.call(r,s)&&(n.defined[s]?p(s,r,n):n.get(s))}a.evaluated||(a.evaluated=!0,a.module.execute.call(e))}}l.prototype.register=function(e,t,r){if("string"!=typeof e&&(r=t,t=e,e=null),"boolean"==typeof r)return this.registerDynamic.apply(this,arguments);var n=P();n.name=e&&(this.decanonicalize||this.normalize).call(this,e),n.declarative=!0,n.deps=t,n.declare=r,this.pushRegister_({amd:!1,entry:n})},l.prototype.registerDynamic=function(e,t,r,n){"string"!=typeof e&&(n=r,r=t,t=e,e=null);var a=P();a.name=e&&(this.decanonicalize||this.normalize).call(this,e),a.deps=t,a.execute=n,a.executingRequire=r,this.pushRegister_({amd:!1,entry:a})},d("reduceRegister_",function(){return function(e,t){if(t){var r=t.entry,n=e&&e.metadata;if(r.name&&(r.name in this.defined||(this.defined[r.name]=r),n&&(n.bundle=!0)),!r.name||e&&!n.entry&&r.name==e.name){if(!n)throw new TypeError("Invalid System.register call. Anonymous System.register calls can only be made by modules loaded by SystemJS.import and not via script tags.");if(n.entry)throw"register"==n.format?new Error("Multiple anonymous System.register calls in module "+e.name+". If loading a bundle, ensure all the System.register calls are named."):new Error("Module "+e.name+" interpreted as "+n.format+" module format, but called System.register.");n.format||(n.format="register"),n.entry=r}}}}),c(function(e){return function(){e.call(this),this.defined={},this._loader.moduleRecords={}}}),F(a,"toString",{value:function(){return"Module"}}),d("delete",function(e){return function(t){return delete this._loader.moduleRecords[t],delete this.defined[t],e.call(this,t)}}),d("fetch",function(e){return function(t){return this.defined[t.name]?(t.metadata.format="defined",""):(t.metadata.deps=t.metadata.deps||[],e.call(this,t))}}),d("translate",function(e){return function(t){return t.metadata.deps=t.metadata.deps||[],Promise.resolve(e.call(this,t)).then(function(e){return("register"==t.metadata.format||!t.metadata.format&&k(t.source))&&(t.metadata.format="register"),e})}}),d("instantiate",function(e){return function(t){"detect"==t.metadata.format&&(t.metadata.format=void 0),e.call(this,t);var n,a=this;if(a.defined[t.name])n=a.defined[t.name],n.declarative||(n.deps=n.deps.concat(t.metadata.deps)),n.deps=n.deps.concat(t.metadata.deps);else if(t.metadata.entry)n=t.metadata.entry,n.deps=n.deps.concat(t.metadata.deps);else if(!(a.builder&&t.metadata.bundle||"register"!=t.metadata.format&&"esm"!=t.metadata.format&&"es6"!=t.metadata.format)){if("undefined"!=typeof K&&K.call(a,t),!t.metadata.entry&&!t.metadata.bundle)throw new Error(t.name+" detected as "+t.metadata.format+" but didn't execute.");n=t.metadata.entry,n&&t.metadata.deps&&(n.deps=n.deps.concat(t.metadata.deps))}n||(n=P(),n.deps=t.metadata.deps,n.execute=function(){}),a.defined[t.name]=n;var o=f(n.deps);n.deps=o.names,n.originalIndices=o.indices,n.name=t.name,n.esmExports=t.metadata.esmExports!==!1;for(var i=[],s=0,l=n.deps.length;l>s;s++)i.push(Promise.resolve(a.normalize(n.deps[s],t.name)));return Promise.all(i).then(function(e){return n.normalizedDeps=e,{deps:n.deps,execute:function(){return r(t.name,a),p(t.name,[],a),a.defined[t.name]=void 0,a.newModule(n.declarative?n.module.exports:n.esModule)}}})}})}(),function(){var t=/(^\s*|[}\);\n]\s*)(import\s*(['"]|(\*\s+as\s+)?[^"'\(\)\n;]+\s*from\s*['"]|\{)|export\s+\*\s+from\s+["']|export\s*(\{|default|function|class|var|const|let|async\s+function))/,r=/\$traceurRuntime\s*\./,n=/babelHelpers\s*\./;d("translate",function(a){return function(o){var i=this;return a.call(i,o).then(function(a){if("esm"==o.metadata.format||"es6"==o.metadata.format||!o.metadata.format&&a.match(t)){if("es6"==o.metadata.format&&v.call(i,"Module "+o.name+' has metadata setting its format to "es6", which is deprecated.\nThis should be updated to "esm".'),o.metadata.format="esm",o.metadata.deps){for(var s="",l=0;l100&&!o.metadata.format&&(o.metadata.format="global","traceur"===i.transpiler&&(o.metadata.exports="traceur"),"typescript"===i.transpiler&&(o.metadata.exports="ts")),i._loader.loadedTranspiler=!0),i._loader.loadedTranspilerRuntime===!1&&(o.name==i.normalizeSync("traceur-runtime")||o.name==i.normalizeSync("babel/external-helpers*"))&&(a.length>100&&(o.metadata.format=o.metadata.format||"global"),i._loader.loadedTranspilerRuntime=!0),("register"==o.metadata.format||o.metadata.bundle)&&i._loader.loadedTranspilerRuntime!==!0){if(!e.$traceurRuntime&&o.source.match(r))return i._loader.loadedTranspilerRuntime=i._loader.loadedTranspilerRuntime||!1,i["import"]("traceur-runtime").then(function(){return a});if(!e.babelHelpers&&o.source.match(n))return i._loader.loadedTranspilerRuntime=i._loader.loadedTranspilerRuntime||!1,i["import"]("babel/external-helpers").then(function(){return a})}return a})}})}();var ie="undefined"!=typeof self?"self":"global";d("fetch",function(e){return function(t){return t.metadata.exports&&!t.metadata.format&&(t.metadata.format="global"),e.call(this,t)}}),d("instantiate",function(e){return function(t){var r=this;if(t.metadata.format||(t.metadata.format="global"),"global"==t.metadata.format&&!t.metadata.registered){var n=P();t.metadata.entry=n,n.deps=[];for(var a in t.metadata.globals){var o=t.metadata.globals[a];o&&n.deps.push(o)}n.execute=function(e,n,a){var o;if(t.metadata.globals){o={};for(var i in t.metadata.globals)t.metadata.globals[i]&&(o[i]=e(t.metadata.globals[i]))}var s=t.metadata.exports;s&&(t.source+="\n"+ie+'["'+s+'"] = '+s+";");var l=r.get("@@global-helpers").prepareGlobal(a.id,s,o,!!t.metadata.encapsulateGlobal);return K.call(r,t),l()}}return e.call(this,t)}}),d("reduceRegister_",function(e){return function(t,r){if(r||!t.metadata.exports)return e.call(this,t,r);t.metadata.format="global";var n=t.metadata.entry=P();n.deps=t.metadata.deps;var a=R(t.metadata.exports);n.execute=function(){return a}}}),c(function(t){return function(){function r(t){if(Object.keys)Object.keys(e).forEach(t);else for(var r in e)i.call(e,r)&&t(r)}function n(t){r(function(r){if(-1==D.call(s,r)){try{var n=e[r]}catch(a){s.push(r)}t(r,n)}})}var a=this;t.call(a);var o,i=Object.prototype.hasOwnProperty,s=["_g","sessionStorage","localStorage","clipboardData","frames","frameElement","external","mozAnimationStartTime","webkitStorageInfo","webkitIndexedDB","mozInnerScreenY","mozInnerScreenX"];a.set("@@global-helpers",a.newModule({prepareGlobal:function(t,r,a,i){var s=e.define;e.define=void 0;var l;if(a){l={};for(var u in a)l[u]=e[u],e[u]=a[u]}return r||(o={},n(function(e,t){o[e]=t})),function(){var t,a=r?R(r):{},u=!!r;if((!r||i)&&n(function(n,s){o[n]!==s&&"undefined"!=typeof s&&(i&&(e[n]=void 0),r||(a[n]=s,"undefined"!=typeof t?u||t===s||(u=!0):t=s))}),a=u?a:t,l)for(var d in l)e[d]=l[d];return e.define=s,a}}}))}}),function(){function t(e){function t(e,t){for(var r=0;rt.index)return!0;return!1}n.lastIndex=a.lastIndex=o.lastIndex=0;var r,i=[],s=[],l=[];if(e.length/e.split("\n").length<200){for(;r=o.exec(e);)s.push([r.index,r.index+r[0].length]);for(;r=a.exec(e);)t(s,r)||l.push([r.index+r[1].length,r.index+r[0].length-1])}for(;r=n.exec(e);)if(!t(s,r)&&!t(l,r)){var u=r[1].substr(1,r[1].length-2);if(u.match(/"|'/))continue;"/"==u[u.length-1]&&(u=u.substr(0,u.length-1)),i.push(u)}return i}var r=/(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])(exports\s*(\[['"]|\.)|module(\.exports|\['exports'\]|\["exports"\])\s*(\[['"]|[=,\.]))/,n=/(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF."'])require\s*\(\s*("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*')\s*\)/g,a=/(^|[^\\])(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/gm,o=/("[^"\\\n\r]*(\\.[^"\\\n\r]*)*"|'[^'\\\n\r]*(\\.[^'\\\n\r]*)*')/g,i=/^\#\!.*/;d("instantiate",function(a){return function(o){var s=this;if(o.metadata.format||(r.lastIndex=0,n.lastIndex=0,(n.exec(o.source)||r.exec(o.source))&&(o.metadata.format="cjs")),"cjs"==o.metadata.format){var l=o.metadata.deps,u=o.metadata.cjsRequireDetection===!1?[]:t(o.source);for(var d in o.metadata.globals)o.metadata.globals[d]&&u.push(o.metadata.globals[d]);var c=P();o.metadata.entry=c,c.deps=u,c.executingRequire=!0,c.execute=function(t,r,n){function a(e){return"/"==e[e.length-1]&&(e=e.substr(0,e.length-1)),t.apply(this,arguments)}if(a.resolve=function(e){return s.get("@@cjs-helpers").requireResolve(e,n.id)},!o.metadata.cjsDeferDepsExecute)for(var u=0;u1;)n=a.shift(),e=e[n]=e[n]||{};n=a.shift(),n in e||(e[n]=r)}c(function(e){return function(){this.meta={},e.call(this)}}),d("locate",function(e){return function(t){var r,n=this.meta,a=t.name,o=0;for(var i in n)if(r=i.indexOf("*"),-1!==r&&i.substr(0,r)===a.substr(0,r)&&i.substr(r+1)===a.substr(a.length-i.length+r+1)){var s=i.split("/").length;s>o&&(o=s),g(t.metadata,n[i],o!=s)}return n[a]&&g(t.metadata,n[a]),e.call(this,t)}});var t=/^(\s*\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)+/,r=/\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\/\/[^\n]*|"[^"]+"\s*;?|'[^']+'\s*;?/g;d("translate",function(n){return function(a){var o=a.source.match(t);if(o)for(var i=o[0].match(r),s=0;s')}else e()}else if("undefined"!=typeof importScripts){var a="";try{throw new Error("_")}catch(o){o.stack.replace(/(?:at|@).*(http.+):[\d]+:[\d]+/,function(e,t){$__curScript={src:t},a=t.replace(/\/[^\/]*$/,"/")})}t&&importScripts(a+"system-polyfills.js"),e()}else $__curScript="undefined"!=typeof __filename?{src:__filename}:null,e()}(); 6 | //# sourceMappingURL=system.js.map 7 | -------------------------------------------------------------------------------- /extension/js/system.js: -------------------------------------------------------------------------------- 1 | /* 2 | * SystemJS v0.19.28 3 | */ 4 | !function(){function e(){!function(e){function t(e,r){if("string"!=typeof e)throw new TypeError("URL must be a string");var n=String(e).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);if(!n)throw new RangeError("Invalid URL format");var a=n[1]||"",o=n[2]||"",i=n[3]||"",s=n[4]||"",l=n[5]||"",u=n[6]||"",d=n[7]||"",c=n[8]||"",f=n[9]||"";if(void 0!==r){var m=r instanceof t?r:new t(r),p=!a&&!s&&!o;!p||d||c||(c=m.search),p&&"/"!==d[0]&&(d=d?(!m.host&&!m.username||m.pathname?"":"/")+m.pathname.slice(0,m.pathname.lastIndexOf("/")+1)+d:m.pathname);var h=[];d.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(e){"/.."===e?h.pop():h.push(e)}),d=h.join("").replace(/^\//,"/"===d[0]?"/":""),p&&(u=m.port,l=m.hostname,s=m.host,i=m.password,o=m.username),a||(a=m.protocol)}"file:"==a&&(d=d.replace(/\\/g,"/")),this.origin=s?a+(""!==a||""!==s?"//":"")+s:"",this.href=a+(a&&s||"file:"==a?"//":"")+(""!==o?o+(""!==i?":"+i:"")+"@":"")+s+d+c+f,this.protocol=a,this.username=o,this.password=i,this.host=s,this.hostname=l,this.port=u,this.pathname=d,this.search=c,this.hash=f}e.URLPolyfill=t}("undefined"!=typeof self?self:global),function(e){function t(e,t){if(!e.originalErr)for(var r=(e.stack||e.message||e).split("\n"),n=[],a=0;a2)throw new TypeError("Only one wildcard in a path is permitted");if(1==i.length){if(t==o)return e[o];if(t.substr(0,o.length-1)==o.substr(0,o.length-1)&&(t.lengtho.length?(e[o]&&"/"||"")+t.substr(o.length):"")}else{var s=i[0].length;s>=a&&t.substr(0,i[0].length)==i[0]&&t.substr(t.length-i[1].length)==i[1]&&(a=s,n=o,r=t.substr(i[0].length,t.length-i[1].length-i[0].length))}}var l=e[n];return"string"==typeof r&&(l=l.replace("*",r)),l}function s(){}function l(){o.call(this),W.call(this)}function u(){}function d(e,t){l.prototype[e]=t(l.prototype[e]||function(){})}function c(e){W=e(W||function(){})}function f(e){for(var t=[],r=[],n=0,a=e.length;a>n;n++){var o=D.call(t,e[n]);-1===o?(t.push(e[n]),r.push([n])):r[o].push(n)}return{names:t,indices:r}}function m(t){var r={};if(("object"==typeof t||"function"==typeof t)&&t!==e)if(V)for(var n in t)"default"!==n&&p(r,t,n);else h(r,t);return r["default"]=t,F(r,"__useDefault",{value:!0}),r}function p(e,t,r){try{var n;(n=Object.getOwnPropertyDescriptor(t,r))&&F(e,r,n)}catch(a){return e[r]=t[r],!1}}function h(e,t,r){var n=t&&t.hasOwnProperty;for(var a in t)(!n||t.hasOwnProperty(a))&&(r&&a in e||(e[a]=t[a]));return e}function g(e,t,r){var n=t&&t.hasOwnProperty;for(var a in t)if(!n||t.hasOwnProperty(a)){var o=t[a];a in e?o instanceof Array&&e[a]instanceof Array?e[a]=[].concat(r?o:e[a]).concat(r?e[a]:o):"object"==typeof o&&null!==o&&"object"==typeof e[a]?e[a]=h(h({},e[a]),o,r):r||(e[a]=o):e[a]=o}}function v(e){this.warnings&&"undefined"!=typeof console&&console.warn}function b(e,t){for(var r=e.split(".");r.length;)t=t[r.shift()];return t}function y(){if(te[this.baseURL])return te[this.baseURL];"/"!=this.baseURL[this.baseURL.length-1]&&(this.baseURL+="/");var e=new B(this.baseURL,U);return this.baseURL=e.href,te[this.baseURL]=e}function w(e,t){var r,n=0;for(var a in e)if(t.substr(0,a.length)==a&&(t.length==a.length||"/"==t[a.length])){var o=a.split("/").length;if(n>=o)continue;r=a,n=o}return r}function x(e){this.set("@system-env",Q=this.newModule({browser:L,node:!!this._nodeRequire,production:e,dev:!e,"default":!0}))}function S(e){return("."!=e[0]||!!e[1]&&"/"!=e[1]&&"."!=e[1])&&"/"!=e[0]&&!e.match(ee)}function E(e,t){return t&&(t=t.replace(/#/g,"%05")),new B(e,t||re).href.replace(/%05/g,"#")}function _(e,t){return new B(t,y.call(e)).href}function j(e,t){if(!S(e))return E(e,t);var r=w(this.map,e);if(r&&(e=this.map[r]+e.substr(r.length),!S(e)))return E(e);if(this.has(e))return e;if("@node/"==e.substr(0,6)){if(!this._nodeRequire)throw new TypeError("Error loading "+e+". Can only load node core modules in Node.");if(!S(e.substr(6)))throw new Error("Node module "+e.substr(6)+" can't be loaded as it is not a package require.");return this.set(e,this.newModule(m(this._nodeRequire(e.substr(6))))),e}var n=i(this.paths,e);return n&&!S(n)?E(n):_(this,n||e)}function k(e){var t=e.match(oe);return t&&"System.register"==e.substr(t[0].length,15)}function P(){return{name:null,deps:null,originalIndices:null,declare:null,execute:null,executingRequire:!1,declarative:!1,normalizedDeps:null,groupIndex:null,evaluated:!1,module:null,esModule:null,esmExports:!1}}function R(t){if("string"==typeof t)return b(t,e);if(!(t instanceof Array))throw new Error("Global exports must be a string or array.");for(var r={},n=!0,a=0;at;t++)if(this[t]===e)return t;return-1};!function(){try{Object.defineProperty({},"a",{})&&(F=Object.defineProperty)}catch(e){F=function(e,t,r){try{e[t]=r.value||r.get.call(e)}catch(n){}}}}();var U,q="_"==new Error(0,"_").fileName;if("undefined"!=typeof document&&document.getElementsByTagName){if(U=document.baseURI,!U){var J=document.getElementsByTagName("base");U=J[0]&&J[0].href||window.location.href}U=U.split("#")[0].split("?")[0],U=U.substr(0,U.lastIndexOf("/")+1)}else if("undefined"!=typeof process&&process.cwd)U="file://"+(A?"/":"")+process.cwd()+"/",A&&(U=U.replace(/\\/g,"/"));else{if("undefined"==typeof location)throw new TypeError("No environment baseURI");U=e.location.href}try{var N="test:"==new e.URL("test:///").protocol}catch($){}var B=N?e.URL:e.URLPolyfill;F(n.prototype,"toString",{value:function(){return"Module"}}),function(){function o(e){return{status:"loading",name:e,linkSets:[],dependencies:[],metadata:{}}}function i(e,t,r){return new Promise(c({step:r.address?"fetch":"locate",loader:e,moduleName:t,moduleMetadata:r&&r.metadata||{},moduleSource:r.source,moduleAddress:r.address}))}function s(e,t,r,n){return new Promise(function(a,o){a(e.loaderObj.normalize(t,r,n))}).then(function(t){var r;if(e.modules[t])return r=o(t),r.status="linked",r.module=e.modules[t],r;for(var n=0,a=e.loads.length;a>n;n++)if(r=e.loads[n],r.name==t)return r;return r=o(t),e.loads.push(r),l(e,r),r})}function l(e,t){u(e,t,Promise.resolve().then(function(){return e.loaderObj.locate({name:t.name,metadata:t.metadata})}))}function u(e,t,r){d(e,t,r.then(function(r){return"loading"==t.status?(t.address=r,e.loaderObj.fetch({name:t.name,metadata:t.metadata,address:r})):void 0}))}function d(t,n,a){a.then(function(a){return"loading"==n.status?Promise.resolve(t.loaderObj.translate({name:n.name,metadata:n.metadata,address:n.address,source:a})).then(function(e){return n.source=e,t.loaderObj.instantiate({name:n.name,metadata:n.metadata,address:n.address,source:e})}).then(function(a){if(void 0===a)return n.address=n.address||"",n.isDeclarative=!0,E.call(t.loaderObj,n).then(function(t){var a=e.System,o=a.register;a.register=function(e,t,r){"string"!=typeof e&&(r=t,t=e),n.declare=r,n.depsList=t},r(t,n.address,{}),a.register=o});if("object"!=typeof a)throw TypeError("Invalid instantiate return value");n.depsList=a.deps||[],n.execute=a.execute,n.isDeclarative=!1}).then(function(){n.dependencies=[];for(var e=n.depsList,r=[],a=0,o=e.length;o>a;a++)(function(e,a){r.push(s(t,e,n.name,n.address).then(function(t){if(n.dependencies[a]={key:e,value:t.name},"linked"!=t.status)for(var r=n.linkSets.concat([]),o=0,i=r.length;i>o;o++)m(r[o],t)}))})(e[a],a);return Promise.all(r)}).then(function(){n.status="loaded";for(var e=n.linkSets.concat([]),t=0,r=e.length;r>t;t++)h(e[t],n)}):void 0})["catch"](function(e){n.status="failed",n.exception=e;for(var t=n.linkSets.concat([]),r=0,a=t.length;a>r;r++)g(t[r],n,e)})}function c(e){return function(t,r){var n=e.loader,a=e.moduleName,i=e.step;if(n.modules[a])throw new TypeError('"'+a+'" already exists in the module table');for(var s,c=0,m=n.loads.length;m>c;c++)if(n.loads[c].name==a&&(s=n.loads[c],"translate"!=i||s.source||(s.address=e.moduleAddress,d(n,s,Promise.resolve(e.moduleSource))),s.linkSets.length&&s.linkSets[0].loads[0].name==s.name))return s.linkSets[0].done.then(function(){t(s)});var p=s||o(a);p.metadata=e.moduleMetadata;var h=f(n,p);n.loads.push(p),t(h.done),"locate"==i?l(n,p):"fetch"==i?u(n,p,Promise.resolve(e.moduleAddress)):(p.address=e.moduleAddress,d(n,p,Promise.resolve(e.moduleSource)))}}function f(e,t){var r={loader:e,loads:[],startingLoad:t,loadingCount:0};return r.done=new Promise(function(e,t){r.resolve=e,r.reject=t}),m(r,t),r}function m(e,t){if("failed"!=t.status){for(var r=0,n=e.loads.length;n>r;r++)if(e.loads[r]==t)return;e.loads.push(t),t.linkSets.push(e),"loaded"!=t.status&&e.loadingCount++;for(var a=e.loader,r=0,n=t.dependencies.length;n>r;r++)if(t.dependencies[r]){var o=t.dependencies[r].value;if(!a.modules[o])for(var i=0,s=a.loads.length;s>i;i++)if(a.loads[i].name==o){m(e,a.loads[i]);break}}}}function p(e){var t=!1;try{w(e,function(r,n){g(e,r,n),t=!0})}catch(r){g(e,null,r),t=!0}return t}function h(e,t){if(e.loadingCount--,!(e.loadingCount>0)){var r=e.startingLoad;if(e.loader.loaderObj.execute===!1){for(var n=[].concat(e.loads),a=0,o=n.length;o>a;a++){var t=n[a];t.module=t.isDeclarative?{name:t.name,module:j({}),evaluated:!0}:{module:j({})},t.status="linked",v(e.loader,t)}return e.resolve(r)}var i=p(e);i||e.resolve(r)}}function g(e,r,n){var a=e.loader;e:if(r)if(e.loads[0].name==r.name)n=t(n,"Error loading "+r.name);else{for(var o=0;oo;o++){var r=u[o];a.loaderObj.failed=a.loaderObj.failed||[],-1==D.call(a.loaderObj.failed,r)&&a.loaderObj.failed.push(r);var c=D.call(r.linkSets,e);if(r.linkSets.splice(c,1),0==r.linkSets.length){var f=D.call(e.loader.loads,r);-1!=f&&e.loader.loads.splice(f,1)}}e.reject(n)}function v(e,t){if(e.loaderObj.trace){e.loaderObj.loads||(e.loaderObj.loads={});var r={};t.dependencies.forEach(function(e){r[e.key]=e.value}),e.loaderObj.loads[t.name]={name:t.name,deps:t.dependencies.map(function(e){return e.key}),depMap:r,address:t.address,metadata:t.metadata,source:t.source,kind:t.isDeclarative?"declarative":"dynamic"}}t.name&&(e.modules[t.name]=t.module);var n=D.call(e.loads,t);-1!=n&&e.loads.splice(n,1);for(var a=0,o=t.linkSets.length;o>a;a++)n=D.call(t.linkSets[a].loads,t),-1!=n&&t.linkSets[a].loads.splice(n,1);t.linkSets.splice(0,t.linkSets.length)}function b(e,t,r){try{var a=t.execute()}catch(o){return void r(t,o)}return a&&a instanceof n?a:void r(t,new TypeError("Execution must define a Module instance"))}function y(e,t,r){var n=e._loader.importPromises;return n[t]=r.then(function(e){return n[t]=void 0,e},function(e){throw n[t]=void 0,e})}function w(e,t){var r=e.loader;if(e.loads.length)for(var n=e.loads.concat([]),a=0;a "'+n.paths[o]+'" uses wildcards which are being deprecated for simpler trailing "/" folder paths.')}if(e.defaultJSExtensions&&(n.defaultJSExtensions=e.defaultJSExtensions,v.call(n,"The defaultJSExtensions configuration option is deprecated, use packages configuration instead.")),e.pluginFirst&&(n.pluginFirst=e.pluginFirst),e.map){var i="";for(var o in e.map){var s=e.map[o];if("string"!=typeof s){i+=(i.length?", ":"")+'"'+o+'"';var l=n.defaultJSExtensions&&".js"!=o.substr(o.length-3,3),u=n.decanonicalize(o);l&&".js"==u.substr(u.length-3,3)&&(u=u.substr(0,u.length-3));var d="";for(var c in n.packages)u.substr(0,c.length)==c&&(!u[c.length]||"/"==u[c.length])&&d.split("/").lengtha&&(r=o,a=n));return r}function t(e,t,r,n,a){if(!n||"/"==n[n.length-1]||a||t.defaultExtension===!1)return n;var o=!1;if(t.meta&&p(t.meta,n,function(e,t,r){return 0==r||e.lastIndexOf("*")!=e.length-1?o=!0:void 0}),!o&&e.meta&&p(e.meta,r+"/"+n,function(e,t,r){return 0==r||e.lastIndexOf("*")!=e.length-1?o=!0:void 0}),o)return n;var i="."+(t.defaultExtension||"js");return n.substr(n.length-i.length)!=i?n+i:n}function r(e,r,n,o,i){if(!o){if(!r.main)return n+(e.defaultJSExtensions?".js":"");o="./"==r.main.substr(0,2)?r.main.substr(2):r.main}if(r.map){var s="./"+o,l=w(r.map,s);if(l||(s="./"+t(e,r,n,o,i),s!="./"+o&&(l=w(r.map,s))),l)return a(e,r,n,l,s,i)}return n+"/"+t(e,r,n,o,i)}function n(e,t,r){if("."==e)throw new Error("Package "+r+' has a map entry for "." which is not permitted.');if(t.substr(0,e.length)==e&&"/"!=e[e.length-1]&&"/"==t[e.length])throw new Error("Package "+r+' has a recursive map for "'+e+'" which is not permitted.')}function a(e,r,a,o,i,s){var l=r.map[o];if("object"==typeof l)throw new Error("Synchronous conditional normalization not supported sync normalizing "+o+" in "+a);if(n(o,l,a),"string"!=typeof l&&(l=o=i),n(o,l,a),"."==l)l=a;else if("./"==l.substr(0,2))return a+"/"+t(e,r,a,l.substr(2)+i.substr(o.length),s);return e.normalizeSync(l+i.substr(o.length),a+"/")}function o(e,r,n,a,o){if(!a){if(!r.main)return Promise.resolve(n+(e.defaultJSExtensions?".js":""));a="./"==r.main.substr(0,2)?r.main.substr(2):r.main}var i,l;return r.map&&(i="./"+a,l=w(r.map,i),l||(i="./"+t(e,r,n,a,o),i!="./"+a&&(l=w(r.map,i)))),(l?s(e,r,n,l,i,o):Promise.resolve()).then(function(i){return i?Promise.resolve(i):Promise.resolve(n+"/"+t(e,r,n,a,o))})}function i(e,r,n,a,o,i,s){if("."==o)o=n;else if("./"==o.substr(0,2))return Promise.resolve(n+"/"+t(e,r,n,o.substr(2)+i.substr(a.length),s)).then(function(t){return C.call(e,t,n+"/")});return e.normalize(o+i.substr(a.length),n+"/")}function s(e,t,r,a,o,s){var l=t.map[a];if("string"==typeof l)return n(a,l,r),i(e,t,r,a,l,o,s);if(e.builder)return Promise.resolve(r+"/#:"+o);var u=[],d=[];for(var c in l){var f=O(c);d.push({condition:f,map:l[c]}),u.push(e["import"](f.module,r))}return Promise.all(u).then(function(e){for(var t=0;tl&&(l=r),g(s,t,r&&l>r)}),g(r.metadata,s)}o.format&&!r.metadata.loader&&(r.metadata.format=r.metadata.format||o.format)}return t})}})}(),function(){function t(){if(i&&"interactive"===i.script.readyState)return i.load;for(var e=0;ea;a++){var i=e.normalizedDeps[a],s=r.defined[i];if(s&&!s.evaluated){var l=e.groupIndex+(s.declarative!=e.declarative);if(null===s.groupIndex||s.groupIndex=0;s--){for(var l=a[s],d=0;dn;n++){var i=a.importers[n];if(!i.locked){var l=D.call(i.dependencies,a);i.setters[l](s)}}return a.locked=!1,t},{id:t.name});if(a.setters=l.setters,a.execute=l.execute,!a.setters||!a.execute)throw new TypeError("Invalid System.register form for "+t.name);for(var u=0,d=t.normalizedDeps.length;d>u;u++){var c,f=t.normalizedDeps[u],m=r.defined[f],p=n[f];p?c=p.exports:m&&!m.declarative?c=m.esModule:m?(i(m,r),p=m.module,c=p.exports):c=r.get(f),p&&p.importers?(p.importers.push(a),a.dependencies.push(p)):a.dependencies.push(null);for(var h=t.originalIndices[u],g=0,v=h.length;v>g;++g){var b=h[g];a.setters[b]&&a.setters[b](c)}}}}function s(e,t){var r,n=t.defined[e];if(n)n.declarative?p(e,[],t):n.evaluated||u(n,t),r=n.module.exports;else if(r=t.get(e),!r)throw new Error("Unable to load dependency "+e+".");return(!n||n.declarative)&&r&&r.__useDefault?r["default"]:r}function u(t,r){if(!t.module){var a={},o=t.module={exports:a,id:t.name};if(!t.executingRequire)for(var i=0,l=t.normalizedDeps.length;l>i;i++){var d=t.normalizedDeps[i],c=r.defined[d];c&&u(c,r)}t.evaluated=!0;var f=t.execute.call(e,function(e){for(var n=0,a=t.deps.length;a>n;n++)if(t.deps[n]==e)return s(t.normalizedDeps[n],r);var o=r.normalizeSync(e,t.name);if(-1!=D.call(t.normalizedDeps,o))return s(o,r);throw new Error("Module "+e+" not declared as a dependency of "+t.name)},a,o);f&&(o.exports=f),a=o.exports,a&&(a.__esModule||a instanceof n)?t.esModule=a:t.esmExports&&a!==e?t.esModule=m(a):t.esModule={"default":a}}}function p(t,r,n){var a=n.defined[t];if(a&&!a.evaluated&&a.declarative){r.push(t);for(var o=0,i=a.normalizedDeps.length;i>o;o++){var s=a.normalizedDeps[o];-1==D.call(r,s)&&(n.defined[s]?p(s,r,n):n.get(s))}a.evaluated||(a.evaluated=!0,a.module.execute.call(e))}}l.prototype.register=function(e,t,r){if("string"!=typeof e&&(r=t,t=e,e=null),"boolean"==typeof r)return this.registerDynamic.apply(this,arguments);var n=P();n.name=e&&(this.decanonicalize||this.normalize).call(this,e),n.declarative=!0,n.deps=t,n.declare=r,this.pushRegister_({amd:!1,entry:n})},l.prototype.registerDynamic=function(e,t,r,n){"string"!=typeof e&&(n=r,r=t,t=e,e=null);var a=P();a.name=e&&(this.decanonicalize||this.normalize).call(this,e),a.deps=t,a.execute=n,a.executingRequire=r,this.pushRegister_({amd:!1,entry:a})},d("reduceRegister_",function(){return function(e,t){if(t){var r=t.entry,n=e&&e.metadata;if(r.name&&(r.name in this.defined||(this.defined[r.name]=r),n&&(n.bundle=!0)),!r.name||e&&!n.entry&&r.name==e.name){if(!n)throw new TypeError("Invalid System.register call. Anonymous System.register calls can only be made by modules loaded by SystemJS.import and not via script tags.");if(n.entry)throw"register"==n.format?new Error("Multiple anonymous System.register calls in module "+e.name+". If loading a bundle, ensure all the System.register calls are named."):new Error("Module "+e.name+" interpreted as "+n.format+" module format, but called System.register.");n.format||(n.format="register"),n.entry=r}}}}),c(function(e){return function(){e.call(this),this.defined={},this._loader.moduleRecords={}}}),F(a,"toString",{value:function(){return"Module"}}),d("delete",function(e){return function(t){return delete this._loader.moduleRecords[t],delete this.defined[t],e.call(this,t)}}),d("fetch",function(e){return function(t){return this.defined[t.name]?(t.metadata.format="defined",""):(t.metadata.deps=t.metadata.deps||[],e.call(this,t))}}),d("translate",function(e){return function(t){return t.metadata.deps=t.metadata.deps||[],Promise.resolve(e.call(this,t)).then(function(e){return("register"==t.metadata.format||!t.metadata.format&&k(t.source))&&(t.metadata.format="register"),e})}}),d("instantiate",function(e){return function(t){"detect"==t.metadata.format&&(t.metadata.format=void 0),e.call(this,t);var n,a=this;if(a.defined[t.name])n=a.defined[t.name],n.declarative||(n.deps=n.deps.concat(t.metadata.deps)),n.deps=n.deps.concat(t.metadata.deps);else if(t.metadata.entry)n=t.metadata.entry,n.deps=n.deps.concat(t.metadata.deps);else if(!(a.builder&&t.metadata.bundle||"register"!=t.metadata.format&&"esm"!=t.metadata.format&&"es6"!=t.metadata.format)){if("undefined"!=typeof K&&K.call(a,t),!t.metadata.entry&&!t.metadata.bundle)throw new Error(t.name+" detected as "+t.metadata.format+" but didn't execute.");n=t.metadata.entry,n&&t.metadata.deps&&(n.deps=n.deps.concat(t.metadata.deps))}n||(n=P(),n.deps=t.metadata.deps,n.execute=function(){}),a.defined[t.name]=n;var o=f(n.deps);n.deps=o.names,n.originalIndices=o.indices,n.name=t.name,n.esmExports=t.metadata.esmExports!==!1;for(var i=[],s=0,l=n.deps.length;l>s;s++)i.push(Promise.resolve(a.normalize(n.deps[s],t.name)));return Promise.all(i).then(function(e){return n.normalizedDeps=e,{deps:n.deps,execute:function(){return r(t.name,a),p(t.name,[],a),a.defined[t.name]=void 0,a.newModule(n.declarative?n.module.exports:n.esModule)}}})}})}(),function(){var t=/(^\s*|[}\);\n]\s*)(import\s*(['"]|(\*\s+as\s+)?[^"'\(\)\n;]+\s*from\s*['"]|\{)|export\s+\*\s+from\s+["']|export\s*(\{|default|function|class|var|const|let|async\s+function))/,r=/\$traceurRuntime\s*\./,n=/babelHelpers\s*\./;d("translate",function(a){return function(o){var i=this;return a.call(i,o).then(function(a){if("esm"==o.metadata.format||"es6"==o.metadata.format||!o.metadata.format&&a.match(t)){if("es6"==o.metadata.format&&v.call(i,"Module "+o.name+' has metadata setting its format to "es6", which is deprecated.\nThis should be updated to "esm".'),o.metadata.format="esm",o.metadata.deps){for(var s="",l=0;l100&&!o.metadata.format&&(o.metadata.format="global","traceur"===i.transpiler&&(o.metadata.exports="traceur"),"typescript"===i.transpiler&&(o.metadata.exports="ts")),i._loader.loadedTranspiler=!0),i._loader.loadedTranspilerRuntime===!1&&(o.name==i.normalizeSync("traceur-runtime")||o.name==i.normalizeSync("babel/external-helpers*"))&&(a.length>100&&(o.metadata.format=o.metadata.format||"global"),i._loader.loadedTranspilerRuntime=!0),("register"==o.metadata.format||o.metadata.bundle)&&i._loader.loadedTranspilerRuntime!==!0){if(!e.$traceurRuntime&&o.source.match(r))return i._loader.loadedTranspilerRuntime=i._loader.loadedTranspilerRuntime||!1,i["import"]("traceur-runtime").then(function(){return a});if(!e.babelHelpers&&o.source.match(n))return i._loader.loadedTranspilerRuntime=i._loader.loadedTranspilerRuntime||!1,i["import"]("babel/external-helpers").then(function(){return a})}return a})}})}();var ie="undefined"!=typeof self?"self":"global";d("fetch",function(e){return function(t){return t.metadata.exports&&!t.metadata.format&&(t.metadata.format="global"),e.call(this,t)}}),d("instantiate",function(e){return function(t){var r=this;if(t.metadata.format||(t.metadata.format="global"),"global"==t.metadata.format&&!t.metadata.registered){var n=P();t.metadata.entry=n,n.deps=[];for(var a in t.metadata.globals){var o=t.metadata.globals[a];o&&n.deps.push(o)}n.execute=function(e,n,a){var o;if(t.metadata.globals){o={};for(var i in t.metadata.globals)t.metadata.globals[i]&&(o[i]=e(t.metadata.globals[i]))}var s=t.metadata.exports;s&&(t.source+="\n"+ie+'["'+s+'"] = '+s+";");var l=r.get("@@global-helpers").prepareGlobal(a.id,s,o,!!t.metadata.encapsulateGlobal);return K.call(r,t),l()}}return e.call(this,t)}}),d("reduceRegister_",function(e){return function(t,r){if(r||!t.metadata.exports)return e.call(this,t,r);t.metadata.format="global";var n=t.metadata.entry=P();n.deps=t.metadata.deps;var a=R(t.metadata.exports);n.execute=function(){return a}}}),c(function(t){return function(){function r(t){if(Object.keys)Object.keys(e).forEach(t);else for(var r in e)i.call(e,r)&&t(r)}function n(t){r(function(r){if(-1==D.call(s,r)){try{var n=e[r]}catch(a){s.push(r)}t(r,n)}})}var a=this;t.call(a);var o,i=Object.prototype.hasOwnProperty,s=["_g","sessionStorage","localStorage","clipboardData","frames","frameElement","external","mozAnimationStartTime","webkitStorageInfo","webkitIndexedDB","mozInnerScreenY","mozInnerScreenX"];a.set("@@global-helpers",a.newModule({prepareGlobal:function(t,r,a,i){var s=e.define;e.define=void 0;var l;if(a){l={};for(var u in a)l[u]=e[u],e[u]=a[u]}return r||(o={},n(function(e,t){o[e]=t})),function(){var t,a=r?R(r):{},u=!!r;if((!r||i)&&n(function(n,s){o[n]!==s&&"undefined"!=typeof s&&(i&&(e[n]=void 0),r||(a[n]=s,"undefined"!=typeof t?u||t===s||(u=!0):t=s))}),a=u?a:t,l)for(var d in l)e[d]=l[d];return e.define=s,a}}}))}}),function(){function t(e){function t(e,t){for(var r=0;rt.index)return!0;return!1}n.lastIndex=a.lastIndex=o.lastIndex=0;var r,i=[],s=[],l=[];if(e.length/e.split("\n").length<200){for(;r=o.exec(e);)s.push([r.index,r.index+r[0].length]);for(;r=a.exec(e);)t(s,r)||l.push([r.index+r[1].length,r.index+r[0].length-1])}for(;r=n.exec(e);)if(!t(s,r)&&!t(l,r)){var u=r[1].substr(1,r[1].length-2);if(u.match(/"|'/))continue;"/"==u[u.length-1]&&(u=u.substr(0,u.length-1)),i.push(u)}return i}var r=/(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])(exports\s*(\[['"]|\.)|module(\.exports|\['exports'\]|\["exports"\])\s*(\[['"]|[=,\.]))/,n=/(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF."'])require\s*\(\s*("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*')\s*\)/g,a=/(^|[^\\])(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/gm,o=/("[^"\\\n\r]*(\\.[^"\\\n\r]*)*"|'[^'\\\n\r]*(\\.[^'\\\n\r]*)*')/g,i=/^\#\!.*/;d("instantiate",function(a){return function(o){var s=this;if(o.metadata.format||(r.lastIndex=0,n.lastIndex=0,(n.exec(o.source)||r.exec(o.source))&&(o.metadata.format="cjs")),"cjs"==o.metadata.format){var l=o.metadata.deps,u=o.metadata.cjsRequireDetection===!1?[]:t(o.source);for(var d in o.metadata.globals)o.metadata.globals[d]&&u.push(o.metadata.globals[d]);var c=P();o.metadata.entry=c,c.deps=u,c.executingRequire=!0,c.execute=function(t,r,n){function a(e){return"/"==e[e.length-1]&&(e=e.substr(0,e.length-1)),t.apply(this,arguments)}if(a.resolve=function(e){return s.get("@@cjs-helpers").requireResolve(e,n.id)},!o.metadata.cjsDeferDepsExecute)for(var u=0;u1;)n=a.shift(),e=e[n]=e[n]||{};n=a.shift(),n in e||(e[n]=r)}c(function(e){return function(){this.meta={},e.call(this)}}),d("locate",function(e){return function(t){var r,n=this.meta,a=t.name,o=0;for(var i in n)if(r=i.indexOf("*"),-1!==r&&i.substr(0,r)===a.substr(0,r)&&i.substr(r+1)===a.substr(a.length-i.length+r+1)){var s=i.split("/").length;s>o&&(o=s),g(t.metadata,n[i],o!=s)}return n[a]&&g(t.metadata,n[a]),e.call(this,t)}});var t=/^(\s*\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)+/,r=/\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\/\/[^\n]*|"[^"]+"\s*;?|'[^']+'\s*;?/g;d("translate",function(n){return function(a){var o=a.source.match(t);if(o)for(var i=o[0].match(r),s=0;s')}else e()}else if("undefined"!=typeof importScripts){var a="";try{throw new Error("_")}catch(o){o.stack.replace(/(?:at|@).*(http.+):[\d]+:[\d]+/,function(e,t){$__curScript={src:t},a=t.replace(/\/[^\/]*$/,"/")})}t&&importScripts(a+"system-polyfills.js"),e()}else $__curScript="undefined"!=typeof __filename?{src:__filename}:null,e()}(); 6 | //# sourceMappingURL=system.js.map 7 | --------------------------------------------------------------------------------