-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlinky.html
66 lines (60 loc) · 2.47 KB
/
linky.html
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
<html><head><title>Linky!</title></head>
<script type="text/javascript">
function dochange()
{
var i = document.getElementById("in");
var o = document.getElementById("out");
var s = document.getElementById("viewsource");
o.href = i.value;
s.href = "view-source:" + i.value;
} //dochange()
function doload()
{
if(location.search.length>1) { // if there's a query string...
var i = document.getElementById("in");
var urlstr = location.search.substring(1); // chop the leading "?"
urlstr = decodeURIComponent(urlstr);
// since the query string gets encoded as a component
// (e.g., http%3A%2F%2F...)
i.value = urlstr;
dochange(); //update the links
}
} //doload()
function addprefix(prefix)
{
var i = document.getElementById("in");
i.value = prefix + i.value;
dochange();
} //addprefix
</script>
<body onload="doload()">
<form>
<label>Enter a URL:</label>
<input type="text" name="in" id="in" onChange="dochange()"></input> •
<a href="#" onclick="addprefix('https://')">+https://</a> •
<a href="#" onclick="addprefix('http://')">+http://</a>
</form>
<br>
Here's the link: <a href="#" name="out" id="out">linky</a>
← right-click or do whatever you want.
Or you can
<a href="#" name="viewsource" id="viewsource">view the target's source</a>
(works at least in Chrome and Firefox).
<br>
<h2>Why?</h2>
Because sometimes you want to save the target of a URL without opening
it in the browser first. Pasting the URL into the address bar doesn't
create an actual link, which is what you need. (See, e.g.,
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=62253">this request</a>
to add such a feature to Firefox.) So here you go!
</body>
<hr>
Copyright (c) 2016 <a href="https://devwrench.wordpress.com">cxw</a> of
<a href="https://bitbucket.org/inclinescene/public">Incline</a> •
<a href="http://stackexchange.com/users/3433783/cxw">Stack Exchange</a> •
Made by hand in <a href="http://www.vim.org/">vim</a> •
Code lives <a href="https://github.com/cxw42/cxw42.github.io">here</a>
<br>
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/80x15.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.
</html>
<!-- vi: set ts=4 sts=4 sw=4 et ai: -->