circle-ihk
Advanced tools
Comparing version 1.0.10 to 1.0.11
import { App } from '../interface'; | ||
export default function pageInfo(app: App, exportFromDOMOrString?: string | HTMLElement): { | ||
export default function pageInfo(app: App, exportFromDOMOrString?: string | HTMLElement, format?: boolean): { | ||
url: string; | ||
@@ -4,0 +4,0 @@ content: HTMLElement; |
import url from './url'; | ||
import nodeText from './node-text'; | ||
import formatNode from './format-node'; | ||
import { isElement, isString } from './is'; | ||
export default function pageInfo(app, exportFromDOMOrString) { | ||
export default function pageInfo(app, exportFromDOMOrString, format = true) { | ||
const returnValue = { | ||
@@ -57,3 +58,6 @@ url: url(), | ||
} | ||
if (format && isElement(returnValue.content)) { | ||
returnValue.content = formatNode(app, returnValue.content); | ||
} | ||
return returnValue; | ||
} |
import url from './url'; | ||
import each from './each'; | ||
import formatNode from './format-node'; | ||
import { isElement, isString } from './is'; | ||
import iterator from './iterator'; | ||
function formatFN(app, node) { | ||
const images = node.getElementsByTagName('img'); | ||
if (images.length > 0) { | ||
const contentClone = iterator(node); | ||
const container = app.field('container'); | ||
if (isElement(container) && | ||
container.style.cssText.indexOf('imagehide: none') >= 0) { | ||
each(contentClone.getElementsByTagName('img'), (item) => item && item.parentElement && item.parentElement.removeChild(item)); | ||
} | ||
else { | ||
each(contentClone.getElementsByTagName('img'), (item) => { | ||
const target = item._mirrorElement && item._mirrorElement._mirrorElement | ||
? item._mirrorElement._mirrorElement | ||
: item; | ||
const attrToRemove = []; | ||
each(item.attributes, (attribute) => { | ||
const name = attribute.nodeName; | ||
!['class', 'src'].includes(name) && attrToRemove.push(name); | ||
}); | ||
each(attrToRemove, (attr) => { | ||
item.removeAttribute(attr); | ||
}); | ||
const width = Math.min(target.width, 410); | ||
item.width = width; | ||
item.height = target.height * (width / target.width); | ||
item.src = item.src.replace('https', 'http'); | ||
}); | ||
} | ||
return contentClone; | ||
} | ||
return node; | ||
} | ||
export default function pageNode(app, format = true) { | ||
@@ -48,3 +15,3 @@ const data = app.field('node'); | ||
else if (isElement(node.content)) { | ||
data += (format ? formatFN(app, node.content) : node.content) | ||
data += (format ? formatNode(app, node.content) : node.content) | ||
.innerHTML; | ||
@@ -58,3 +25,3 @@ } | ||
else if (isElement(item.content)) { | ||
item.content = format ? formatFN(app, item.content) : item.content; | ||
item.content = format ? formatNode(app, item.content) : item.content; | ||
} | ||
@@ -61,0 +28,0 @@ if (!item.title) { |
{ | ||
"name": "circle-ihk", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Circle Reader Component Library", |
50214
63
1459