これは何か
pylonshq の文書を翻訳する際に、ページをコピーする権限がない場合は Info > View Source から原文を取得しますが、 ブラウザに表示されるソースをそのままコピーしようとするとインデントが消えてしまったり、 かといって HTML のソースでは HTML の実体参照を置換しなければならなかったりして、余計な手間がかかります。
これは、そんな手間を軽減するための Greasemonkey スクリプトです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | // ==UserScript== // @name Pylonsdoc View Source // @namespace http://wiki.pylonshq.com/display/~knzm/Home // @include http://wiki.pylonshq.com/display/* // @include http://wiki.pylonshq.com/pages/viewpage.action* // ==/UserScript== (function(){ function getElementsByXPath(xpath, doc, context) { if (doc == null) doc = document; if (context == null) context = doc; var it = doc.evaluate(xpath, context, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); var nodes = new Array(); var node; while ((node = it.iterateNext()) != null) { nodes.push(node); } return nodes; } function onViewSourceClicked(ev) { GM_xmlhttpRequest({ method: 'GET', url: ev.target.href, onload: function(req) { if (req.responseText.match('<div class="padded">[ \n\r]*((?:.|[\r\n])*?)[ \n\r]*</div>')) { var text = RegExp.$1; var win = window.open('', null); win.document.open(); win.document.write('<pre>'); win.document.write(text.replace(/[\r\n]<br>/g, "\n")); win.document.write('</pre>'); win.document.close(); } }, }); ev.preventDefault(); return; } var info = getElementsByXPath("//a[@accesskey='i']")[0]; if (info && info.href.match(/\?pageId=(\d+)/)) { var pageId = RegExp.$1; var a = document.createElement("a"); a.href = 'http://wiki.pylonshq.com/pages/viewpagesrc.action?pageId=' + pageId; // a.target = '_blank'; a.addEventListener('click', onViewSourceClicked, false); a.appendChild(document.createTextNode("View source")); var form = getElementsByXPath("//td[@class='pagecontent']/table//tr[position()=1]//td[position()=1]//form")[0]; if (form != null) { form.parentNode.insertBefore(a, form); } } })() |
使い方
インストール後、pylonshq の Wiki ページを表示すると、ページの上部に"View source"というリンクが追加されています。 このリンクをクリックすると、別ウィンドウにそのページのソースコードが表示されます。
Comments (9)
Dec 04, 2010
Anonymous says:
When you can feel the things you,coach stores want to feel able to say what you ...When you can feel the things you,coach stores want to feel able to say what you feel when this is a very happy time.
Dec 06, 2010
Anonymous says:
cheap jordans Nothing can make me so crazycheap jordans Nothing can make me so crazy
Dec 06, 2010
Anonymous says:
A beautiful day began, the purpose for it! coach outletA beautiful day began, the purpose for it! coach outlet
Dec 06, 2010
Anonymous says:
coach factory stores. That is too cool! thanks.*coach factory stores. That is too cool! thanks.*
Dec 06, 2010
Anonymous says:
air jordans Nothing can make me so crazyair jordans Nothing can make me so crazy
Dec 06, 2010
Anonymous says:
This site is being spammed out of oblivion.This site is being spammed out of oblivion.
Dec 08, 2010
Anonymous says:
Large selection of premium <a href="http://www.algozone.com">ecommerce tem...Large selection of premium <a href="http://www.algozone.com">ecommerce templates</a> and designs with variety of themes, layouts and features to comply with latest technologies and standards in Ecommerce industry. Add professional touch to your ecommerce store front.
Dec 08, 2010
Anonymous says:
http://www.algozone.comhttp://www.algozone.com
Jan 08, 2011
Anonymous says:
We realize the true worth of happiness when we are in sorrow` http://www.trjea...We realize the true worth of happiness when we are in sorrow` http://www.trjeansoutlet.com
Add Comment