Changeset 5156
- Timestamp:
- 01/21/08 10:44:25 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/userscripts/gen1986.addacountinfo.user.js
r5146 r5156 23 23 http.get("http://generation1986.g.hatena.ne.jp/keyword/Twitter").next(genParser(function (t) { 24 24 t = t.replace("@", ""); 25 return h("<a href='http://twitter.com/"+t+"'>@"+t+"</a>").firstChild;25 return $N("<a href='http://twitter.com/"+t+"'>@"+t+"</a>"); 26 26 })), 27 27 Skype : 28 28 http.get("http://generation1986.g.hatena.ne.jp/keyword/Skype").next(genParser(function (t) { 29 return h("<a href='skype:"+t+"?add'>"+t+"</a>").firstChild;29 return $N("<a href='skype:"+t+"?add'>"+t+"</a>"); 30 30 })) 31 31 }; … … 38 38 console.log(r); 39 39 for (var service in services) if (services.hasOwnProperty(service)) { 40 var th = document.createElement("th"); 41 th.appendChild(document.createTextNode(service)); 42 htr.appendChild(th); 40 htr.appendChild($N("<th>"+service+"</th>")); 43 41 44 42 users.forEach(function (tr) { 45 43 var id = $X("string(./td[contains(., 'id:')])", tr).match(/id:(\S+)/)[1]; 46 44 47 var td = document.createElement("td");48 td.appendChild(r[service][id] || document.createTextNode("---"));45 var td = $N("<td/>") 46 td.appendChild(r[service][id] || $N("---")); 49 47 tr.appendChild(td); 50 48 }); … … 63 61 return d; 64 62 } 63 64 function $N (str) { 65 var t, cur, stack = [cur = document.createDocumentFragment()]; 66 while (str.length) { 67 if (str.indexOf("<") == 0) { 68 if (t = str.match(/^\s*<(\/?[^\s>\/]+)([^>]+?)?(\/)?>/)) { 69 var tag = t[1], attrs = t[2], isempty = !!t[3]; 70 if (tag.indexOf("/") == -1) { 71 child = document.createElement(tag); 72 if (attrs) attrs.replace(/([a-z]+)=(?:'([^']+)'|"([^"]+)")/gi, 73 function (m, name, v1, v2) { 74 child.setAttribute(name, v1 || v2); 75 } 76 ); 77 cur.appendChild(child); 78 if (!isempty) { 79 stack.push(cur); 80 cur = child; 81 } 82 } else cur = stack.pop(); 83 } else throw("Parse Error: " + str); 84 } else { 85 if (t = str.match(/^([^<]+)/)) cur.appendChild(document.createTextNode(t[0])); 86 } 87 str = str.substring(t[0].length); 88 } 89 var ret = stack.pop(); 90 return ret.childNodes.length == 1 ? ret.firstChild : ret; 91 } 92 65 93 66 94 function log (m) { … … 77 105 location.href = "javascript:(function () { if (window.console) console.log.apply(console.log, "+o.toSource()+") })();"; 78 106 } 79 }80 81 function $N(name, attr, childs) {82 var ret = document.createElement(name);83 for (k in attr) {84 if (!attr.hasOwnProperty(k)) continue;85 v = attr[k];86 if (k == "class") {87 ret.className = v;88 } else {89 ret.setAttribute(k, v);90 }91 }92 switch (typeof childs) {93 case "string": {94 ret.appendChild(document.createTextNode(childs));95 break;96 }97 case "object": {98 for (var i = 0, len = childs.length; i < len; i++) {99 var child = childs[i];100 if (typeof child == "string") {101 ret.appendChild(document.createTextNode(child));102 } else {103 ret.appendChild(child);104 }105 }106 break;107 }108 }109 return ret;110 107 } 111 108
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)