Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fkling committed Dec 6, 2011
0 parents commit 5b77876
Show file tree
Hide file tree
Showing 9 changed files with 574 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jQuery/
CodeMirror/
88 changes: 88 additions & 0 deletions archive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<html>
<head>
<title>Codepad for Chrome - History</title>
<script src="CodeMirror/js/highlight.js" type="text/javascript"></script>
<script src="CodeMirror/js/stringstream.js" type="text/javascript"></script>
<script src="CodeMirror/js/tokenize.js" type="text/javascript"></script>
<script src="jquery/jquery.min.js"></script>
<script src="jquery/jquery.timeago.js"></script>
<script src="history.js"></script>
<script type="text/javascript" src="CodeMirror/js/parsedummy.js"></script><script type="text/javascript" src="CodeMirror/js/parsecss.js"></script><script type="text/javascript" src="CodeMirror/js/tokenizejavascript.js"></script><script type="text/javascript" src="CodeMirror/js/parsejavascript.js"></script><script type="text/javascript" src="CodeMirror/js/parsexml.js"></script><script type="text/javascript" src="CodeMirror/js/parsepython.js"></script><script type="text/javascript" src="CodeMirror/js/parsehtmlmixed.js"></script><script type="text/javascript" src="CodeMirror/js/tokenizescheme.js"></script><script type="text/javascript" src="CodeMirror/js/parsescheme.js"></script><script type="text/javascript" src="CodeMirror/js/tokenizephp.js"></script><script type="text/javascript" src="CodeMirror/js/parsephp.js"></script><script type="text/javascript" src="CodeMirror/js/parsephphtmlmixed.js"></script><link rel="stylesheet" type="text/css" href="CodeMirror/css/csscolors.css"><link rel="stylesheet" type="text/css" href="CodeMirror/css/jscolors.css"><link rel="stylesheet" type="text/css" href="CodeMirror/css/phpcolors.css"><link rel="stylesheet" type="text/css" href="CodeMirror/css/pythoncolors.css"><link rel="stylesheet" type="text/css" href="CodeMirror/css/xmlcolors.css"><link rel="stylesheet" type="text/css" href="CodeMirror/css/schemecolors.css">
<style>
body {
font-family: sans-serif;
font-size: 12px;
}
.snippet {
margin-left: 20px;
margin-right: 20px;
position: relative;
border-bottom: 1px solid black;
padding: 10px;
margin-bottom: 10px;
}
.date {
font-style: italic;
}
.lang {
font-weight: bold;
}
.code {
font-family: monospace;
background-color: #EEE;
border: 1px dotted black;
padding: 10px;
}
.output {
background-color: #FFFDC2;
padding: 10px;
margin-top: 10px;

}
.link {
font-size: 12px;
}
.action {
vertical-align: center;
text-align: center;
}
.delete {
font-weight: bold;
color: red;
cursor: pointer;
}
.edit {
font-weight: bold;
color: green;
cursor: pointer;
display: inline-block;
margin-left: 10px;
}
.action {
position: absolute;
top:-5px;
left:0;
display: none;
font-size: 22px;
}
.snippet:hover .action {
display: block;
}
.header {
font-size: 16px;
}

</style>


</head>

<body>
<h1>Codepad for Chrome - History</h1>
<div id="items">
</div>
<div>
<a href="#" onclick="chrome.extension.getBackgroundPage().history.dropTable(function(){});$('#items').empty()">Remove all snippets</a>
</div>
</body>
</html>
102 changes: 102 additions & 0 deletions background.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<script>
window.history = {};
history.db = null;

history.open = function() {
var dbSize = 5 * 1024 * 1024; // 5MB
history.db = openDatabase('History', '1.0', 'history', dbSize);
}

history.onError = function(tx, e) {
console.log('Something unexpected happened: ' + e.message );
}

history.onSuccess = function(tx, r) {
}

history.createTable = function() {
history.db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS ' +
'history(ID INTEGER PRIMARY KEY ASC, code TEXT, link TEXT, output TEXT, lang TEXT, time INTEGER)', []);
});
}

history.addItem = function(item, success, error) {
history.db.transaction(function(tx){
var addedOn = (new Date()).getTime();
tx.executeSql('INSERT INTO history(code, link, output, lang, time) VALUES (?,?,?,?,?)',
[item.code,item.link,item.output,item.lang,addedOn],
(success || history.onSuccess),
(error || history.onError));
});
}

history.getAllItems = function(renderFunc) {
history.db.transaction(function(tx) {
tx.executeSql('SELECT * FROM history ORDER BY time DESC', [], renderFunc,
history.onError);
});
}

history.deleteItem = function(id, cb) {
history.db.transaction(function(tx) {
tx.executeSql('DELETE FROM history WHERE ID=?', [id],
cb , history.onError);
});
}

history.dropTable = function(succ, err) {
history.db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS history', [], function() {history.createTable();succ();}, history.onError);
});
}


history.open();
history.createTable();

CodeSnippet = {
db: history,
dirty: false,
get code() {
return sessionStorage.getItem('code');
},
set code(code) {
if(code != this.code) {
sessionStorage.setItem('code', code);
this.dirty = true;
}
},
get output() {
return sessionStorage.getItem('output');
},
set output(output) {
if(this.output != output) {
sessionStorage.setItem('output', output);
this.dirty = true;
}
},
get lang() {
return sessionStorage.getItem('lang');
},
set lang(lang) {
sessionStorage.setItem('lang', lang);
},
get link() {
return sessionStorage.getItem('link');
},
set link(link) {
sessionStorage.setItem('link', link);
},
clear : function() {
sessionStorage.clear();
},
save: function() {
if(this.link && this.dirty) {
this.db.addItem(this);
this.dirty = false;
}
}
};

