-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_main.js
53 lines (45 loc) · 1.55 KB
/
content_main.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
import { getEnableStatus } from "./StorageOperations.js";
const upResumeButtonQuery = '#HH-React-Root > div > div.HH-MainContent.HH-Supernova-MainContent > div.main-content > div > div:nth-child(2) > div > div > div.resume-wrapper > div:nth-child(2) > div > div.bloko-columns-row > div > div > div:nth-child(2) > div.bloko-gap.bloko-gap_top > div > button';
const targetUrl = "https://hh.ru/resume/";
//4 hours in milliSeconds
const milliSeconds = 14400000;
//Mutation observer
const mo = new MutationObserver(onMutation);
//Interval number by setInterval()
var intervalId;
//Script stopped within runtime
var stoppedInRuntime = false;
export function main() {
getEnableStatus().then((isEnabled) => {
if (isEnabled === true) {
mo.observe(document, {
subtree: true,
childList: true,
});
}
});
}
//If document changes and adds upResumeButton then fire the script
function onMutation(mutations) {
let buttonie = document.querySelector(upResumeButtonQuery);
if (buttonie != null) {
mo.disconnect();
upResume();
intervalId = setInterval(upResume, milliSeconds);
}
}
//Stop the script if popup.js sends a message.
chrome.runtime.onMessage.addListener(
function (message) {
if (message.stopRuntime === true) {
clearInterval(intervalId);
stoppedInRuntime = true;
}
}
);
//Up resume by clicking the up button
function upResume() {
if (!stoppedInRuntime) {
document.querySelector(upResumeButtonQuery).click();
}
}