Created
March 10, 2009 14:30
-
-
Save ucnv/76905 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 Diff for AppJet IDE | |
// @description Provides the view of unified diff between published app and saved one. | |
// @namespace http://userscripts.org/users/40991 | |
// @include http://appjet.com/app/*/ide | |
// @require http://svn.coderepos.org/share/lang/javascript/jsdeferred/trunk/jsdeferred.userscript.js | |
// @require http://gist.github.com/105908.txt | |
// ==/UserScript== | |
// thanks to jsdeferred by cho45 | |
(function() { | |
if(window != window.parent) return; | |
var $ = unsafeWindow.jQuery; | |
var urlbase = location.href.replace('/ide', ''); | |
$('#publishpane').append( | |
<div id="diff-pane" class="panebox"> | |
<input id="diff-button" type="button" name="diff-button" value=" Diff " /> | |
<pre id="diff-view"> </pre> | |
</div>.toXMLString() | |
); | |
$('#diff-button').bind('click', function() {with(D()) { | |
parallel([ | |
xhttp.get(urlbase + '/source?plaintext=1'), // published | |
xhttp.get(urlbase + '/rawcode') // current | |
]).next(function (res) { | |
if(res[0].responseText == res[1].responseText) | |
return $('#diff-view').empty().append('No difference.').show(); | |
var udiff = new UnifiedDiff(res[0].responseText, res[1].responseText, 3).toString(); | |
if(udiff.split(/\n/).length < 5000) { | |
udiff = udiff.replace(/^(\+.*)$/mg, '<span class="diff-plus">$1</span>'); | |
udiff = udiff.replace(/^(\-.*)$/mg, '<span class="diff-minus">$1</span>'); | |
} | |
$('#diff-view').empty().append(udiff) | |
.css('width', Math.floor(window.innerWidth / 10 * 4.3) + 'px') | |
.show(); | |
}); | |
}}); | |
GM_addStyle(<><![CDATA[ | |
#diff-view { | |
display: none; | |
overflow: auto; | |
font-family: 'Bitstream Vera Sans Mono','Courier',monospace; | |
line-height: 1.3; | |
background-color: #f5f5ff; | |
padding: .5em; | |
margin: .5em; | |
} | |
.diff-plus { | |
background-color: #fdd; | |
} | |
.diff-minus { | |
background-color: #dfd; | |
} | |
]]></>); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment