-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.js
28 lines (23 loc) · 792 Bytes
/
link.js
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
a = document.querySelectorAll('[href]');
ext = ".php"
String.prototype.insertAt=function(index, string) {
return this.substr(0, index) + string + this.substr(index);
}
for(i=0;i<a.length;i++) {
value = a[i].getAttribute('href');
if(value.indexOf('.') == -1 && value.indexOf('?')==-1 && value.indexOf('#')==-1) {
a[i].href+= ext;
}
else if(value.indexOf('?')>-1 && value.indexOf('.')==-1) {
var inat = value.indexOf('?');
var pstring = a[i].getAttribute('href');
var nstring = pstring.insertAt(inat,ext);
a[i].setAttribute('href',nstring);
}
else if(value.indexOf('#')>-1 && value.indexOf('.')==-1) {
var inat = value.indexOf('#');
var pstring = a[i].getAttribute('href');
var nstring = pstring.insertAt(inat,ext);
a[i].setAttribute('href',nstring);
}
}