forked from rik/server-switch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
170 lines (163 loc) · 5.26 KB
/
Copy pathindex.html
File metadata and controls
170 lines (163 loc) · 5.26 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bookmarklet generator for URL rotation</title>
<style>
body {
margin: 2% auto auto;
max-width: 50em;
min-width: 35em;
font-family: sans-serif;
padding: 0 2em;
}
label, fieldset input, output {
display: block;
margin: 1em 0;
}
fieldset {
padding-right: 0;
}
.stringset {
max-height: 24em;
overflow-y: scroll;
margin: 0;
}
form, #instructions {
display: table-cell;
float: left;
width: 45%;
margin-right: 1em;
color: #555;
cursor: default;
}
ul.examples {
display: inline-block;
border: 1px solid lightgray;
padding: 1em;
margin-left: 2em;
}
ul.examples li {
display: block;
padding: .25em;
cursor: default;
}
ul.examples li a {
cursor: default;
}
label.optional {
margin-left: 2em;
}
label.optional input {
margin-left: -1.8em
}
[hidden=true] {
display: none;
}
output a, output a:link, output a:visited {
color: #000;
background-color: #ddd;
border-radius: 4px;
padding: 3px 6px;
margin: 0;
white-space: nowrap;
text-decoration: none;
cursor: grab;
cursor: -webkit-grab;
}
output a:before {
content: '⋮ ';
color: #eee;
}
output a:hover {
color: #fff;
background-color: #999;
text-decoration: none;
}
</style>
</head>
<h1>Bookmarklet generator for URL rotation</h1>
<p><i>Rotate between different versions of a website by changing the URL.</i></p>
<form>
<label>Bookmark title: <input id="bookmark-title" placeholder="Rotate!"></label>
<fieldset>
<legend>Strings</legend>
<div class="stringset">
<input class="needle" value="locale=en_US">
<input class="needle" value="locale=de_DE">
<input class="needle" value="locale=ru_RU">
<input class="needle" value="locale=zh_CN">
<button type="button">+</button>
</div>
</fieldset>
<label class="optional">
<input type="checkbox" checked id="adddefault">
Add <code>?[first string]</code> to the end of the URL when none is found as in:<br /> <code>example.com/page/?locale=en_US</code>
</label>
<input type="submit" value="Generate bookmarklet">
<output hidden="true">Drag me or copy me: <a href="#"></a></output>
</form>
<div id="instructions">
<p>This will generate a bookmarklet that replaces a string in the list with the next string. For example using this:</p>
<ul class="examples">
<li><a href="#">www.example.com</a></li>
<li><a href="#">stage.example.com</a></li>
<li><a href="#">example.local</a></li>
</ul>
<p>…will take you to the exact same page on another domain. Or you can replace a query string name/value pair with the next one:</p>
<ul class="examples">
<li><a href="#">locale=en_US</a></li>
<li><a href="#">locale=en_XA</a></li>
<li><a href="#">locale=fr_FR</a></li>
</ul>
<p>Each time you click the bookmarklet, the next string will be pushed into the URL and the page will be reloaded.</p>
</div>
<script>
function generateBookmarklet(e) {
e.preventDefault();
var needles = [];
var needlesInput = document.querySelectorAll('input.needle');
for (var i=0, il=needlesInput.length; i<il; i++) {
var needle = needlesInput[i].value;
if (needle.length > 0) {
needles.push('"' + needle + '"');
}
}
needleArray= '[' + needles.join(',') + ']';
var addDefault = document.querySelectorAll('input#adddefault');
var addDefaultJs = '';
if (addDefault[0].checked) { addDefaultJs = 'if(!flag){newLoc=loc.href+"?"+' + needles[0] + ';loc.assign(newLoc);}'; }
// generate bookmark string
var bookmarkletJs = 'javascript:(function(){var strs=' + needleArray + ',\
loc=window.location,\
flag=false;\
for(var i=0;i<strs.length;i++){\
var pos=loc.href.indexOf(strs[i]);\
if(pos>=0){\
j=((i+1)%strs.length);\
newLoc=loc.href.split(strs[i]).join(strs[j]);\
loc.assign(newLoc);\
flag=true;\
}\
}' + addDefaultJs + '\
})();';
// generate link to copy.
var output = document.querySelector('output');
var a = output.querySelector('a');
a.href = bookmarkletJs;
var title = document.getElementById('bookmark-title').value;
if (title.length == 0) {
title = "Rotate!";
};
a.innerHTML = title;
output.removeAttribute('hidden');
}
function addField(e) {
var input = document.createElement('input');
input.className = "needle";
input.placeholder = "another string";
e.target.parentNode.insertBefore(input, e.target);
}
document.querySelector('form').addEventListener('submit', generateBookmarklet, false);
document.querySelector('button').addEventListener('click', addField, false);
</script>