Skip to content

Instantly share code, notes, and snippets.

@IlyaZha
Created June 6, 2023 07:29
Show Gist options
  • Save IlyaZha/cd90efcdddeee995708c6896aad460b8 to your computer and use it in GitHub Desktop.
Save IlyaZha/cd90efcdddeee995708c6896aad460b8 to your computer and use it in GitHub Desktop.
tlscontact JS
const audio = new Audio();
// Set the source of the audio file
audio.src = 'http://commondatastorage.googleapis.com/codeskulptor-assets/week7-brrring.m4a';
const audio2 = new Audio();
// Set the source of the audio file
audio2.src = 'http://commondatastorage.googleapis.com/codeskulptor-assets/Collision8-Bit.ogg';
function makeAttention() {
audio.play();
setTimeout(() => audio2.play(), 1000);
}
function getBlockElement() {
return document.querySelector('#timeTable');
}
// Get the DOM block element using the CSS selector
const blockElement = getBlockElement();
// Check if the block element exists
if (blockElement) {
// Convert the DOM block to HTML string
const blockHtml = blockElement.outerHTML;
if (blockHtml !== localStorage.getItem('savedBlock', blockHtml)) {
makeAttention();
}
// Save the HTML string to local storage
localStorage.setItem('savedBlock', blockHtml);
// Create a new mutation observer instance
const observer = new MutationObserver((mutations) => {
// Handle mutations
mutations.forEach((mutation) => {
// Perform actions based on the type of mutation
// For example, log the mutation type to the console
makeAttention();
});
});
// Configure and start the observer
const observerConfig = { attributes: true,
childList: true,
subtree: true,
characterData: true };
observer.observe(blockElement, observerConfig);
} else {
makeAttention();
}
function callable() {
const blockElement = getBlockElement();
const blockHtml = blockElement.outerHTML;
if (blockHtml !== localStorage.getItem('savedBlock', blockHtml)) {
makeAttention();
}
// Call the function again after 1 second
setTimeout(callable, 1000);
}
// Start the initial call
callable();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment