-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathremove-blur.js
More file actions
57 lines (54 loc) · 2.66 KB
/
remove-blur.js
File metadata and controls
57 lines (54 loc) · 2.66 KB
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
// Chỉ chạy trên trang xem tài liệu, tránh làm vỡ trang chủ / trang khác (fix "Well, this is awkward")
function isDocumentViewerPage() {
if (typeof window === 'undefined' || !window.location || !window.location.pathname) return false;
const path = window.location.pathname.toLowerCase();
if (path.indexOf('/document/') !== -1 || path.indexOf('/doc/') !== -1) return true;
if (document.getElementById('document-wrapper') || document.getElementById('viewer-wrapper')) return true;
return false;
}
function getViewerWrapper() {
return document.getElementById('viewer-wrapper')
|| document.querySelector('[class*="viewer-wrapper"]')
|| document.querySelector('[class*="ViewerWrapper"]');
}
function getDocumentWrapper() {
return document.getElementById('document-wrapper')
|| document.querySelector('[class*="document-wrapper"]');
}
function getPageContentElements() {
const byClass = document.getElementsByClassName('page-content');
if (byClass.length > 0) return Array.from(byClass);
var root = document.getElementById('viewer-wrapper') || document.getElementById('document-wrapper');
if (!root) return [];
return Array.from(root.querySelectorAll('[class*="page-content"], [class*="PageContent"]'));
}
const focusImages = () => {
var bluredContainers = Array.from(document.getElementsByClassName('blurred-container'));
bluredContainers.forEach( (bluredContainer) => {
if (!bluredContainer.firstChild || !bluredContainer.firstChild.src) return;
bluredContainer.firstChild.src = bluredContainer.firstChild.src.replace('/blurred/', '/');
bluredContainer.firstChild.classList.add('bi', 'x0', 'y0', 'w1', 'h1');
bluredContainer.classList.remove('blurred-container');
});
// Một số phiên bản dùng class/selector khác cho ảnh blur
document.querySelectorAll('[class*="blurred"] img[src*="blurred"]').forEach(img => {
img.src = img.src.replace('/blurred/', '/');
});
};
window.addEventListener('load', function(){
if (!isDocumentViewerPage()) return;
var pages = getPageContentElements();
/* Không xóa sibling của .page-content — dễ xóa nhầm nội dung tài liệu khi Studocu đổi DOM. Chỉ thêm nofilter + unblur ảnh. */
pages.forEach(function(page) {
if (page && page.classList) page.classList.add("nofilter");
});
const viewerWrapper = getViewerWrapper();
if (viewerWrapper) {
viewerWrapper.addEventListener('scroll', focusImages);
}
const documentWrapper = getDocumentWrapper();
if (documentWrapper) {
documentWrapper.addEventListener('scroll', focusImages);
}
focusImages();
});