Skip to content

Commit

Permalink
改版升级
Browse files Browse the repository at this point in the history
  • Loading branch information
52cik committed Feb 4, 2016
1 parent 0f57bd4 commit f311a49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
1 change: 0 additions & 1 deletion locals.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ I18N.zh = {
"Current streak": "当前连续贡献天数",

"commits": " 次提交 ",

"Pull Requests": " 合并请求",
"Issues reported": " 问题报告",

Expand Down
24 changes: 11 additions & 13 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,27 @@
// @grant none
// ==/UserScript==

(function () {
(function (document) {
'use strict';

var body = document.body;

// 要翻译的页面正则
var rePage = /\b(vis-public|page-(dashboard|profile|account)|homepage|signup|session-authentication)\b/;
var page = document.body.className.match(rePage);

var page = body.className.match(rePage);
page = page ? page[1] : false;

walk(document.body); // 立即翻译
walk(body); // 立即翻译

$(document).ajaxComplete(function() {
walk(document.body); // ajax 请求后再次翻译
walk(body); // ajax 请求后再次翻译
});

function walk(node) {
var nodes = node.childNodes;
var nodes, i, len, el, attr;
nodes = node.childNodes;

var i = 0;
var len = nodes.length;
var el = null; // 遍历元素用
var attr; // 元素属性

for (; i < len; i++) {
for (i = 0, len = nodes.length; i < len; i++) {
el = nodes[i];

if (el.nodeType === 1) {
Expand Down Expand Up @@ -75,6 +72,7 @@

function transPage(page, key) {
var str, res, len, i;

// 静态翻译
str = I18N['zh'][page]['static'][key];
if (str) { return str; }
Expand All @@ -90,4 +88,4 @@
return key;
}

})();
})(document);

0 comments on commit f311a49

Please sign in to comment.