MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / findPostName

Function findPostName

scripts/insta_injectDownloadBtn.js:686–716  ·  view source on GitHub ↗
(articleNode)

Source from the content-addressed store, hash-verified

684 }
685
686 function findPostName(articleNode) {
687 // this grabs the username link that is visually in the author's post comment below the media
688 // 'article section' includes the likes section and comment box
689 // '+ * a' pulls the first element after the section that contains a link (comment box doesn't)
690 // '[href^="/"][href$="/"]' requires the href attribute to begin and end with a slash to match a username
691 let imgNoCanvas = articleNode.querySelector(
692 'article section + * a[href^="/"][href$="/"]'
693 );
694 if (imgNoCanvas) {
695 return imgNoCanvas;
696 }
697
698 // videos are handled differently
699 let imgAlt = articleNode.querySelector("canvas ~ * img");
700 if (imgAlt) {
701 imgAlt = imgAlt.getAttribute("alt");
702 let links = articleNode.querySelectorAll("a");
703 for (let i = 0; i < links.length; i++) {
704 const posterName = links[i]
705 .getAttribute("href")
706 .replace(/\//g, "");
707 if (imgAlt.includes(posterName)) {
708 return links[i];
709 }
710 }
711 } else {
712 // first H2 with a direction set
713 const el = document.querySelector("h2[dir]");
714 return el.innerText;
715 }
716 }
717
718 function findPostId(articleNode) {
719 let aNodes = articleNode.querySelectorAll("a");

Callers 1

postOnClickedFunction · 0.85

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected