Skip to content

Instantly share code, notes, and snippets.

@ebith
Created May 31, 2014 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebith/352db6741eb4df8231ee to your computer and use it in GitHub Desktop.
Save ebith/352db6741eb4df8231ee to your computer and use it in GitHub Desktop.
VimperatorプラグインなSteamクライアント
// Generated by CoffeeScript 1.7.1
(function() {
var apiKey, request, setup, steamId, subCommands;
apiKey = liberator.globalVariables.steam_api || 'E912B5192623C96289A8EA2322E501DB';
if (!liberator.globalVariables.steam_id) {
return liberator.echoerr('steam: need steam id');
} else {
steamId = liberator.globalVariables.steam_id;
}
setup = function() {
var options;
options = {
responseType: 'json',
url: "https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=" + apiKey + "&steamid=" + steamId + "&format=json&include_appinfo=1"
};
return request(options, function(res) {
if (res.status === 200) {
return this.games = res.response.response.games;
}
});
};
subCommands = [
new Command('p[lay]', 'play game', function(args) {
return liberator.open("steam://run/" + args);
}, {
options: [[['-sort', '-s'], commands.OPTION_STRING, null, [['title', ''], ['title!', ''], ['playtime', ''], ['playtime!', '']]]],
completer: function(context, args) {
context.title = ['Title', 'Total playtime'];
context.keys = {
text: 'appid',
description: 'playtime',
icon: 'icon'
};
context.process = [
function(item, text) {
return new TemplateXML("<span highlight=\"CompIcon\"><img src=\"" + item.icon + "\"/></span><span class=\"td-strut\"/>" + (util.escapeHTML(item.item.name)));
}
];
context.filters = [
function(item) {
return this.match(item.item.name);
}
];
context.completions = (function() {
var game, list;
list = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = games.length; _i < _len; _i++) {
game = games[_i];
_results.push({
appid: game.appid,
name: game.name,
playtime: (game.playtime_forever / 60).toFixed(1),
icon: "http://media.steampowered.com/steamcommunity/public/images/apps/" + game.appid + "/" + game.img_icon_url + ".jpg"
});
}
return _results;
})();
switch (args['-sort']) {
case 'playtime':
list.sort(function(a, b) {
return a.playtime - b.playtime;
});
break;
case 'playtime!':
list.sort(function(a, b) {
return b.playtime - a.playtime;
});
break;
case 'title!':
list.sort(function(a, b) {
return b.name.localeCompare(a.name);
});
break;
default:
list.sort(function(a, b) {
return a.name.localeCompare(b.name);
});
}
return list;
})();
return context.compare = CompletionContext.Sort.unsorted;
}
})
];
commands.addUserCommand(['steam'], 'steam', function(args) {
return liberator.open('steam://');
}, {
subCommands: subCommands
}, true);
request = function(options, callback) {
var body, key, value, xhr, _ref, _ref1, _ref2;
xhr = new XMLHttpRequest();
xhr.open((_ref = options.method) != null ? _ref : 'GET', options.url);
if (options.method === 'POST') {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
_ref1 = options.headers;
for (key in _ref1) {
value = _ref1[key];
xhr.setRequestHeader(key, value);
}
xhr.responseType = (_ref2 = options.responseType) != null ? _ref2 : 'text';
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
return callback(xhr);
}
};
body = (function() {
var _ref3, _results;
_ref3 = options.body;
_results = [];
for (key in _ref3) {
value = _ref3[key];
_results.push("" + (encodeURIComponent(key)) + "=" + (encodeURIComponent(value)));
}
return _results;
})();
return xhr.send(options.body ? body.join('&') : null);
};
setup();
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment