Skip to content

Instantly share code, notes, and snippets.

@YungSang
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save YungSang/9922467 to your computer and use it in GitHub Desktop.

Select an option

Save YungSang/9922467 to your computer and use it in GitHub Desktop.
Taberareloo 用パッチ:CoreOS のリリースをチェックする
// ==Taberareloo==
// {
// "name" : "Check CoreOS Releases"
// , "description" : "Check CoreOS Releases"
// , "include" : ["background"]
// , "version" : "2.0.0"
// , "downloadURL" : "https://gist.github.com/YungSang/9922467/raw/patch.check.coreos.release.tbrl.js"
// }
// ==/Taberareloo==
(function() {
var TITLE = 'Check CoreOS Releases';
var URL = 'http://storage.core-os.net/coreos/amd64-usr/';
var KEY = 'coreos_previous_version';
var CHANNELS = ['master', 'alpha', 'beta'];
var PREVIOUS_VERSIONS = localStorage.getItem(KEY);
try {
PREVIOUS_VERSIONS = JSON.parse(PREVIOUS_VERSIONS);
if (!PREVIOUS_VERSIONS) {
throw 'null';
}
}
catch (e) {
PREVIOUS_VERSIONS = {};
CHANNELS.forEach(function (channel) {
PREVIOUS_VERSIONS[channel] = '0.0.0';
});
}
Menus._register({
type : 'separator',
contexts : ['all']
});
Menus._register({
title : TITLE,
contexts : ['all'],
onclick : function(info, tab) {
CHANNELS.forEach(function (channel) {
check(channel);
});
}
});
Menus.create();
function check(channel) {
request(URL + channel + '/version.txt?_=' + (new Date()).getTime()).then(function (res) {
var version = res.responseText;
var current_version = version.extract(/COREOS_VERSION=([\d.+-]+)/);
if (semver.gt(current_version, PREVIOUS_VERSIONS[channel])) {
TBRL.Notification.notify({
title : TITLE,
message : 'New ' + channel + ' Version ' + current_version + ' Released!',
onclick : function () {
window.open(URL + channel);
this.close();
}
});
} else {
TBRL.Notification.notify({
title : TITLE,
message : 'No New ' + channel + ' Version Released Yet',
timeout : 3,
onclick : function () {
this.close();
}
});
}
PREVIOUS_VERSIONS[channel] = current_version;
localStorage.setItem(KEY, JSON.stringify(PREVIOUS_VERSIONS));
});
}
CHANNELS.forEach(function (channel) {
check(channel);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment