Created
December 12, 2023 06:59
-
-
Save jemsgit/324c94e3ccb342bc4cef3b763b5600a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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