function getElementByXPath(path, context=null, _document=undefined) {
	if( _document === undefined ) _document = document;
	let res = document.evaluate(path, _document, context, XPathResult.FIRST_ORDERED_NODE_TYPE);
	if( !res ) return null;
	return res.singleNodeValue;
}

function getTextByXPath(path, context=null, _document=undefined) {
	let e = getElementByXPath(path, context, _document);
	if( !e ) return undefined;
	return e.textContent;
}

function getTextByQuerySelector(selector) {
	let e = document.querySelector(selector);
	if( !e ) return undefined;
	return e.textContent;
}

Leave a Reply

Your email address will not be published.

Warning: This site uses Akismet to filter spam. Until or unless I can find a suitable replacement anti-spam solution, this means that (per their indemnification document) all commenters' IP addresses will be sent to Automattic, Inc., who may choose to share such with 3rd parties.
If this is unacceptable to you, I highly recommend using an anonymous proxy or public Wi-Fi connection when commenting.