-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookmarklet-compiler.js
More file actions
32 lines (31 loc) · 1.08 KB
/
bookmarklet-compiler.js
File metadata and controls
32 lines (31 loc) · 1.08 KB
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
/**
* Bookmarklet Compiler
*
* @copyright Moxley Stratton - http://www.moxleystratton.com/
*/
window.Bookmarklet = {
compileBody: function (source) {
source = source.replace(/[\t\r\n]/g, ''); // Remove tabs, newlines
source = source.replace(/\/\*[^*]*\*\//, ''); // Remove multi-line comments; This needs more work
source = escape(source);
return source;
},
makeURL: function (sourceCode) {
return 'javascript:(function(){' + this.compileBody(sourceCode) + '}());';
},
forPost: function () {
var source = document.getElementById('source').value;
var display = document.getElementById('display');
var url = this.makeURL(source);
var container = document.getElementById('generated');
for (var i = 0; i < container.childNodes.length; i++) {
container.removeChild(container.childNodes[i]);
}
var a = document.createElement('a');
a.href = url;
var text = document.createTextNode('> > > Bookmark this link');
a.appendChild(text);
container.appendChild(a);
document.getElementById('source').style.height = '2em';
}
};