-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages_switcher.user.js
48 lines (44 loc) · 1.42 KB
/
images_switcher.user.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ==UserScript==
// @name Images/links switcher
// @description Insert images instead of links, or links instead of images.
// @version 1.0.2
// @homepageURL https://github.com/VapaudenKuolemasta/images-links-switcher-userscript
// @updateURL https://github.com/VapaudenKuolemasta/images-links-switcher-userscript/raw/master/images_switcher.user.js
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
GM_registerMenuCommand('Switch "images/links"', function(){
var linkToImg = true;
if( GM_getValue(document.domain) ){
GM_setValue( document.domain, false );
linkToImg = false;
}else{
GM_setValue( document.domain, true );
}
toggler( linkToImg );
});
function toggler( linkToImg ){
for (var key in document.getElementsByTagName('a')){
var val = document.getElementsByTagName('a')[key];
if( val.getAttribute('href').search(/(.jpg|.png|.jpeg)/i)+1 ){
if( linkToImg ){
img = new Image();
img.onload = function() {
if(this.height>document.body.clientHeight){
this.style.height = document.body.clientHeight-30;
}
if(this.width>document.body.clientWidth){
this.style.width = document.body.clientWidth;
}
};
img.src = val.getAttribute('href');
val.innerHTML = '';
val.appendChild(img);
}else{
val.innerHTML = val.getAttribute('href');
}
}
}
}
if( GM_getValue(document.domain) ) toggler( true );