Skip to content

Instantly share code, notes, and snippets.

@gijigae
Created October 10, 2022 04:23
Show Gist options
  • Save gijigae/861dff43579c3e17b403543855d75a40 to your computer and use it in GitHub Desktop.
Save gijigae/861dff43579c3e17b403543855d75a40 to your computer and use it in GitHub Desktop.
Newsela to Roam without Lexile
javascript:void function(){const a=document.querySelector("%23article-title").textContent,b=document.querySelector("h2[data-qa-selector=article_label_text]").textContent,c=document.querySelector("div span[data-qa-selector=word_count]").textContent,e=document.querySelector("article img").getAttribute("src"),f=document.evaluate("//span[text()='Published:']",document,null,XPathResult.ANY_TYPE,null),g=f.iterateNext(),h=new Date(g.nextElementSibling.textContent),i=(a=>{const b=a.getFullYear(),c=a.toLocaleString("en-us",{month:"long"}),d=(a=>a+(0<a%3F["th","st","nd","rd"][3<a%26%2621>a||3<a%2510%3F0:a%2510]:""))(a.getDate());return`${c} ${d}, ${b}`})(h),j=document.querySelectorAll("div[data-qa-selector=article_text] p,div[data-qa-selector=article_text] h2");let k=location.href;try{k=document.querySelector("link[rel='canonical']").getAttribute("href")}catch(a){console.log("canonical url is not found.")}const l=[`- Topic: %23[[${b}]]`,`Words: ${c}`,`Source: ${k}`,`![](${e})\n- `];let m=l.join("\n- "),o=!1;const p=a=>{const b=a%3F4:2;return" ".repeat(b)};j.forEach(a=>{const b="H2"===a.tagName,c=null!==a.querySelector("img");b%26%26(o=!1);let d=b%3F`%23%23 ${a.textContent}`:a.textContent;if(c){const b=a.querySelector("img").getAttribute("src");d=`![](${b})\n- ${d}`}m+=`${p(o)} ${d}\n- `,b%26%26(o=!0)}),navigator.clipboard.writeText(m)}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment