Created
March 1, 2009 14:01
-
-
Save kiy0taka/72335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name HudsonTerminal | |
// @namespace http://d.hatena.ne.jp/kiy0taka/ | |
// @include http://*/script | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js | |
// @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.2/jquery-ui.min.js | |
// ==/UserScript== | |
function xpath(query, contextNode) { | |
contextNode = contextNode || document; | |
var snapshot = document.evaluate( | |
query, | |
contextNode, | |
null, | |
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, | |
null); | |
var result = []; | |
for (var i=0,n=snapshot.snapshotLength; i<n; i++) { | |
result.push(snapshot.snapshotItem(i)); | |
} | |
return result; | |
} | |
function dom(text) { | |
var tmp = document.createElement('div'); | |
tmp.innerHTML = text; | |
return tmp.childNodes[0]; | |
} | |
GM_addStyle(<><![CDATA[ | |
.hudsonterminal { | |
position: absolute; | |
top: 100px; | |
left: 100px; | |
} | |
.hudsonterminal .titleBar { | |
width: 100%; | |
text-align: center; | |
padding: 3px 0px 3px 0px; | |
font-size: 14px; | |
background-color: gray; | |
color: white; | |
} | |
.hudsonterminal .console { | |
background-color: black; | |
-moz-opacity: 0.80; | |
color: white; | |
font-size: 14px; | |
overflow: auto; | |
width: 800px; | |
height: 400px; | |
padding: 0px 0px 0px 5px; | |
} | |
.hudsonterminal .console input { | |
background-color: black; | |
color: white; | |
font-size: 14px; | |
width: 700px; | |
border: 0px; | |
} | |
.hudsonterminal .console pre { | |
padding: 0px 0px 0px 2px; | |
margin: 0px; | |
} | |
]]></>) | |
function Terminal() { | |
var titleBar = $('<div class="titleBar">Hudson Terminal</div>') | |
this.console = $('<div>').attr('class', 'console') | |
$('<div class="hudsonterminal"/>').append(titleBar).append(this.console).appendTo(document.body) | |
/* | |
.draggable({ | |
'handle' : titleBar, | |
'cursor' : 'move' | |
}) | |
*/ | |
this.newLine(); | |
} | |
Terminal.prototype = { | |
newLine : function(val) { | |
var self = this; | |
var input = $('<input type="text"/>').val(val || '').keydown(function(e) { | |
if (e.keyCode == 13) { | |
input.after($('<span/>').text(input.val())) | |
input.remove(); | |
self.exec(input.val()) | |
} else if (e.ctrlKey && e.keyCode == 76) { | |
self.console.children().remove(); | |
self.newLine(input.val()) | |
} | |
}); | |
this.console.append($('<div/>') | |
.append('<span style="padding-right:5px">hudson></span>') | |
.append(input) | |
) | |
input.focus(); | |
}, | |
exec : function(command) { | |
var self = this; | |
if (!(command || '').replace(/^[ ]+|[ ]+$/g, '')) { | |
self.newLine(); | |
return; | |
} | |
GM_xmlhttpRequest({ | |
'method' : 'POST', | |
'headers' : {'Content-type': 'application/x-www-form-urlencoded'}, | |
'url' : location.href, | |
'data' : 'script=' + encodeURIComponent('println(("""' + command.split(/[^\\]\|/).join('""".execute() | """') + '""".execute()).text)'), | |
'onload' : function(res) { | |
self.console.append($(xpath('//pre', dom(res.responseText))[1])) | |
self.newLine(); | |
} | |
}) | |
} | |
} | |
$(function() { | |
new Terminal(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment