Skip to content

Commit 6cd072e

Browse files
committed
Display images and videos in the lightbox
The lightbox only appears when the pointer is on a image or a video. When is on a thumbnail of a PDF or some other file the lightbox doesn't show.
1 parent b7979bb commit 6cd072e

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ Because I didn't want to install all the dependencies just to test a few lines o
1616
I know but I'm not sure if I'm able to use the Lainchan's favicon for this, ~~but I use that icon on my computer and it looks cute.~~
1717

1818
## TODO
19-
- Fix the lightbox, when you load an image for the first time it doesn't use the margin.
20-
- When you use the *Expand everything* button it also loads the videos.
19+
- When you use the *Expand everything* button it also loads the videos.

js/script.js

+28-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
function lightbox(){
22
let img = document.getElementsByClassName('post-image');
3-
let link;
43

54
/*
65
* Load all the big images in the thread
76
*/
87
for (let i = 0; i < img.length; i++) {
9-
link = img[i].parentElement.href;
8+
let link = img[i].parentElement.href;
109
document.getElementById('thread').insertAdjacentHTML('afterbegin', '<img class="lightbox-img-hide" src="' + link + '">');
1110
}
1211

@@ -16,13 +15,33 @@ function lightbox(){
1615
* the image appears in the lightbox
1716
*/
1817
img[i].addEventListener('mouseover', function(){
19-
link = this.parentElement.href;
20-
document.getElementById('thread').insertAdjacentHTML('afterbegin', '<div id="lightbox"><img id="lightbox-img" src="' + link + '"></div>');
18+
let link = this.parentElement.href;
19+
let ext = link.slice(-4, link.length);
20+
switch (ext) {
21+
case '.png':
22+
case '.jpg':
23+
case 'jpeg':
24+
case '.gif':
25+
document.getElementById('thread').insertAdjacentHTML(
26+
'afterbegin',
27+
'<div id="lightbox"><img id="lightbox-img" src="' + link + '"></div>'
28+
);
29+
break;
30+
default:
31+
let file = link.indexOf('&');
32+
link = link.slice(0, file);
33+
document.getElementById('thread').insertAdjacentHTML(
34+
'afterbegin',
35+
'<div id="lightbox"><video id="lightbox-video" src="' + link + '" autoplay="true" loop="true"></video></div>'
36+
);
37+
console.log(link);
38+
break;
39+
}
2140
}, false);
2241

2342
/*
24-
* When pointer is out: Remove the lightbox from the DOM
25-
*/
43+
* When pointer is out: Remove the lightbox from the DOM
44+
*/
2645
img[i].addEventListener('mouseout', function(){
2746
document.getElementById('lightbox').parentNode.removeChild(document.getElementById('lightbox'));
2847
}, false);
@@ -33,9 +52,9 @@ function lightbox(){
3352

3453
function expandIMG(){
3554
/*
36-
* It creates a button
37-
* in the bottom bar which can be used
38-
* to load all the original images in the thread
55+
* It creates a button
56+
* in the bottom bar which can be used
57+
* to load all the original images in the thread
3958
*/
4059

4160
let bottomBar = document.getElementsByClassName('threadlinks');

manifest.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
"manifest_version": 2,
33

44
"name": "Lain++",
5-
"version": "0.0.1",
5+
"version": "0.0.3",
66
"description": "This extension gives Lainchan.org new functions",
7-
"version": "1.0",
87
"author": "Akko",
98
"homepage_url": "https://github.com/4k1k0/lainpp",
109

1110
"browser_action": {
12-
"default_icon": "img/icon16.png",
11+
"default_icon": "img/icon48.png",
1312
"default_title": "Lain++"
1413
},
1514
"icons": { "16": "img/icon16.png",
@@ -35,4 +34,3 @@
3534
"https://ajax.googleapis.com/"
3635
]
3736
}
38-

0 commit comments

Comments
 (0)