Are you sure you want to go to an external site to donate a monetary value?
WARNING: Some countries laws may supersede the payment processors policy such as the GDPR and PayPal. While it is highly appreciated to donate, please check with your countries privacy and identity laws regarding privacy of information first. Use at your utmost discretion.
Recently, more websites store data on JSON files and that data is rendered upon page load.
What my script does, is generating page Title (and also description note).
I'm attempting to get the name of a seller at https://www.aliexpress.com/item/4000087251384.html
mediaUploader = document.evaluate('//h3[@class="store-name"]//a/text()', document, null, XPathResult.STRING_TYPE, null );
Yet, the following code is generated only on Event
<div class="store-container" data-role="dsr"> <h3 class="store-name" data-role="store-name"><a href="//www.aliexpress.com/store/614324?spm=a2g0o.detail.1000007.1.733865798XwyaA" target="_blank" data-spm-anchor-id="a2g0o.detail.1000007.1">The Supplier of High-end Glasses</a></h3> <div> <span data-role="positive-feedback"><i>97.4%</i> <span class="feedback-type">Positive feedback</span></span></div> </div> <div class="follow-container"><span class="text-btn follow" data-role="add-storelist" data-text-follow="Follow" data-text-following="Following">+ Follow</span> <p class="num-followers"><i>7122</i> Followers</p> </div>
Here's my script
// ==UserScript== // @name Proper Title // @namespace org.title.proper // @description Set sensible and functional page title and description // @grant none // @run-at document-end // @include http://www.israelbar.org.il/* // @include https://addons.mozilla.org/* // @include https://github.com/*/* // @exclude https://github.com/*/*/blob/* // @exclude https://github.com/*/*/commit/* // @exclude https://github.com/*/*/issues/* // @exclude https://github.com/*/*/issues // @exclude https://github.com/*/*/notifications // @exclude https://github.com/*/*/orgs/* // @exclude https://github.com/*/*/projects // @exclude https://github.com/*/*/pull/* // @exclude https://github.com/*/*/pulls // @exclude https://github.com/*/*/pulse // @exclude https://github.com/*/*/search // @exclude https://github.com/*/*/wiki // @exclude https://github.com/*/*/wiki/* // @exclude https://github.com/notifications/* // @exclude https://github.com/sessions/* // @exclude https://gist.github.com/*/forked // @exclude https://gist.github.com/*/starred // @include https://gist.github.com/*/* // @include https://www.aliexpress.com/item/* // @include https://www.nevo.co.il/law_html/* // @include https://www.youtube.com/watch?v=* // @include https://openclipart.org/detail/* // @include https://sourceforge.net/projects/* // @include https://torrentz2.me/* // @exclude https://torrentz2.me/search* // @version 1.0.0 // ==/UserScript== var mediaDescription, metaElements, mediaProducer, mediaTitle, mediaUploader, pageTitle; metaElements = document.getElementsByTagName('meta'); mediaDescription = null; switch (window.location.hostname) { case 'addons.mozilla.org': mediaTitle = document.evaluate('//h1/text()', document, null, XPathResult.STRING_TYPE, null ); mediaUploader = document.evaluate('//h1/span/a/text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue + ' (by ' + mediaUploader.stringValue + ')'; break; case 'www.aliexpress.com': mediaTitle = document.evaluate('//h1[@class="product-title-text"]/text()', document, null, XPathResult.STRING_TYPE, null ); //mediaDescription = document.evaluate('h1[@class="product-title-text"]/text()', document, null, XPathResult.STRING_TYPE, null ); mediaUploader = document.evaluate('//h3[@class="store-name"]//a/text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue + ' (by ' + mediaUploader.stringValue + ')'; break; case 'github.com': //mediaTitle = document.evaluate('//strong[@itemprop="name"]//text()', document, null, XPathResult.STRING_TYPE, null ); mediaTitle = document.evaluate('//strong[@itemprop="name"]/a/text()', document, null, XPathResult.STRING_TYPE, null ); mediaDescription = document.evaluate('normalize-space(//span[@itemprop="about"]//text())', document, null, XPathResult.STRING_TYPE, null ); //mediaUploader = document.evaluate('//span[@itemprop="author"]//text()', document, null, XPathResult.STRING_TYPE, null ); mediaUploader = document.evaluate('//a[@rel="author"]/text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue + ' (by ' + mediaUploader.stringValue + ')'; break; case 'gist.github.com': //mediaTitle = document.evaluate('//div[@itemprop="about"]/text()', document, null, XPathResult.STRING_TYPE, null ); mediaTitle = document.evaluate('//strong[@itemprop="name"]/a/text()', document, null, XPathResult.STRING_TYPE, null ); //mediaUploader = document.evaluate('//span[@itemprop="author"]/text()', document, null, XPathResult.STRING_TYPE, null ); mediaUploader = document.evaluate('//span[@class="author"]/a/text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue + ' (by ' + mediaUploader.stringValue + ')'; break; case 'www.israelbar.org.il': switch (window.location.pathname) { case '/article_inner.asp': mediaTitle = document.evaluate('//div[@class="name"]/h1/text()', document, null, XPathResult.STRING_TYPE, null ); mediaDescription = document.evaluate('//div[@class="article_container"]/div/text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue; break; case '/article.asp': mediaTitle = document.evaluate('//div[@class="s_title"]/text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue; break; case '/stage1_inner.asp': mediaTitle = document.evaluate('//div[@class="s_title"]//text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue; break; default: mediaTitle = document.evaluate('//div[@class="inner_title"]//span/text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue; } break; case 'www.nevo.co.il': mediaTitle = document.evaluate('//meta[@name="LAWNAME"]/@content', document, null, XPathResult.STRING_TYPE, null ); mediaDescription = document.evaluate('//meta[@name="NOSE1"]/@content', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue; break; case 'openclipart.org': mediaTitle = document.evaluate('//h2[@itemprop="name"]/text()', document, null, XPathResult.STRING_TYPE, null ); mediaDescription = document.evaluate('//dd[@itemprop="articleBody"]/text()', document, null, XPathResult.STRING_TYPE, null ); mediaUploader = document.evaluate('//span[@itemprop="name"]/text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = 'Clipart - ' + mediaTitle.stringValue + ' (by ' + mediaUploader.stringValue + ')'; break; case 'sourceforge.net': //mediaTitle = document.evaluate('//h1[@itemprop="name"]/text()', document, null, XPathResult.STRING_TYPE, null ); mediaTitle = document.evaluate('//h1/text()', document, null, XPathResult.STRING_TYPE, null ); //mediaDescription = document.evaluate('//p[@id="description"]/text()', document, null, XPathResult.STRING_TYPE, null ); mediaDescription = document.evaluate('normalize-space(//h3[@class="summary"]/text())', document, null, XPathResult.STRING_TYPE, null ); //mediaUploader = document.evaluate('//p[@id="maintainers"]/a//text()', document, null, XPathResult.STRING_TYPE, null ); mediaUploader = document.evaluate('//h3[@class="brought-by"]//a/text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue + ' (by ' + mediaUploader.stringValue + ')'; break; case 'torrentz2.me': mediaTitle = document.evaluate('//h2/span/text()', document, null, XPathResult.STRING_TYPE, null ); mediaAvailability = document.evaluate('//h2/text()', document, null, XPathResult.STRING_TYPE, null ); //mediaDescription is not working mediaDescription = document.evaluate('//div[@class="download"]/div/span/@title', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue + ' (available in ' + mediaAvailability.stringValue + ')'; break; case 'www.youtube.com': mediaTitle = document.evaluate('//h1/text()', document, null, XPathResult.STRING_TYPE, null ); mediaDescription = document.evaluate('//div[@id="content"]//text()', document, null, XPathResult.STRING_TYPE, null ); mediaUploader = document.evaluate('//div[@id="owner-container"]//text()', document, null, XPathResult.STRING_TYPE, null ); pageTitle = mediaTitle.stringValue + ' (by ' + mediaUploader.stringValue + ')'; break; } document.title = pageTitle; //loop through and find the element you want for (var i = 0; i < metaElements.length; i++) { if (metaElements[i].getAttribute('name') == 'description') { if (mediaDescription == null) { //remove element metaElements[i].parentNode.removeChild(metaElements[i]); } else { //make necessary changes metaElements[i].setAttribute('content', mediaDescription.stringValue); } //stop loop upon action break; } }
Re: @GreenLunar:
Is this discussion subject a statement or are you asking a question?
Assuming a question, based off what you said (some buzz words detected) of:
... means one should probably be using a MutationObserver to detect changes in the DOM and probably attempting to run the .user.js as soon as possible with
@run-at
in the UserScript metadata block. How you parse the DOM fragments is up to you at that point.