node-webkitã§Node.jsãããããªãã¨ã«ä½¿ã
node-webkitã¨ã¯
æ¥æ¬ã§ã¯ãã¾ãnode-webkitã¯ç¥å度ãé«ããªãããç°¡åã«è¨ãã¨Intelãéçºã«é¢ãã£ã¦ãããnodeã¨WebKitãçµ±åããDOMã³ã³ããã¹ãä¸ã§node.jsã®æ©è½ã使ããããã«ããã½ããã¦ã§ã¢ãä¸è¨ã§ããã¨è¨ãã¨ãã¦ã§ãã§node.jsãåãããã©ãããã©ã¼ã ã
ä½ãã§ããã®ã
node.jsã§åºæ¥ããã¨ã¨ãã¦ã§ãã§åºæ¥ããã¨ã¨ãnode-webkitãç¨æãã¦ããæ©è½ï¼GUIã®æä½ãªã©ï¼ã使ããã
ä¾ãã°/etc/hostsãèªã¿è¾¼ãå ´å
node-webkitã¨åä¸ã®ãã£ã¬ã¯ããªã«ä¸è¨ã®ãããªindex.htmlãç¨æãã¦
<!doctype html> <html> <body> <pre id="hosts"></pre> </body> <script> var fs = require('fs'); fs.readFile('/etc/hosts', function (error, file) { if (error) { alert('Loading /etc/hosts failed :('); } else { document.querySelector('#hosts').textContent = file.toString(); } }); </script> </html>
package.jsonããã®ããã«æ¸ãã ãã§ããã
{ "name": "hosts viewer", "main": "index.html" }
Node.jsã®ãããã®ã³ã°ãã¼ã«ã¨ãã¦
èªåçã«ä¸çªãã°ããããªã¨æã£ã¦ããã®ã¯ãWeb Inspectorãªã©ã®ããããã¬ãåãã¨ããã§ãããä¿¡é ¼æ§ãå¿é ãªnode.jsã®ã¢ã¸ã¥ã¼ã«ã¨ç°ãªããSafariä¸ã§ä½¿ã£ã¦ããæ©è½ã¯å ¨ã¦åããã¹ãããå®è¡ããã¬ã¤ã¯ãã¤ã³ããã³ã¼ã«ã¹ã¿ãã¯ãªã©ãè¦ããã¾ã ã³ã³ã½ã¼ã«ããrequire('fs')ãªã©ã¨å ¥åãã¦ããªãã¸ã§ã¯ããã¯ãªãã¯ãã¦ãã©ã£ã¦ããã¡ã½ãããããããã£ãªã©ãè¦ããã¨ã容æã§ããã
æ®éã®node.jsã¨ã¯å®è¡ç°å¢ãå¤å°ç°ãªãããnode.jsã§åãã¢ã¸ã¥ã¼ã«ã¯å ¨ã¦node-webkitã§ãåããã¨ãç®æãã¦ä½ããã¦ããã®ã§ãnode-webkitã«é¢ä¿ã®ãªãæ®éã®node.jséçºã§ãå©ç¨ã§ãã便å©ãªã®ã§èªåã¯åä½ç¢ºèªã«ãã使ã£ã¦ããã
ãã¹ã¯ãããçGreasemonkey/ã¹ã¯ã¬ã¤ãã³ã°ãã¼ã«ã¨ãã¦
XMLHttpRequestãiframeã®same-origin policyãªã©ãè¶ ããããã®ã§ãä¾ãã°è¤éãªãµã¤ããiframeå ã«èªã¿è¾¼ãã§ããµã¤ãå´ã®JSå®è¡ãçµãã£ãå¾ã«DOMã«ã¢ã¯ã»ã¹ãã¦ããã¼ã¿ãåãåºãã¦æ¸ãåºããããããã¨ãã§ããã èªåã®ãã½ã³ã³å ã§å®è¡ããã¡ãã£ã¨ããèªååãã¼ã«ã¨ãã¦ãnode-webkitã¯ããªãåªç§ã§ããã
ææ³
ã¡ãã£ã¨ãããã®ãä½ãã¨ãã«é常ã«ä¾¿å©ã§ã次ä¸ä»£ã®Greasemonkeyã®ãããªãhackableãªæããã¨ã¦ãã¯ã¯ã¯ã¯ãããã使ã£ã¦ã¿ãã¨ããã¨æã