Skip to content

Commit

Permalink
o
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Jun 25, 2020
1 parent 1ce6664 commit 7b0bbd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "font-extractor",
"version": "1.1.3",
"version": "1.1.4",
"description": "",
"main": "dist/index",
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions src/headless.ls
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ getText = (page,url,fontName,scrollElementSelector) ->>
e.scrollBy(0, e.scrollHeight,behavior: 'auto')
while e.scrollHeight - e.scrollTop != e.offsetHeight
handle = new Function("eles","""
return eles.filter((e)=> window.getComputedStyle(e).getPropertyValue("font-family").includes('#{fontName}')).reduce( ( (p,c)=> p+= c.textContent ),"" ).split("").filter( (v,i,s)=> s.indexOf(v) === i )
return eles.filter((e)=> window.getComputedStyle(e).getPropertyValue("font-family").split(",").map( (x) => x.trim() ).includes('#{fontName}')).reduce( ( (p,c)=> p+= c.textContent ),"" ).split("").filter( (v,i,s)=> s.indexOf(v) === i )
""")
if scrollElementSelector
await page.waitFor 100
Expand Down Expand Up @@ -43,14 +43,18 @@ export collect = (entry,fontName,scrollElement) ->>
pages = []
filtered = hrefs.filter (x) -> x.startsWith("http")
for href in filtered
url = new URL(href)
url = ""
try
url = new URL(href)
catch
continue
urlS = url.toString!
if visited.indexOf(urlS) == -1 and url.origin == entryURL.origin
pages.push urlS
while p = pages.shift!
text = text ++ await getText(page,p,fontName)
visited.push p
text = text.filter( (v,i,s)-> s.indexOf(v) === i )#.join("")
text = text.filter( (v,i,s)-> s.indexOf(v) === i )
console.log text
await page.close()
await browser.close()
Expand Down

0 comments on commit 7b0bbd3

Please sign in to comment.