-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen-comments.user.js
57 lines (47 loc) · 1.48 KB
/
open-comments.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
49
50
51
52
53
54
55
56
57
// ==UserScript==
// @name Script for open comments on sites vc.ru, dtf.ru
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Open all comments
// @author Arthur N
// @match *://dtf.ru/*
// @match *://vc.ru/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function () {
"use strict";
console.log("start");
let previousTitle = document.title;
let currentTitle = document.title;
let isLinkToComment = Boolean(document.querySelector(".comments__link_to_all"));
const showAllComments = () =>
setTimeout(() => {
const showCommentsButton = document.querySelector(".comments__show-all");
if (showCommentsButton) {
showCommentsButton.click();
console.log("clicked");
}
}, 3000);
const observer = new MutationObserver(function (mutations) {
if (document.title !== currentTitle) {
previousTitle = currentTitle;
currentTitle = document.title;
isLinkToComment = Boolean(document.querySelector(".comments__link_to_all"));
if (!isLinkToComment) {
showAllComments();
}
}
});
const config = { subtree: true, childList: true };
observer.observe(document, config);
window.addEventListener("beforeunload", function (event) {
observer.disconnect();
});
if (isLinkToComment) {
return;
}
if (previousTitle === currentTitle) {
showAllComments();
}
})();