Skip to content

Instantly share code, notes, and snippets.

@jemsgit
Created December 12, 2023 06:59
Show Gist options
  • Save jemsgit/324c94e3ccb342bc4cef3b763b5600a1 to your computer and use it in GitHub Desktop.
Save jemsgit/324c94e3ccb342bc4cef3b763b5600a1 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Extract Text from Astrocentr Pages
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Extract text content from multiple pages on Astrocentr website
// @author Your Name
// @match https://www.astrocentr.ru/index.php*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const extractText = () => {
const mainText = document.querySelector('.main_text > div > fieldset');
if (mainText) {
console.log(`Text content from current page:`);
console.log(mainText.textContent.trim());
let persistedTextArray = JSON.parse(localStorage.getItem('persistedTextArray')) || [];
persistedTextArray.push({
textContent: mainText.textContent.trim(),
img: 'https://www.astrocentr.ru' + document.querySelectorAll('.fsdiv img')[0].getAttribute('src')
});
localStorage.setItem('persistedTextArray', JSON.stringify(persistedTextArray));
} else {
console.log(`No main text found on current page`);
}
};
const navigateAndExtract = (linkNum) => {
if (linkNum <= 36) {
document.location = `https://www.astrocentr.ru/index.php?przd=lenorman&str=len&nr=${linkNum}b`;
} else {
console.log('Finished extracting content from all pages.');
}
};
window.addEventListener('load', () => {
const currentLinkNum = parseInt(window.location.href.match(/nr=(\d+)/)[1], 10);
extractText();
navigateAndExtract(currentLinkNum + 1);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment