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

Commit

Permalink
Tumblrのアカウント切り替えでhttpsも可能にするTomblooパッチ。
Browse files Browse the repository at this point in the history
 - http と https のアカウントを融合してソートする動作に
  • Loading branch information
polygonplanet committed Apr 1, 2012
1 parent 514f1d6 commit 21368be
Showing 1 changed file with 68 additions and 15 deletions.
83 changes: 68 additions & 15 deletions tombloo.model.tumblr.changeaccount.https.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,84 @@
*
* --------------------------------------------------------------------------
*
* @version 1.02
* @date 2012-02-17
* @author polygon planet <polygon.planet@gmail.com>
* - Blog : http://polygon-planet.blogspot.com/
* @version 1.04
* @date 2012-04-01
* @author polygon planet <polygon.planet.aqua@gmail.com>
* - Twitter : http://twitter.com/polygon_planet
* - Tumblr : http://polygonplanet.tumblr.com/
* @license Same as Tombloo
* @updateURL https://github.com/polygonplanet/tombloo/raw/master/tombloo.model.tumblr.changeaccount.https.js
*
* Tombloo: https://github.com/to/tombloo/wiki
*/
(function() {

update(Tumblr, {
getPasswords : function() {
let ok = true, infos = getPasswords('http://www.tumblr.com');
if (!infos || !infos.length) {
ok = false;
} else {
infos.forEach(function(info) {
if (!info || !info.user || !info.password) {
ok = false;
let results = [];
['http://www.tumblr.com', 'https://www.tumblr.com'].forEach(function(url) {
let users = getPasswords(url);
if (!users || !users.length) {
users = [];
}
try {
users.forEach(function(info) {
let add = false;
if (info && info.user != null && info.password != null) {
if (results.length === 0) {
add = true;
} else {
add = !results.some(function(o) {
return o.user === info.user && o.password === info.password;
});
}
if (add) {
results[results.length] = info;
}
}
});
} catch (e) {}
});
return alphanumSort(results);
}
});

// http://www.davekoelle.com/alphanum.html
var alphanumSort = (function() {
function chunkify(t) {
var tz = [], x = 0, y = -1, n = 0, i, j, m;
while ((i = (j = t.charAt(x++)).charCodeAt(0))) {
m = (i == 46 || (i >= 48 && i <= 57));
if (m !== n) {
tz[++y] = '';
n = m;
}
tz[y] += j;
}
return tz;
}

function alphanumCase(a, b) {
var aa, bb, c, d, i;
aa = chunkify(a.user.toLowerCase());
bb = chunkify(b.user.toLowerCase());
for (i = 0; (aa[i] && bb[i]); i++) {
if (aa[i] !== bb[i]) {
c = +aa[i];
d = +bb[i];
if (c == aa[i] && d == bb[i]) {
return c - d;
} else {
return (aa[i] > bb[i]) ? 1 : -1;
}
});
}
}
return ok ? infos : getPasswords('https://www.tumblr.com');
return aa.length - bb.length;
}
});

return function(array) {
array.sort(alphanumCase);
return array;
};
}());

}());

0 comments on commit 21368be

Please sign in to comment.