</script>
77 changes: 77 additions & 0 deletions history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
var path = "CodeMirror/js/";
var parsers = ["parsedummy.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js", "parsexml.js",
"parsepython.js", "parsehtmlmixed.js", "tokenizescheme.js", "parsescheme.js", "tokenizephp.js", "parsephp.js", "parsephphtmlmixed.js"];

var stylesheets = ["CodeMirror/css/csscolors.css", "CodeMirror/css/jscolors.css", "CodeMirror/css/phpcolors.css", "CodeMirror/css/pythoncolors.css", "CodeMirror/css/xmlcolors.css", "CodeMirror/css/schemecolors.css"];


var parserConfig;

$(function() {
loadItems();
});

function loadItems() {
$('#items').empty();
chrome.extension.getBackgroundPage().history.getAllItems(function(tx, rs) {
parserConfig = {
'PHP': PHPHTMLMixedParser,
'Python': PythonParser,
'Scheme': SchemeParser,
'default': DummyParser
};

var rowOutput = [];
var rows = rs.rows;
var history = $('#items');
for (var i=0; i < rows.length; i++) {
history.append(renderItem(rows.item(i)));
}

});

}


function renderItem(item) {
var row = $('<div class="snippet"/>');
row.append('<p class="header"><span class="lang">' + item.lang + '</span>, <span class="date">' + $.timeago(new Date(item.time)) +'</span></p>');
row.append('<div><span class="label">Code:</span> <pre class="code"/></div>');
var parser = (parserConfig[item.lang] || parserConfig['default']);
highlightText(item.code, row.find('> :last pre')[0], parser);
row.append('<div><span class="label">Output:</span><pre class="output">' + item.output + '</pre></div>');
row.append('<div class="link"><a href="' + item.link+ '">' + item.link + '</a></div>');
row.append('<div class="action"/>');
$('<span class="delete" title="delete">X</span>').bind('click', {item: item, row: row}, function(event) {
chrome.extension.getBackgroundPage().history.deleteItem(event.data.item.ID, function() {
event.data.row.remove();
});
}).appendTo(row.children(':last'));
$('<span class="edit" title="edit">&#8634;</span>').bind('click', {item: item, row: row}, function(event) {
var s = chrome.extension.getBackgroundPage().CodeSnippet;
s.clear();
s.code = item.code;
s.lang = item.lang;
chrome.browserAction.setBadgeText({text:'Done'});
chrome.browserAction.setBadgeBackgroundColor({color:[255,0,0,255]});
}).appendTo(row.children(':last'));
return row;
}


function loadjscssfile(filename, filetype){
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
}
else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
}

Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Chrome - codepad.org",
"version": "1.0",
"description": "A codepad.org interface.",
"background_page": "background.html",
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"permissions": [
"tabs", "http://codepad.org/*"
]

}
107 changes: 107 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<style>
.logo {
font-family: courier-new, monospace;
font-size: 100%;
display: block;
float: right;
}

.logo > a {
text-decoration: none;
}


body, html {
min-width:300px;
overflow-x:hidden;
font-family: sans-serif;
font-size: 12px;
}

#result {
border-top: 1px dotted #999;
display: none;
}

.CodeMirror-line-numbers {
font-size: 12px;
font-family: monospace;
color: #AAA;
padding-right: 5px;
}
#codebox {
margin-bottom: 10px;
margin-top: 10px;
font-family: monospace;

}

.editbox {
font-size: 12px !important;
}

#submit {
line-height: 18px;
margin-top: 20px;
}

.error {
color: #400;
font-weight: bolder;
}
.menu {
padding-top: 5px;
margin-top: 10px;
border-top: 1px solid #BBB;
width: 100%;

}

#history {
display: inline-block;
float: right;
}

#clear {
display: inline-block;
float: left;
}

#note {
font-size: 12px;
display: none;
font-style: italic;
}


</style>

<div>
<span class="logo"><a href="http://codepad.org">codepad</a> for Chrome</span>
<span>Language: </span>
<select id="lang" name="lang" style="vertical-align:middle">
<option value="C">C</option>
<option value="C++">C++</option>
<option value="D">D</option>
<option value="Haskell">Haskell</option>
<option value="Lua">Lua</option>
<option value="OCaml">OCaml</option>
<option value="PHP">PHP</option>
<option value="Perl">Perl</option>
<option value="Plain Text">Plain Text</option>
<option value="Python">Python</option>
<option value="Ruby">Ruby</option>
<option value="Scheme">Scheme</option>
<option value="Tcl">Tcl</option>
</select>
<div id="codebox">
<textarea id="code"></textarea>
<button id="submit">Run</button>
<div id="note">codepad.org seems to be under heavy load... be patient or try again later.</div>
</div>
</div>
<div id="result"></div>
<div class="menu"><a id="history" href="#">Show history</a><a id="clear" href="#">Clear</a></div>
<script src="CodeMirror/js/codemirror.js"></script>
<script src="popup.js"></script>

Loading

0 comments on commit 5b77876

Please sign in to comment.