Fossil SCM

New javascript for href.js such that any mousemove or mousedown event at any time is sufficient to trigger the mouse activity condition for activation of hyperlinks. This works better on FF and chrome, but with safari, the visited/unvisited link color is determined by the initial value of href= and is not adjusted when href= changes, so visited/unvisited colors are not being updated on safari.

drh 2022-02-12 13:29 trunk
Commit e7d67b7640414f6e66e8d4b582dcb383270ea3b42e46a6805f7942ab3025b5ff
1 file changed +25 -12
+25 -12
--- src/href.js
+++ src/href.js
@@ -15,14 +15,15 @@
1515
** The <script> must have an id='href-data'. DELAY is the number
1616
** milliseconds delay prior to populating href= and action=. If the
1717
** mouseover boolean is true, then the href= rewrite is further delayed
1818
** until the first mousedown event that occurs after the timer expires.
1919
*/
20
-var antiRobotOnce = 0;
21
-function antiRobotSetAllHrefs(){
22
- if( antiRobotOnce ) return;
23
- antiRobotOnce = 1;
20
+var antiRobot = 0;
21
+var antiRobotBody = document.getElementsByTagName("body")[0];
22
+function antiRobotGo(){
23
+ if( antiRobot!=3 ) return;
24
+ antiRobot = 7;
2425
var anchors = document.getElementsByTagName("a");
2526
for(var i=0; i<anchors.length; i++){
2627
var j = anchors[i];
2728
if(j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
2829
}
@@ -30,22 +31,34 @@
3031
for(var i=0; i<forms.length; i++){
3132
var j = forms[i];
3233
if(j.hasAttribute("data-action")) j.action=j.getAttribute("data-action");
3334
}
3435
}
35
-function antiRobotSetMouseEventHandler(){
36
- document.getElementsByTagName("body")[0].onmousedown=function(){
37
- antiRobotSetAllHrefs();
38
- document.getElementsByTagName("body")[0].onmousedown=null;
39
- }
40
-}
4136
function antiRobotDefense(){
4237
var x = document.getElementById("href-data");
4338
var jx = x.textContent || x.innerText;
4439
var g = JSON.parse(jx);
4540
if( g.mouseover ){
46
- setTimeout(antiRobotSetMouseEventHandler, g.delay);
41
+ antiRobotBody.onmousedown=function(){
42
+ antiRobot |= 2;
43
+ antiRobotGo();
44
+ antiRobotBody.onmousedown=null;
45
+ }
46
+ antiRobotBody.onmousemove=function(){
47
+ antiRobot |= 2;
48
+ antiRobotGo();
49
+ antiRobotBody.onmousemove=null;
50
+ }
51
+ }else{
52
+ antiRobot |= 2;
53
+ }
54
+ if( g.delay>0 ){
55
+ setTimeout(function(){
56
+ antiRobot |= 1;
57
+ antiRobotGo();
58
+ }, g.delay)
4759
}else{
48
- setTimeout(antiRobotSetAllHrefs, g.delay);
60
+ antiRobot |= 1;
4961
}
62
+ antiRobotGo();
5063
}
5164
antiRobotDefense();
5265
--- src/href.js
+++ src/href.js
@@ -15,14 +15,15 @@
15 ** The <script> must have an id='href-data'. DELAY is the number
16 ** milliseconds delay prior to populating href= and action=. If the
17 ** mouseover boolean is true, then the href= rewrite is further delayed
18 ** until the first mousedown event that occurs after the timer expires.
19 */
20 var antiRobotOnce = 0;
21 function antiRobotSetAllHrefs(){
22 if( antiRobotOnce ) return;
23 antiRobotOnce = 1;
 
24 var anchors = document.getElementsByTagName("a");
25 for(var i=0; i<anchors.length; i++){
26 var j = anchors[i];
27 if(j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
28 }
@@ -30,22 +31,34 @@
30 for(var i=0; i<forms.length; i++){
31 var j = forms[i];
32 if(j.hasAttribute("data-action")) j.action=j.getAttribute("data-action");
33 }
34 }
35 function antiRobotSetMouseEventHandler(){
36 document.getElementsByTagName("body")[0].onmousedown=function(){
37 antiRobotSetAllHrefs();
38 document.getElementsByTagName("body")[0].onmousedown=null;
39 }
40 }
41 function antiRobotDefense(){
42 var x = document.getElementById("href-data");
43 var jx = x.textContent || x.innerText;
44 var g = JSON.parse(jx);
45 if( g.mouseover ){
46 setTimeout(antiRobotSetMouseEventHandler, g.delay);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47 }else{
48 setTimeout(antiRobotSetAllHrefs, g.delay);
49 }
 
50 }
51 antiRobotDefense();
52
--- src/href.js
+++ src/href.js
@@ -15,14 +15,15 @@
15 ** The <script> must have an id='href-data'. DELAY is the number
16 ** milliseconds delay prior to populating href= and action=. If the
17 ** mouseover boolean is true, then the href= rewrite is further delayed
18 ** until the first mousedown event that occurs after the timer expires.
19 */
20 var antiRobot = 0;
21 var antiRobotBody = document.getElementsByTagName("body")[0];
22 function antiRobotGo(){
23 if( antiRobot!=3 ) return;
24 antiRobot = 7;
25 var anchors = document.getElementsByTagName("a");
26 for(var i=0; i<anchors.length; i++){
27 var j = anchors[i];
28 if(j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
29 }
@@ -30,22 +31,34 @@
31 for(var i=0; i<forms.length; i++){
32 var j = forms[i];
33 if(j.hasAttribute("data-action")) j.action=j.getAttribute("data-action");
34 }
35 }
 
 
 
 
 
 
36 function antiRobotDefense(){
37 var x = document.getElementById("href-data");
38 var jx = x.textContent || x.innerText;
39 var g = JSON.parse(jx);
40 if( g.mouseover ){
41 antiRobotBody.onmousedown=function(){
42 antiRobot |= 2;
43 antiRobotGo();
44 antiRobotBody.onmousedown=null;
45 }
46 antiRobotBody.onmousemove=function(){
47 antiRobot |= 2;
48 antiRobotGo();
49 antiRobotBody.onmousemove=null;
50 }
51 }else{
52 antiRobot |= 2;
53 }
54 if( g.delay>0 ){
55 setTimeout(function(){
56 antiRobot |= 1;
57 antiRobotGo();
58 }, g.delay)
59 }else{
60 antiRobot |= 1;
61 }
62 antiRobotGo();
63 }
64 antiRobotDefense();
65

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button