-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookmarklet-generator.html
More file actions
141 lines (129 loc) · 3.65 KB
/
bookmarklet-generator.html
File metadata and controls
141 lines (129 loc) · 3.65 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<title>Bookmarklet Maker</title>
<meta charset="UTF-8">
<meta name="keywords" content="bookmarklet, hack, javascript, automate, browse, app">
<meta name="description" content="Bookmarklet creator tool.">
<style>
html {
background-color: white;
width: 100%;
height: 100%;
}
body {
font: 13px/1.4 sans-serif;
margin: 0 auto;
padding: 1em;
max-width: 800px;
}
h1 {
color: rgb(78,98,114);
font-weight: bold;
border-bottom: 1px solid #ddd;
text-align: center;
}
label {
font-weight: bold;
}
input, textarea, button {
font-size: 14px;
padding: 6px;
margin: 6px 0;
}
textarea {
width: 100%;
height: 150px;
border: 1px solid #ccc;
resize: vertical;
}
.output-textarea {
height: 60px;
}
.button-bar {
margin-top: 10px;
text-align: center;
}
.bookmarklet, .button-bar button {
display: inline-block;
margin: 4px;
padding: 6px 12px;
color: #fff;
background-color: #32a0eb;
border: none;
border-radius: 4px;
text-decoration: none;
cursor: pointer;
}
.bookmarklet:hover, .button-bar button:hover {
background-color: #2187d1;
}
#bookmarklet-a {
font-weight: bold;
}
.section {
margin-top: 2em;
}
pre {
background: #f0f0f0;
padding: 0.5em;
overflow-x: auto;
}
</style>
<script>
function cleanCode(code) {
return code.trim();
}
function generateBookmarklet() {
const title = document.getElementById("title-input").value;
const code = document.getElementById("code-textarea").value;
const output = "javascript:" + encodeURIComponent("(function(){" + cleanCode(code) + "})();");
document.getElementById("bookmarklet-a").href = output;
document.getElementById("bookmarklet-a").textContent = title;
document.getElementById("output-textarea").value = output;
document.getElementById("htmlOuput-textarea").value = `<a href="${output}">${title}</a>`;
}
function runCode() {
const code = document.getElementById("code-textarea").value;
eval(code);
}
function clearCode() {
document.getElementById("title-input").value = "bookmarklet";
document.getElementById("code-textarea").value = "";
}
</script>
</head>
<body>
<h1>Bookmarklet Maker</h1>
<div class="button-bar">
<label for="title-input">Title:</label>
<input id="title-input" value="bookmarklet">
<button onclick="generateBookmarklet()">Generate Bookmarklet</button>
<button onclick="runCode()">Run Code</button>
<button onclick="clearCode()">Clear</button>
</div>
<div class="section">
<label for="code-textarea">Code:</label>
<textarea id="code-textarea">alert('hello world');</textarea>
</div>
<div class="section">
<p><b>Bookmarklet:</b> <a id="bookmarklet-a" class="bookmarklet" href="#">bookmarklet</a></p>
</div>
<div class="section">
<label for="output-textarea">JavaScript Output:</label>
<textarea id="output-textarea" class="output-textarea" readonly></textarea>
</div>
<div class="section">
<label for="htmlOuput-textarea">HTML Link Code:</label>
<textarea id="htmlOuput-textarea" class="output-textarea" readonly></textarea>
</div>
<div class="section">
<h2>Usage</h2>
<ul>
<li>Paste your JavaScript into the code box and click <b>Generate</b></li>
<li>Click the blue <b>bookmarklet</b> button to test</li>
<li>Drag it into your browser’s bookmarks bar to save</li>
</ul>
</div>
</body>
</html>