-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path8kun-disable-spoiler-thumbnail.js
63 lines (56 loc) · 2.18 KB
/
8kun-disable-spoiler-thumbnail.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
8chan disable spoiler thumbnail
Version 1.0.2
*/
(function (jQuery) {
'use strict';
function unspoilerThumbnail(postImage) {
if (postImage.src.endsWith(`/static/assets/${window.board_name}/spoiler.png`)
|| postImage.src.endsWith('/static/spoiler.png')) {
const fileURL = postImage.closest('div.file').querySelector('.fileinfo>a[title]').href;
if (fileURL === undefined || fileURL.indexOf('/file_store/') == -1) return;
const spoilerImg = postImage.src;
const thumbURL = fileURL.replace('/file_store/', '$&thumb/').replace((/(webm|mp4)$/), 'jpg');
postImage.onerror = () => postImage.src = spoilerImg;
postImage.onload = () => {
const multifile = postImage.closest('.multifile');
postImage.style.width = `${postImage.naturalWidth}px`;
postImage.style.height = `${postImage.naturalHeight}px`;
if (multifile) {
multifile.style.width = `${postImage.naturalWidth + 40}px`;
}
};
postImage.src = thumbURL;
}
}
function main() {
if (window.active_page == 'thread' || window.active_page == 'index') {
if (localStorage.disable_image_spoiler === undefined) {
localStorage.disable_image_spoiler = 'true';
}
if (window.Options && Options.get_tab('general')) {
Options.extend_tab('general', '<label id="disable-spoiler"><input type="checkbox"> Disable image spoiler where possible</label>');
document.querySelector('#disable-spoiler>input').addEventListener('change', () => {
localStorage.disable_image_spoiler = (localStorage.disable_image_spoiler === 'true') ? 'false' : 'true';
});
if (localStorage.disable_image_spoiler === 'true') {
document.querySelector('#disable-spoiler>input').setAttribute('checked', true);
}
}
if (localStorage.disable_image_spoiler === 'true') {
document.querySelectorAll('.post-image').forEach(unspoilerThumbnail);
jQuery(document).on('new_post', function (e, post) {
post.querySelectorAll('.post-image').forEach(unspoilerThumbnail);
});
}
}
}
function onReady(fn) {
if (document.readyState == 'loading') {
window.addEventListener('DOMContentLoaded', fn);
} else {
fn();
}
}
onReady(main);
})(window.jQuery);