Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
adds Chrome version support. introduce findBrowserVersion for ease of…
Browse files Browse the repository at this point in the history
… maintenance. closes #4
  • Loading branch information
myakura committed May 5, 2012
1 parent 9f4a65f commit 8155fa4
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 21 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Dicentra",
"version": "0.4.1",
"version": "0.5",
"description": "enhances WebKit changeset page.",
"manifest_version": 2,

Expand Down
99 changes: 79 additions & 20 deletions wkversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

/**
* Canonicalizes the version string by zero-padding for making it easier in comparison.
* @param {(Array.<string>|string)} version WebKit Version string
* @param {(Array.<string>|string)} version WebKit version string
* @return {string} canonicalized version string; zero-pads if necessary
*/
var canonicalizeWebKitVersion = function (version) {
Expand All @@ -79,47 +79,106 @@
};

/**
* Returns the Safari version number in which feature might be available with the associated WebKit Version
* @param {string} version canonicalized version string
* @return {string} the Safari version number in which feature might be available with the associated WebKit Version
* Returns the earliest version of a browser that (might) support the feature on the changeset
* @param {browser} browser an array contains objects of product and webkit version numbers
* @param {string} version WebKit version string
* @return {string} a browser version number
*/
var findSafariVersion = function (version) {
var findBrowserVersion = function (browser, version) {

if (!Array.isArray(browser) || browser.length === 0) {
console.error('Invalid argument: ', browser);
return;
}

if (!('product' in browser[0]) || !('webkit' in browser[0])) {
console.error('Invalid argument: ', browser[0]);
return;
}

version = canonicalizeWebKitVersion(version);

var safari = [
{ "product": "5.1", "webkit" : "534.55.3" },
{ "product": "5.0", "webkit" : "534.22.3" },
{ "product": "4.1", "webkit" : "533.19.4" },
{ "product": "4.0", "webkit" : "531.22.7" },
{ "product": "3.2", "webkit" : "525.28" },
{ "product": "3.1", "webkit" : "525.21" },
{ "product": "3.0", "webkit" : "523.10" }
];
var i = 0,
l = safari.length,
l = browser.length,
candidate;

if (version > safari[0].webkit) { return 'Nightly'; }
if (version < safari[l-1].webkit) { return ''; }
if (version > browser[0].webkit) { return 'Nightly'; }
if (version < browser[l-1].webkit) { return ''; }

while (i < l) {
if (version <= safari[i].webkit) {
if (version <= browser[i].webkit) {
candidate = i;
} else {
return safari[candidate].product;
return browser[candidate].product;
}
i++;
}
};

/**
* Returns the earliest Safari version that (might) support the feature on the changeset
* @param {string} version canonicalized version string
* @return {string} Safari version number
*/
var findSafariVersion = function (version) {

var safari = [
{ "product": "5.1", "webkit": "534.55.3" },
{ "product": "5.0", "webkit": "534.22.3" },
{ "product": "4.1", "webkit": "533.19.4" },
{ "product": "4.0", "webkit": "531.22.7" },
{ "product": "3.2", "webkit": "525.28" },
{ "product": "3.1", "webkit": "525.21" },
{ "product": "3.0", "webkit": "523.10" }
];

return findBrowserVersion(safari, version);
};

/**
* Returns the earliest Chrome version that (might) support the feature on the changeset
* @param {string} version canonicalized version string
* @return {string} Chrome version number
*/
var findChromeVersion = function (version) {

var chrome = [
{ "product": "20", "branch": "1123", "webkit": "536.10" },
{ "product": "19", "branch": "1084", "webkit": "536.5" },
{ "product": "18", "branch": "1025", "webkit": "535.19" },
{ "product": "17", "branch": "963", "webkit": "535.11" },
{ "product": "16", "branch": "912", "webkit": "535.7" },
{ "product": "15", "branch": "874", "webkit": "535.2" },
{ "product": "13/14", "branch": "835", "webkit": "535.1" },
/* TODO: find a way to differentiate Cr13 and Cr14
{ "product": "14", "branch": "835", "webkit": "535.1" },
{ "product": "13", "branch": "782", "webkit": "535.1" },
*/
{ "product": "12", "branch": "742", "webkit": "534.30" },
{ "product": "11", "branch": "696", "webkit": "534.24" },
{ "product": "10", "branch": "648", "webkit": "534.16" },
{ "product": "9", "branch": "597", "webkit": "534.13" },
{ "product": "8", "branch": "552", "webkit": "534.10" },
{ "product": "7", "branch": "517", "webkit": "534.7" },
{ "product": "6", "branch": "472", "webkit": "534.3" },
{ "product": "5", "branch": "375", "webkit": "533.4" },
{ "product": "4", "branch": "249", "webkit": "532.5" },
{ "product": "3", "branch": "195", "webkit": "532.0" },
{ "product": "2", "branch": "172", "webkit": "530.5" },
{ "product": "1", "branch": "154", "webkit": "525.19" },
];

return findBrowserVersion(chrome, version);
};

/**
* Adds corresponding WebKit version to the changeset heading.
* @param {string} version WebKit version string
*/
var updateChangesetHeading = function (version) {
var safariVersion = findSafariVersion(version);
document.querySelector('h1').textContent += ' (' + version + ' / Safari ' + safariVersion + ')';
var chromeVersion = findChromeVersion(version);
document.querySelector('h1').textContent += ' (' + version + ' | Safari ' + safariVersion + ' | Chrome ' + chromeVersion + ')';
};


Expand Down

0 comments on commit 8155fa4

Please sign in to comment.