From 004041be1da59eaac804000ef337006ae8c82d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Vieille?= Date: Thu, 28 Apr 2016 02:13:23 +0200 Subject: [PATCH] Fix ancre & mailto & empty array --- Js/anywhere.js | 15 +++++++++------ Js/anywhere.min.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Js/anywhere.js b/Js/anywhere.js index 3ca0132..bf27315 100644 --- a/Js/anywhere.js +++ b/Js/anywhere.js @@ -4,11 +4,14 @@ */ javascript:(function(){ - var l = Array.prototype.slice.call(document.getElementsByTagName('a')); - for(var i = l.length-1;i>=0;i--){ - if(/^(#|mailto)/.test(l[i].href.slice(0,1))||l[i].href==document.location.href)l.splice(i,0); + var l = Array.prototype.slice.call(document.getElementsByTagName('a')), + c = document.location.href; + var e = new RegExp("^(mailto|(https?)?"+c+"/?#)"), + r = "http://swapthatlink.com"; + for (var i = l.length-1;i>=0;i--){ + if (e.test(l[i].href.slice(0,1)) || l[i].href == c) l.splice(i,0); }; - r=l[Math.floor(Math.random()*l.length)].href; - console.log(r); - document.location.href=r; + if (l.length>0) r = l[Math.floor(Math.random()*l.length)].href; + document.location.href = r; + return; })(); \ No newline at end of file diff --git a/Js/anywhere.min.js b/Js/anywhere.min.js index 62a7d01..2c621a6 100644 --- a/Js/anywhere.min.js +++ b/Js/anywhere.min.js @@ -1 +1 @@ -javascript:(function(){var l=Array.prototype.slice.call(document.getElementsByTagName('a'));for(var i=l.length-1;i>=0;i--){if(/^(#|mailto)/.test(l[i].href.slice(0,1))||l[i].href==document.location.href)l.splice(i,0)};r=l[Math.floor(Math.random()*l.length)].href;console.log(r);document.location.href=r})(); \ No newline at end of file +javascript:(function(){var l=Array.prototype.slice.call(document.getElementsByTagName('a')),c=document.location.href;var e=new RegExp("^(mailto|(https?)?"+c+"/?#)"),r="http://swapthatlink.com";for(var i=l.length-1;i>=0;i--){if(e.test(l[i].href.slice(0,1))||l[i].href==c)l.splice(i,0)};if(l.length>0)r=l[Math.floor(Math.random()*l.length)].href;document.location.href=r;return})(); \ No newline at end of file