Changeset 17865 for lang/javascript/userscripts
- Timestamp:
- 08/19/08 00:35:03 (3 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/userscripts/tophatenar_view.user.js
r17850 r17865 43 43 null), 44 44 r = []; 45 for (var i = 0;i < xp.snapshotLength;i++) 46 r.push(xp.snapshotItem(i)); 45 for (var i = 0, l = xp.snapshotLength; i < l; r.push(xp.snapshotItem(i++))); 47 46 return r; 48 47 } … … 62 61 left: 0px; 63 62 overflow: hidden; 64 Opacity: 0.85;65 min- Height: 20px;66 min- Width: 20px;67 max- Height: 400px;63 opacity: 0.85; 64 min-height: 20px; 65 min-width: 20px; 66 max-height: 400px; 68 67 padding: 2px; 69 68 -moz-border-radius: 0 8px 8px 0; … … 71 70 } 72 71 div#TopHatenar_view table.TopHatenar_view_table{ 73 color: #CCCCCC;74 font-size : 12px;75 font-weight : bold;76 border: none; 77 padding: 5px 10px; 78 margin : 10px 10px 10px 10px;79 background-color :#333333;80 border-collapse: collapse;72 color: #CCCCCC; 73 font-size: 12px; 74 font-weight: bold; 75 border: none; 76 padding: 5px 10px; 77 margin: 10px 10px 10px 10px; 78 background-color: #333333; 79 border-collapse: collapse; 81 80 } 82 81 div#TopHatenar_view table.TopHatenar_view_table td{ 83 padding : 0px 15px;84 background-color :#333333;85 white-space: nowrap; 86 border: 1px solid #CCCCCC;82 padding: 0px 15px; 83 background-color: #333333; 84 white-space: nowrap; 85 border: 1px solid #CCCCCC; 87 86 } 88 87 div#TopHatenar_view table.TopHatenar_view_table a{ 89 color: #CCCCCC;90 text-decoration: none;91 } 92 img:after {88 color: #CCCCCC; 89 text-decoration: none; 90 } 91 img:after{ 93 92 display: block; 94 content : "<" attr(title) ">";95 color: #CCCCCC;93 content: "<" attr(title) ">"; 94 color: #CCCCCC; 96 95 } 97 96 … … 99 98 100 99 101 function main() {100 function main() { 102 101 103 102 var element = document.createElement('div'); … … 109 108 } 110 109 var logo = document.createElement('div'); 111 with (logo){112 id = 'TopHatenar_view_logo';110 with (logo) { 111 id = 'TopHatenar_view_logo'; 113 112 innerHTML = "T?"; 114 113 with (style) { … … 121 120 } 122 121 } 123 element.appendChild( logo);124 122 element.appendChild(logo); 123 125 124 var content = document.createElement('div'); 126 with (content){127 id = 'TopHatenar_view_content';128 init_style(style);129 with (style) {130 display = 'none';131 margin = '7px 4px 4px 4px';132 width = '540px';133 134 }135 } 136 element.appendChild( content);137 125 with (content) { 126 id = 'TopHatenar_view_content'; 127 init_style(style); 128 with (style) { 129 display = 'none'; 130 margin = '7px 4px 4px 4px'; 131 width = '540px'; 132 133 } 134 } 135 element.appendChild(content); 136 138 137 document.body.appendChild(element); 139 138 } … … 141 140 function show_TopHatenar_view() { 142 141 143 if ( !already_got_chart) {142 if (!already_got_chart) { 144 143 get_TopHatenar_chart(); 145 144 } … … 147 146 var TopHatenar_view_logo = document.getElementById('TopHatenar_view_logo'); 148 147 TopHatenar_view_logo.style.display = 'none'; 149 148 150 149 var TopHatenar_view_elem = document.getElementById('TopHatenar_view_content'); 151 150 TopHatenar_view_elem.style.display = 'block'; … … 162 161 163 162 function get_TopHatenar_chart() { 164 163 165 164 var content = document.getElementById('TopHatenar_view_content'); 166 165 167 166 // HatenaIDを切り出す 168 var m = top.location.href.match(/d.hatena.ne.jp\/(\w+)(\/.*)?/);167 var m = /^http:\/\/d\.hatena\.ne\.jp\/([a-zA-Z][\w-]{1,30}[a-zA-Z\d])/.exec(top.location.href); 169 168 var hatena_id = m[1]; 170 169 171 170 var detail_url = 'http://tophatenar.com/view/' + hatena_id; // 詳細ページURL 172 171 173 172 // ID Link 174 173 var id_link = document.createElement('a'); 175 with (id_link){174 with (id_link) { 176 175 innerHTML = 'TopHatenar@' + hatena_id; 177 setAttribute('href', detail_url);178 setAttribute('title', 'クリックで詳細情報ページへ');179 with (style){176 setAttribute('href', detail_url); 177 setAttribute('title', 'クリックで詳細情報ページへ'); 178 with (style) { 180 179 fontSize = '20px'; 181 180 textAlign = 'center'; … … 187 186 } 188 187 content.appendChild(id_link); 189 188 190 189 // Ranking情報表示用 191 190 var id_info = document.createElement('div'); … … 194 193 // グラフを取得 195 194 var correlation_chart = document.createElement('img'); 196 with (correlation_chart){195 with (correlation_chart) { 197 196 src = 'http://tophatenar.com/chart/correlation_small/' + hatena_id; 198 197 title = "相関グラフ"; … … 204 203 correlation_chart_title.appendChild(correlation_chart); 205 204 content.appendChild(correlation_chart_title); 206 correlation_chart_title.innerHTML += "<p><相関グラフ></ P>";207 205 correlation_chart_title.innerHTML += "<p><相関グラフ></p>"; 206 208 207 var subscriber_chart = document.createElement('img'); 209 with (subscriber_chart){208 with (subscriber_chart) { 210 209 src = 'http://tophatenar.com/chart/subscriber_small/' + hatena_id; 211 210 title = "購読者数の推移"; 212 init_img_style(style); 211 init_img_style(style); 213 212 } 214 213 var subscriber_chart_title = document.createElement('div'); … … 216 215 subscriber_chart_title.style.textAlign = 'center'; 217 216 subscriber_chart_title.appendChild(subscriber_chart); 218 subscriber_chart_title.innerHTML += "< P><購読者数の推移></P>";217 subscriber_chart_title.innerHTML += "<p><購読者数の推移></p>"; 219 218 content.appendChild(subscriber_chart_title); 220 219 221 220 var bookmark_chart = document.createElement('img'); 222 with (bookmark_chart){221 with (bookmark_chart) { 223 222 src = 'http://tophatenar.com/chart/bookmark_small/' + hatena_id; 224 223 title = "ブックマーク数の推移"; 225 init_img_style(style); 224 init_img_style(style); 226 225 } 227 226 var bookmark_chart_title = document.createElement('div'); … … 230 229 bookmark_chart_title.appendChild(bookmark_chart); 231 230 content.appendChild(bookmark_chart_title); 232 bookmark_chart_title.innerHTML += "< P><ブックマーク数の推移></P>";233 231 bookmark_chart_title.innerHTML += "<p><ブックマーク数の推移></p>"; 232 234 233 // 詳細ページから情報取得 235 234 GM_xmlhttpRequest({ 236 235 method : 'GET', 237 236 url : detail_url, 238 onload : function (res) { 239 var html = res.responseText 240 var numbers = getTags( html , "div" , "number"); 241 var ranks = getTags( html , "div" , "rank"); 242 var percentiles = getTags( html , "div" , "percentile"); 243 244 for( n in numbers ) console.log( numbers[n] ); 245 for( n in ranks ) console.log( ranks[n] ); 246 for( n in percentiles ) console.log( percentiles[n] ); 247 248 249 subscriber_cnt = numbers[1].match(/\d+/gm); 250 subscriber_rank = ranks[0].match(/\d+/gm); 251 subscriber_percentile = percentiles[0].match(/(\d|\.)+/gm); 252 253 bookmark_cnt = numbers[2].match(/\d+/gm); 254 bookmark_rank = ranks[1].match(/\d+/gm); 255 bookmark_percentile = percentiles[1].match(/(\d|\.)+/gm); 256 257 258 console.log(subscriber_cnt ); 259 console.log(subscriber_rank ); 260 console.log(subscriber_percentile ); 261 console.log(bookmark_cnt ); 262 console.log(bookmark_rank ); 263 console.log(bookmark_percentile ); 264 265 266 237 onload : function(res) { 238 var html = res.responseText; 239 var numbers = getTags(html, "div", "number"); 240 var ranks = getTags(html, "div", "rank"); 241 var percentiles = getTags(html, "div", "percentile"); 242 243 [numbers, ranks, percentiles].forEach(function(n) n.forEach(console.log)); 244 245 246 var subscriber_cnt = numbers[1].match(/\d+/gm); 247 var subscriber_rank = ranks[0].match(/\d+/gm); 248 var subscriber_percentile = percentiles[0].match(/[\d.]+/gm); 249 250 var bookmark_cnt = numbers[2].match(/\d+/gm); 251 var bookmark_rank = ranks[1].match(/\d+/gm); 252 var bookmark_percentile = percentiles[1].match(/[\d.]+/gm); 253 254 255 console.log(subscriber_cnt ); 256 console.log(subscriber_rank ); 257 console.log(subscriber_percentile); 258 console.log(bookmark_cnt ); 259 console.log(bookmark_rank ); 260 console.log(bookmark_percentile ); 261 262 263 267 264 var inner = "<table class='TopHatenar_view_table'><tbody><tr>"; 268 265 inner += "<td>購読者数 : " + subscriber_cnt + "</td>"; … … 276 273 inner += "<td>(上位" +bookmark_percentile + "%以内) </td>"; 277 274 inner += "</tr></tbody></table>" 278 275 279 276 id_info.innerHTML += inner; 280 } ,277 } 281 278 }); 282 283 279 280 284 281 already_got_chart = true; 285 286 287 } 288 289 282 283 284 } 285 286 290 287 function init_style(style) { 291 with (style) {288 with (style) { 292 289 fontSize = '12px'; 293 290 textAlign = 'left'; … … 300 297 } 301 298 } 302 303 function init_img_style(style) {304 with (style){299 300 function init_img_style(style) { 301 with (style) { 305 302 border = '1px solid #CCCCCC'; 306 303 margin = '5px'; … … 309 306 } 310 307 } 311 312 function getTags(html, tagName, className) {308 309 function getTags(html, tagName, className) { 313 310 var cls = ""; 314 if (className){315 cls = " [^>]*?class=\"" + className + "\"";316 } 317 var reg = new RegExp("<" + tagName + cls + "( \\s|.)*?>([^<]*)</" + tagName + ">", "ig");311 if (className) { 312 cls = "(?:\\s[^>]*?)?\\sclass\\s*=\\s*([\"'])(?:(?:\\\\\\1|(?!\\1).)+?\\s+)?" + className + "(?:\\s+(?:\\\\\\1|(?!\\1).)+?)?\\1"; 313 } 314 var reg = new RegExp("<" + tagName + cls + "(?:\\s[^>]*)?>(?:(?!<" + tagName + "\\b)[\\s\\S])*?</" + tagName + "\\s*>", "ig"); 318 315 return html.match(reg); 319 316 } 320 317 321 318 main(); 322 319 323 320 })();
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)