Skip to content

Commit

Permalink
Merge pull request #3 from 9Lucky9/dev
Browse files Browse the repository at this point in the history
Fix bug, when button clicks only after refreshing the page.
  • Loading branch information
9Lucky9 authored Apr 22, 2023
2 parents cf03a1b + ea5ce3c commit 50f4073
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions content_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const targetUrl = "https://hh.ru/resume/";

//4 hours in milliSeconds
const milliSeconds = 14400000;
//Mutation observer
const mo = new MutationObserver(onMutation);
//Create interval number by setInterval()
//Interval number by setInterval()
var intervalId;

//Script stopped within runtime
Expand All @@ -15,18 +16,21 @@ var stoppedInRuntime = false;
export function main() {
getEnableStatus().then((isEnabled) => {
if (isEnabled === true) {
observe();
mo.observe(document, {
subtree: true,
childList: true,
});
}
});
}

//If document changes and adds upResumeButton then fire the script
function onMutation() {
if (document.querySelector(upResumeButtonQuery)) {
function onMutation(mutations) {
let buttonie = document.querySelector(upResumeButtonQuery);
if (buttonie != null) {
mo.disconnect();
upResume();
intervalId = setInterval(upResume, milliSeconds);
observe();
}
}

Expand All @@ -40,21 +44,10 @@ chrome.runtime.onMessage.addListener(
}
);

//Observe document only on page *resume/*
function observe() {
if (document.URL.includes(targetUrl)) {
mo.observe(document, {
subtree: true,
childList: true,
});
}
}

//Up resume by clicking the up button
function upResume() {
if (!stoppedInRuntime) {
document.querySelector(upResumeButtonQuery).click();
console.log("Fired");
}
}

0 comments on commit 50f4073

Please sign in to comment.