index.md - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
index.md (3226B) | |
--- | |
1 # Link hinting | |
2 ## Description | |
3 This script allows a user to follow link by pressing Alt+number of the | |
4 link. Numbers are never over 5, to ease finger access. | |
5 Deploy it into ~/.surf/script.js | |
6 | |
7 *Needs some work on the script to permi buttons and textinput | |
8 following...* | |
9 | |
10 ## Usage | |
11 Press `Alt`, then the number of the link, and finally `f`to follow the | |
12 link, only with left hand. | |
13 | |
14 ## Author | |
15 Christian hahn <ch radamanthys de> | |
16 | |
17 [dev mailing list](//lists.suckless.org/dev/1009/5996.html) | |
18 | |
19 | |
20 ## Code | |
21 | |
22 | |
23 // easy links for surf | |
24 // christian hahn <ch radamanthys de>, sep 2010 | |
25 | |
26 testcomplete = function() { | |
27 if(document.readyState=="complete") { | |
28 run(); return; | |
29 } | |
30 window.setTimeout("testcomplete()",200); | |
31 } | |
32 testcomplete(); | |
33 | |
34 run=function() { | |
35 // config , any css | |
36 var modkey = 18; //ctrl=17, alt=18 | |
37 var cancelkey = 67; // c | |
38 var newwinkey = 84; // t | |
39 var openkey = 70; // f | |
40 var label_style = {"color":"black","fontSize":"10px","ba… | |
41 var hl_style = {"backgroundColor":"#E3FF38","fontSize… | |
42 var nr_base = 5; // >=10 : normal integer, | |
43 | |
44 // globals | |
45 var ankers = document.getElementsByTagName("a"); | |
46 var labels = new Object(); | |
47 var ui_visible = false; | |
48 var input = ""; | |
49 | |
50 // functions | |
51 hl=function(t) { | |
52 for(var id in labels) { | |
53 if (t && id.match("^"+t)==t) | |
54 for(var s in hl_style) | |
55 labels[id].rep.style[s]=… | |
56 else | |
57 for(var s in label_style) | |
58 labels[id].rep.style[s]=… | |
59 } | |
60 } | |
61 open_link=function(id, new_win) { | |
62 try { | |
63 var a = labels[input].a; | |
64 if(a && !new_win) window.location.href=a… | |
65 if(a && new_win) window.open(a.href,a.h… | |
66 } catch (e) {} | |
67 } | |
68 set_ui=function(s) { | |
69 var pos = "static"; | |
70 ui_visible = true; | |
71 if(s == "hidden") { | |
72 ui_visible = false; | |
73 pos = "absolute"; | |
74 input=""; | |
75 } | |
76 for(var id in labels) { | |
77 labels[id].rep.style.visibility=s; | |
78 labels[id].rep.style.position=pos; | |
79 } | |
80 } | |
81 base=function(n, b) { | |
82 if(b>=10) return n.toString(); | |
83 var res = new Array(); | |
84 while(n) { | |
85 res.push( (n%b +1).toString() ) | |
86 n=parseInt(n/b); | |
87 } | |
88 return res.reverse().join(""); | |
89 } | |
90 | |
91 // main | |
92 // create labels | |
93 for (var i=0; i<ankers.length; i++) { | |
94 var a = ankers[i]; | |
95 if (!a.href) continue; | |
96 var b = base(i+1,nr_base); | |
97 var d = document.createElement("span"); | |
98 d.style.visibility="hidden"; | |
99 d.innerHTML=b; | |
100 for(var s in label_style) | |
101 d.style[s]=label_style[s]; | |
102 labels[b]={"a":a, "rep":d}; | |
103 a.parentNode.insertBefore(d, a.nextSibling); | |
104 } | |
105 | |
106 // set key handler | |
107 window.onkeydown=function(e) { | |
108 if (e.keyCode == modkey) { | |
109 set_ui("visible"); | |
110 } | |
111 } | |
112 window.onkeyup=function(e) { | |
113 if (e.keyCode == modkey ) { | |
114 open_link(input); | |
115 set_ui("hidden"); | |
116 hl(input); | |
117 } else if (ui_visible) { | |
118 if(e.keyCode == newwinkey) { | |
119 open_link(input, true); | |
120 set_ui("hidden"); | |
121 } else if(e.keyCode == cancelkey) | |
122 input=""; | |
123 else if(e.keyCode == openkey) { | |
124 open_link(input); | |
125 set_ui("hidden"); | |
126 } else | |
127 input += String.fromCharCode(e.k… | |
128 hl(input); | |
129 } | |
130 } | |
131 } | |
132 | |
133 |