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

Commit

Permalink
support for showing the earliest Safari version that (might) ships wi…
Browse files Browse the repository at this point in the history
…th the feature landed on the changeset. closes #3
  • Loading branch information
myakura committed May 2, 2012
1 parent bd51c93 commit e647d4d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion manifest.json
@@ -1,6 +1,6 @@
{ {
"name": "Dicentra", "name": "Dicentra",
"version": "0.3.3", "version": "0.4",
"description": "enhances WebKit changeset page.", "description": "enhances WebKit changeset page.",
"manifest_version": 2, "manifest_version": 2,


Expand Down
58 changes: 57 additions & 1 deletion wkversion.js
Expand Up @@ -55,12 +55,68 @@
xhr.send(); xhr.send();
}; };


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

if (Array.isArray(version) && version.length >= 2) {
version = version.join('.');
}

var regVersion = /^(\d{3})\.(\d{1,2})\.?\d*$/;
if (typeof version === 'string' && regVersion.test(version)) {
return version.replace(regVersion, function(m, p1, p2) {
return p1 + '.' + (p2.length === 2 ? p2 : '0' + p2);
});
} else {
console.error('Invalid argument: ', version);
return;
}
};

/**
* 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
*/
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" },
];
var i = 0,
l = safari.length,
candidate;

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

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

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




Expand Down

0 comments on commit e647d4d

Please sign in to comment.