Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eoureo/208bf6f37ff4faa903d01f3605cda59f to your computer and use it in GitHub Desktop.
Save eoureo/208bf6f37ff4faa903d01f3605cda59f to your computer and use it in GitHub Desktop.
Fix Obsidian Web Clipper Bookmarklet - CORS issue in a crazy way. 옵시디언 Web Clipper Bookmarklet 고침 - CORS 문제 해결. 무식한 방법.
javascript:(function(){
/* Optional vault name */
const vault = "V-07";
/* Optional folder name such as "Clippings/" */
const folder = "Scraps/";
/* Optional tags */
const tags = "#clippings";
const Turndown = set_Turndown();
const Readability = set_Readability();
function getSelectionHtml() {
var html = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
html = container.innerHTML;
}
} else if (typeof document.selection != "undefined") {
if (document.selection.type == "Text") {
html = document.selection.createRange().htmlText;
}
}
return html;
}
const selection = getSelectionHtml();
const {
title,
byline,
content
} = new Readability(document.cloneNode(true)).parse();
function getFileName(fileName) {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
if (windowsPlatforms.indexOf(platform) !== -1) {
fileName = fileName.replace(':', '').replace(/[/\\?%*|"<>]/g, '-');
} else {
fileName = fileName.replace(':', '').replace(/\//g, '-').replace(/\\/g, '-');
}
return fileName;
}
const fileName = getFileName(title);
if (selection) {
var markdownify = selection;
} else {
var markdownify = content;
}
if (vault) {
var vaultName = '&vault=' + encodeURIComponent(`${vault}`);
} else {
var vaultName = '';
}
const markdownBody = new Turndown({
headingStyle: 'atx',
hr: '---',
bulletListMarker: '-',
codeBlockStyle: 'fenced',
emDelimiter: '*',
}).turndown(markdownify);
var date = new Date();
function convertDate(date) {
var yyyy = date.getFullYear().toString();
var mm = (date.getMonth()+1).toString();
var dd = date.getDate().toString();
var mmChars = mm.split('');
var ddChars = dd.split('');
return yyyy + '-' + (mmChars[1]?mm:"0"+mmChars[0]) + '-' + (ddChars[1]?dd:"0"+ddChars[0]);
}
const today = convertDate(date);
const fileContent =
"author:: " + byline + "\n"
+ "source:: [" + title + "](" + document.URL + ")\n"
+ "clipped:: [[" + today + "]]\n"
+ "published:: \n\n"
+ tags + "\n\n"
+ markdownBody ;
document.location.href = "obsidian://new?"
+ "file=" + encodeURIComponent(folder + fileName)
+ "&content=" + encodeURIComponent(fileContent)
+ "&append"
+ vaultName ;
function set_Turndown(){
/* https://unpkg.com/turndown@6.0.0?module */
function extend(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}return e}function repeat(e,n){return Array(n+1).join(e)}var blockElements=["address","article","aside","audio","blockquote","body","canvas","center","dd","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frameset","h1","h2","h3","h4","h5","h6","header","hgroup","hr","html","isindex","li","main","menu","nav","noframes","noscript","ol","output","p","pre","section","table","tbody","td","tfoot","th","thead","tr","ul"];function isBlock(e){return-1!==blockElements.indexOf(e.nodeName.toLowerCase())}var voidElements=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"];function isVoid(e){return-1!==voidElements.indexOf(e.nodeName.toLowerCase())}var voidSelector=voidElements.join();function hasVoid(e){return e.querySelector&&e.querySelector(voidSelector)}var rules={};function Rules(e){for(var n in this.options=e,this._keep=[],this._remove=[],this.blankRule={replacement:e.blankReplacement},this.keepReplacement=e.keepReplacement,this.defaultRule={replacement:e.defaultReplacement},this.array=[],e.rules)this.array.push(e.rules[n])}function findRule(e,n,t){for(var r=0;r<e.length;r++){var i=e[r];if(filterValue(i,n,t))return i}}function filterValue(e,n,t){var r=e.filter;if("string"==typeof r){if(r===n.nodeName.toLowerCase())return!0}else if(Array.isArray(r)){if(r.indexOf(n.nodeName.toLowerCase())>-1)return!0}else{if("function"!=typeof r)throw new TypeError("`filter` needs to be a string, array, or function");if(r.call(e,n,t))return!0}}function collapseWhitespace(e){var n=e.element,t=e.isBlock,r=e.isVoid,i=e.isPre||function(e){return"PRE"===e.nodeName};if(n.firstChild&&!i(n)){for(var o=null,a=!1,l=null,s=next(l,n,i);s!==n;){if(3===s.nodeType||4===s.nodeType){var u=s.data.replace(/[ \r\n\t]+/g," ");if(o&&!/ $/.test(o.data)||a||" "!==u[0]||(u=u.substr(1)),!u){s=remove(s);continue}s.data=u,o=s}else{if(1!==s.nodeType){s=remove(s);continue}t(s)||"BR"===s.nodeName?(o&&(o.data=o.data.replace(/ $/,"")),o=null,a=!1):r(s)&&(o=null,a=!0)}var c=next(l,s,i);l=s,s=c}o&&(o.data=o.data.replace(/ $/,""),o.data||remove(o))}}function remove(e){var n=e.nextSibling||e.parentNode;return e.parentNode.removeChild(e),n}function next(e,n,t){return e&&e.parentNode===n||t(n)?n.nextSibling||n.parentNode:n.firstChild||n.nextSibling||n.parentNode}rules.paragraph={filter:"p",replacement:function(e){return"\n\n"+e+"\n\n"}},rules.lineBreak={filter:"br",replacement:function(e,n,t){return t.br+"\n"}},rules.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(e,n,t){var r=Number(n.nodeName.charAt(1));return"setext"===t.headingStyle&&r<3?"\n\n"+e+"\n"+repeat(1===r?"=":"-",e.length)+"\n\n":"\n\n"+repeat("#",r)+" "+e+"\n\n"}},rules.blockquote={filter:"blockquote",replacement:function(e){return"\n\n"+(e=(e=e.replace(/^\n+|\n+$/g,"")).replace(/^/gm,"> "))+"\n\n"}},rules.list={filter:["ul","ol"],replacement:function(e,n){var t=n.parentNode;return"LI"===t.nodeName&&t.lastElementChild===n?"\n"+e:"\n\n"+e+"\n\n"}},rules.listItem={filter:"li",replacement:function(e,n,t){e=e.replace(/^\n+/,"").replace(/\n+$/,"\n").replace(/\n/gm,"\n ");var r=t.bulletListMarker+" ",i=n.parentNode;if("OL"===i.nodeName){var o=i.getAttribute("start"),a=Array.prototype.indexOf.call(i.children,n);r=(o?Number(o)+a:a+1)+". "}return r+e+(n.nextSibling&&!/\n$/.test(e)?"\n":"")}},rules.indentedCodeBlock={filter:function(e,n){return"indented"===n.codeBlockStyle&&"PRE"===e.nodeName&&e.firstChild&&"CODE"===e.firstChild.nodeName},replacement:function(e,n,t){return"\n\n "+n.firstChild.textContent.replace(/\n/g,"\n ")+"\n\n"}},rules.fencedCodeBlock={filter:function(e,n){return"fenced"===n.codeBlockStyle&&"PRE"===e.nodeName&&e.firstChild&&"CODE"===e.firstChild.nodeName},replacement:function(e,n,t){for(var r,i=((n.firstChild.className||"").match(/language-(\S+)/)||[null,""])[1],o=n.firstChild.textContent,a=t.fence.charAt(0),l=3,s=new RegExp("^"+a+"{3,}","gm");r=s.exec(o);)r[0].length>=l&&(l=r[0].length+1);var u=repeat(a,l);return"\n\n"+u+i+"\n"+o.replace(/\n$/,"")+"\n"+u+"\n\n"}},rules.horizontalRule={filter:"hr",replacement:function(e,n,t){return"\n\n"+t.hr+"\n\n"}},rules.inlineLink={filter:function(e,n){return"inlined"===n.linkStyle&&"A"===e.nodeName&&e.getAttribute("href")},replacement:function(e,n){return"["+e+"]("+n.getAttribute("href")+(n.title?' "'+n.title+'"':"")+")"}},rules.referenceLink={filter:function(e,n){return"referenced"===n.linkStyle&&"A"===e.nodeName&&e.getAttribute("href")},replacement:function(e,n,t){var r,i,o=n.getAttribute("href"),a=n.title?' "'+n.title+'"':"";switch(t.linkReferenceStyle){case"collapsed":r="["+e+"][]",i="["+e+"]: "+o+a;break;case"shortcut":r="["+e+"]",i="["+e+"]: "+o+a;break;default:var l=this.references.length+1;r="["+e+"]["+l+"]",i="["+l+"]: "+o+a}return this.references.push(i),r},references:[],append:function(e){var n="";return this.references.length&&(n="\n\n"+this.references.join("\n")+"\n\n",this.references=[]),n}},rules.emphasis={filter:["em","i"],replacement:function(e,n,t){return e.trim()?t.emDelimiter+e+t.emDelimiter:""}},rules.strong={filter:["strong","b"],replacement:function(e,n,t){return e.trim()?t.strongDelimiter+e+t.strongDelimiter:""}},rules.code={filter:function(e){var n=e.previousSibling||e.nextSibling,t="PRE"===e.parentNode.nodeName&&!n;return"CODE"===e.nodeName&&!t},replacement:function(e){if(!e.trim())return"";var n="`",t="",r="",i=e.match(/`+/gm);if(i)for(/^`/.test(e)&&(t=" "),/`$/.test(e)&&(r=" ");-1!==i.indexOf(n);)n+="`";return n+t+e+r+n}},rules.image={filter:"img",replacement:function(e,n){var t=n.alt||"",r=n.getAttribute("src")||"",i=n.title||"";return r?"!["+t+"]("+r+(i?' "'+i+'"':"")+")":""}},Rules.prototype={add:function(e,n){this.array.unshift(n)},keep:function(e){this._keep.unshift({filter:e,replacement:this.keepReplacement})},remove:function(e){this._remove.unshift({filter:e,replacement:function(){return""}})},forNode:function(e){return e.isBlank?this.blankRule:(n=findRule(this.array,e,this.options))||(n=findRule(this._keep,e,this.options))||(n=findRule(this._remove,e,this.options))?n:this.defaultRule;var n},forEach:function(e){for(var n=0;n<this.array.length;n++)e(this.array[n],n)}};var root="undefined"!=typeof window?window:{};function canParseHTMLNatively(){var e=root.DOMParser,n=!1;try{(new e).parseFromString("","text/html")&&(n=!0)}catch(e){}return n}function createHTMLParser(){var e=function(){},n=require("jsdom").JSDOM;return e.prototype.parseFromString=function(e){return new n(e).window.document},e}var _htmlParser,HTMLParser=canParseHTMLNatively()?root.DOMParser:createHTMLParser();function RootNode(e){var n;"string"==typeof e?n=htmlParser().parseFromString('<x-turndown id="turndown-root">'+e+"</x-turndown>","text/html").getElementById("turndown-root"):n=e.cloneNode(!0);return collapseWhitespace({element:n,isBlock:isBlock,isVoid:isVoid}),n}function htmlParser(){return _htmlParser=_htmlParser||new HTMLParser}function Node(e){return e.isBlock=isBlock(e),e.isCode="code"===e.nodeName.toLowerCase()||e.parentNode.isCode,e.isBlank=isBlank(e),e.flankingWhitespace=flankingWhitespace(e),e}function isBlank(e){return-1===["A","TH","TD","IFRAME","SCRIPT","AUDIO","VIDEO"].indexOf(e.nodeName)&&/^\s*$/i.test(e.textContent)&&!isVoid(e)&&!hasVoid(e)}function flankingWhitespace(e){var n="",t="";if(!e.isBlock){var r=/^\s/.test(e.textContent),i=/\s$/.test(e.textContent),o=e.isBlank&&r&&i;r&&!isFlankedByWhitespace("left",e)&&(n=" "),o||!i||isFlankedByWhitespace("right",e)||(t=" ")}return{leading:n,trailing:t}}function isFlankedByWhitespace(e,n){var t,r,i;return"left"===e?(t=n.previousSibling,r=/ $/):(t=n.nextSibling,r=/^ /),t&&(3===t.nodeType?i=r.test(t.nodeValue):1!==t.nodeType||isBlock(t)||(i=r.test(t.textContent))),i}var reduce=Array.prototype.reduce,leadingNewLinesRegExp=/^\n*/,trailingNewLinesRegExp=/\n*$/,escapes=[[/\\/g,"\\\\"],[/\*/g,"\\*"],[/^-/g,"\\-"],[/^\+ /g,"\\+ "],[/^(=+)/g,"\\$1"],[/^(#{1,6}) /g,"\\$1 "],[/`/g,"\\`"],[/^~~~/g,"\\~~~"],[/\[/g,"\\["],[/\]/g,"\\]"],[/^>/g,"\\>"],[/_/g,"\\_"],[/^(\d+)\. /g,"$1\\. "]];function TurndownService(e){if(!(this instanceof TurndownService))return new TurndownService(e);var n={rules:rules,headingStyle:"setext",hr:"* * *",bulletListMarker:"*",codeBlockStyle:"indented",fence:"```",emDelimiter:"_",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",br:" ",blankReplacement:function(e,n){return n.isBlock?"\n\n":""},keepReplacement:function(e,n){return n.isBlock?"\n\n"+n.outerHTML+"\n\n":n.outerHTML},defaultReplacement:function(e,n){return n.isBlock?"\n\n"+e+"\n\n":e}};this.options=extend({},n,e),this.rules=new Rules(this.options)}function process(e){var n=this;return reduce.call(e.childNodes,(function(e,t){var r="";return 3===(t=new Node(t)).nodeType?r=t.isCode?t.nodeValue:n.escape(t.nodeValue):1===t.nodeType&&(r=replacementForNode.call(n,t)),join(e,r)}),"")}function postProcess(e){var n=this;return this.rules.forEach((function(t){"function"==typeof t.append&&(e=join(e,t.append(n.options)))})),e.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}function replacementForNode(e){var n=this.rules.forNode(e),t=process.call(this,e),r=e.flankingWhitespace;return(r.leading||r.trailing)&&(t=t.trim()),r.leading+n.replacement(t,e,this.options)+r.trailing}function separatingNewlines(e,n){var t=[e.match(trailingNewLinesRegExp)[0],n.match(leadingNewLinesRegExp)[0]].sort(),r=t[t.length-1];return r.length<2?r:"\n\n"}function join(e,n){var t=separatingNewlines(e,n);return(e=e.replace(trailingNewLinesRegExp,""))+t+(n=n.replace(leadingNewLinesRegExp,""))}function canConvert(e){return null!=e&&("string"==typeof e||e.nodeType&&(1===e.nodeType||9===e.nodeType||11===e.nodeType))}TurndownService.prototype={turndown:function(e){if(!canConvert(e))throw new TypeError(e+" is not a string, or an element/document/fragment node.");if(""===e)return"";var n=process.call(this,new RootNode(e));return postProcess.call(this,n)},use:function(e){if(Array.isArray(e))for(var n=0;n<e.length;n++)this.use(e[n]);else{if("function"!=typeof e)throw new TypeError("plugin must be a Function or an Array of Functions");e(this)}return this},addRule:function(e,n){return this.rules.add(e,n),this},keep:function(e){return this.rules.keep(e),this},remove:function(e){return this.rules.remove(e),this},escape:function(e){return escapes.reduce((function(e,n){return e.replace(n[0],n[1])}),e)}};
return TurndownService;
}
function set_Readability(){
/* https://unpkg.com/@tehshrike/readability@0.2.0 */
/* eslint-env es6:false*/
/*
* Copyright (c) 2010 Arc90 Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* This code is heavily based on Arc90's readability.js (1.7.1) script
* available at: http://code.google.com/p/arc90labs-readability
*/
/**
* Public constructor.
* @param {HTMLDocument} doc The document to parse.
* @param {Object} options The options object.
*/
function Readability(e,t){if(t&&t.documentElement)e=t,t=arguments[2];else if(!e||!e.documentElement)throw new Error("First argument to Readability constructor should be a document object.");let i;t=t||{},this._doc=e,this._docJSDOMParser=this._doc.firstChild.__JSDOMParser__,this._articleTitle=null,this._articleByline=null,this._articleDir=null,this._articleSiteName=null,this._attempts=[],this._debug=!!t.debug,this._maxElemsToParse=t.maxElemsToParse||this.DEFAULT_MAX_ELEMS_TO_PARSE,this._nbTopCandidates=t.nbTopCandidates||this.DEFAULT_N_TOP_CANDIDATES,this._charThreshold=t.charThreshold||this.DEFAULT_CHAR_THRESHOLD,this._classesToPreserve=this.CLASSES_TO_PRESERVE.concat(t.classesToPreserve||[]),this._keepClasses=!!t.keepClasses,this._flags=this.FLAG_STRIP_UNLIKELYS|this.FLAG_WEIGHT_CLASSES|this.FLAG_CLEAN_CONDITIONALLY,this._debug?(i=function(e){const t=e.nodeName+" ";if(e.nodeType==e.TEXT_NODE)return t+'("'+e.textContent+'")';const i=e.className&&"."+e.className.replace(/ /g,".");let s="";return e.id?s="(#"+e.id+i+")":i&&(s="("+i+")"),t+s},this.log=function(){if("undefined"!=typeof dump){const e=Array.prototype.map.call(arguments,(e=>e&&e.nodeName?i(e):e)).join(" ");dump("Reader: (Readability) "+e+"\n")}else if("undefined"!=typeof console){const e=["Reader: (Readability) "].concat(arguments);console.log.apply(console,e)}}):this.log=function(){}}Readability.prototype={FLAG_STRIP_UNLIKELYS:1,FLAG_WEIGHT_CLASSES:2,FLAG_CLEAN_CONDITIONALLY:4,ELEMENT_NODE:1,TEXT_NODE:3,DEFAULT_MAX_ELEMS_TO_PARSE:0,DEFAULT_N_TOP_CANDIDATES:5,DEFAULT_TAGS_TO_SCORE:"section,h2,h3,h4,h5,h6,p,td,pre".toUpperCase().split(","),DEFAULT_CHAR_THRESHOLD:500,REGEXPS:{unlikelyCandidates:/-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i,okMaybeItsACandidate:/and|article|body|column|content|main|shadow/i,positive:/article|body|content|entry|hentry|h-entry|main|page|pagination|post|text|blog|story/i,negative:/hidden|^hid$| hid$| hid |^hid |banner|combx|comment|com-|contact|foot|footer|footnote|gdpr|masthead|media|meta|outbrain|promo|related|scroll|share|shoutbox|sidebar|skyscraper|sponsor|shopping|tags|tool|widget/i,extraneous:/print|archive|comment|discuss|e[\-]?mail|share|reply|all|login|sign|single|utility/i,byline:/byline|author|dateline|writtenby|p-author/i,replaceFonts:/<(\/?)font[^>]*>/gi,normalize:/\s{2,}/g,videos:/\/\/(www\.)?((dailymotion|youtube|youtube-nocookie|player\.vimeo|v\.qq)\.com|(archive|upload\.wikimedia)\.org|player\.twitch\.tv)/i,shareElements:/(\b|_)(share|sharedaddy)(\b|_)/i,nextLink:/(next|weiter|continue|>([^\|]|$)|»([^\|]|$))/i,prevLink:/(prev|earl|old|new|<|«)/i,whitespace:/^\s*$/,hasContent:/\S$/,srcsetUrl:/(\S+)(\s+[\d.]+[xw])?(\s*(?:,|$))/g,b64DataUrl:/^data:\s*([^\s;,]+)\s*;\s*base64\s*,/i},DIV_TO_P_ELEMS:["A","BLOCKQUOTE","DL","DIV","IMG","OL","P","PRE","TABLE","UL","SELECT"],ALTER_TO_DIV_EXCEPTIONS:["DIV","ARTICLE","SECTION","P"],PRESENTATIONAL_ATTRIBUTES:["align","background","bgcolor","border","cellpadding","cellspacing","frame","hspace","rules","style","valign","vspace"],DEPRECATED_SIZE_ATTRIBUTE_ELEMS:["TABLE","TH","TD","HR","PRE"],PHRASING_ELEMS:["ABBR","AUDIO","B","BDO","BR","BUTTON","CITE","CODE","DATA","DATALIST","DFN","EM","EMBED","I","IMG","INPUT","KBD","LABEL","MARK","MATH","METER","NOSCRIPT","OBJECT","OUTPUT","PROGRESS","Q","RUBY","SAMP","SCRIPT","SELECT","SMALL","SPAN","STRONG","SUB","SUP","TEXTAREA","TIME","VAR","WBR"],CLASSES_TO_PRESERVE:["page"],HTML_ESCAPE_MAP:{lt:"<",gt:">",amp:"&",quot:'"',apos:"'"},_postProcessContent(e){this._fixRelativeUris(e),this._keepClasses||this._cleanClasses(e)},_removeNodes(e,t){if(this._docJSDOMParser&&e._isLiveNodeList)throw new Error("Do not pass live node lists to _removeNodes");for(let i=e.length-1;i>=0;i--){const s=e[i],n=s.parentNode;n&&(t&&!t.call(this,s,i,e)||n.removeChild(s))}},_replaceNodeTags(e,t){if(this._docJSDOMParser&&e._isLiveNodeList)throw new Error("Do not pass live node lists to _replaceNodeTags");for(let i=e.length-1;i>=0;i--){const s=e[i];this._setNodeTag(s,t)}},_forEachNode(e,t){Array.prototype.forEach.call(e,t,this)},_someNode(e,t){return Array.prototype.some.call(e,t,this)},_everyNode(e,t){return Array.prototype.every.call(e,t,this)},_concatNodeLists(){const e=Array.prototype.slice,t=e.call(arguments).map((t=>e.call(t)));return Array.prototype.concat.apply([],t)},_getAllNodesWithTag:(e,t)=>e.querySelectorAll?e.querySelectorAll(t.join(",")):[].concat.apply([],t.map((t=>{const i=e.getElementsByTagName(t);return Array.isArray(i)?i:Array.from(i)}))),_cleanClasses(e){const t=this._classesToPreserve,i=(e.getAttribute("class")||"").split(/\s+/).filter((e=>-1!=t.indexOf(e))).join(" ");for(i?e.setAttribute("class",i):e.removeAttribute("class"),e=e.firstElementChild;e;e=e.nextElementSibling)this._cleanClasses(e)},_fixRelativeUris(e){const t=this._doc.baseURI,i=this._doc.documentURI;function s(e){if(t==i&&"#"==e.charAt(0))return e;try{return new URL(e,t).href}catch(e){}return e}const n=this._getAllNodesWithTag(e,["a"]);this._forEachNode(n,(function(e){const t=e.getAttribute("href");if(t)if(0===t.indexOf("javascript:"))if(1===e.childNodes.length&&e.childNodes[0].nodeType===this.TEXT_NODE){const t=this._doc.createTextNode(e.textContent);e.parentNode.replaceChild(t,e)}else{const t=this._doc.createElement("span");for(;e.childNodes.length>0;)t.appendChild(e.childNodes[0]);e.parentNode.replaceChild(t,e)}else e.setAttribute("href",s(t))}));const a=this._getAllNodesWithTag(e,["img","picture","figure","video","audio","source"]);this._forEachNode(a,(function(e){const t=e.getAttribute("src"),i=e.getAttribute("poster"),n=e.getAttribute("srcset");if(t&&e.setAttribute("src",s(t)),i&&e.setAttribute("poster",s(i)),n){const t=n.replace(this.REGEXPS.srcsetUrl,((e,t,i,n)=>s(t)+(i||"")+n));e.setAttribute("srcset",t)}}))},_getArticleTitle(){const e=this._doc;let t="",i="";try{t=i=e.title.trim(),"string"!=typeof t&&(t=i=this._getInnerText(e.getElementsByTagName("title")[0]))}catch(e){}let s=!1;function n(e){return e.split(/\s+/).length}if(/ [\|\-\\\/>»] /.test(t))s=/ [\\\/>»] /.test(t),t=i.replace(/(.*)[\|\-\\\/>»] .*/gi,"$1"),n(t)<3&&(t=i.replace(/[^\|\-\\\/>»]*[\|\-\\\/>»](.*)/gi,"$1"));else if(-1!==t.indexOf(": ")){const s=this._concatNodeLists(e.getElementsByTagName("h1"),e.getElementsByTagName("h2")),a=t.trim();this._someNode(s,(e=>e.textContent.trim()===a))||(t=i.substring(i.lastIndexOf(":")+1),n(t)<3?t=i.substring(i.indexOf(":")+1):n(i.substr(0,i.indexOf(":")))>5&&(t=i))}else if(t.length>150||t.length<15){const i=e.getElementsByTagName("h1");1===i.length&&(t=this._getInnerText(i[0]))}t=t.trim().replace(this.REGEXPS.normalize," ");const a=n(t);return a<=4&&(!s||a!=n(i.replace(/[\|\-\\\/>»]+/g,""))-1)&&(t=i),t},_prepDocument(){const e=this._doc;this._removeNodes(this._getAllNodesWithTag(e,["style"])),e.body&&this._replaceBrs(e.body),this._replaceNodeTags(this._getAllNodesWithTag(e,["font"]),"SPAN")},_nextElement(e){let t=e;for(;t&&t.nodeType!=this.ELEMENT_NODE&&this.REGEXPS.whitespace.test(t.textContent);)t=t.nextSibling;return t},_replaceBrs(e){this._forEachNode(this._getAllNodesWithTag(e,["br"]),(function(e){let t=e.nextSibling,i=!1;for(;(t=this._nextElement(t))&&"BR"==t.tagName;){i=!0;const e=t.nextSibling;t.parentNode.removeChild(t),t=e}if(i){const i=this._doc.createElement("p");for(e.parentNode.replaceChild(i,e),t=i.nextSibling;t;){if("BR"==t.tagName){const e=this._nextElement(t.nextSibling);if(e&&"BR"==e.tagName)break}if(!this._isPhrasingContent(t))break;const e=t.nextSibling;i.appendChild(t),t=e}for(;i.lastChild&&this._isWhitespace(i.lastChild);)i.removeChild(i.lastChild);"P"===i.parentNode.tagName&&this._setNodeTag(i.parentNode,"DIV")}}))},_setNodeTag(e,t){if(this.log("_setNodeTag",e,t),this._docJSDOMParser)return e.localName=t.toLowerCase(),e.tagName=t.toUpperCase(),e;const i=e.ownerDocument.createElement(t);for(;e.firstChild;)i.appendChild(e.firstChild);e.parentNode.replaceChild(i,e),e.readability&&(i.readability=e.readability);for(let t=0;t<e.attributes.length;t++)try{i.setAttribute(e.attributes[t].name,e.attributes[t].value)}catch(e){}return i},_prepArticle(e){this._cleanStyles(e),this._markDataTables(e),this._fixLazyImages(e),this._cleanConditionally(e,"form"),this._cleanConditionally(e,"fieldset"),this._clean(e,"object"),this._clean(e,"embed"),this._clean(e,"h1"),this._clean(e,"footer"),this._clean(e,"link"),this._clean(e,"aside");const t=this.DEFAULT_CHAR_THRESHOLD;this._forEachNode(e.children,(function(e){this._cleanMatchedNodes(e,(function(e,i){return this.REGEXPS.shareElements.test(i)&&e.textContent.length<t}))}));const i=e.getElementsByTagName("h2");if(1===i.length){const t=(i[0].textContent.length-this._articleTitle.length)/this._articleTitle.length;if(Math.abs(t)<.5){let s=!1;s=t>0?i[0].textContent.includes(this._articleTitle):this._articleTitle.includes(i[0].textContent),s&&this._clean(e,"h2")}}this._clean(e,"iframe"),this._clean(e,"input"),this._clean(e,"textarea"),this._clean(e,"select"),this._clean(e,"button"),this._cleanHeaders(e),this._cleanConditionally(e,"table"),this._cleanConditionally(e,"ul"),this._cleanConditionally(e,"div"),this._removeNodes(this._getAllNodesWithTag(e,["p"]),(function(e){return 0===e.getElementsByTagName("img").length+e.getElementsByTagName("embed").length+e.getElementsByTagName("object").length+e.getElementsByTagName("iframe").length&&!this._getInnerText(e,!1)})),this._forEachNode(this._getAllNodesWithTag(e,["br"]),(function(e){const t=this._nextElement(e.nextSibling);t&&"P"==t.tagName&&e.parentNode.removeChild(e)})),this._forEachNode(this._getAllNodesWithTag(e,["table"]),(function(e){const t=this._hasSingleTagInsideElement(e,"TBODY")?e.firstElementChild:e;if(this._hasSingleTagInsideElement(t,"TR")){const i=t.firstElementChild;if(this._hasSingleTagInsideElement(i,"TD")){let t=i.firstElementChild;t=this._setNodeTag(t,this._everyNode(t.childNodes,this._isPhrasingContent)?"P":"DIV"),e.parentNode.replaceChild(t,e)}}}))},_initializeNode(e){switch(e.readability={contentScore:0},e.tagName){case"DIV":e.readability.contentScore+=5;break;case"PRE":case"TD":case"BLOCKQUOTE":e.readability.contentScore+=3;break;case"ADDRESS":case"OL":case"UL":case"DL":case"DD":case"DT":case"LI":case"FORM":e.readability.contentScore-=3;break;case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":case"TH":e.readability.contentScore-=5}e.readability.contentScore+=this._getClassWeight(e)},_removeAndGetNext(e){const t=this._getNextNode(e,!0);return e.parentNode.removeChild(e),t},_getNextNode(e,t){if(!t&&e.firstElementChild)return e.firstElementChild;if(e.nextElementSibling)return e.nextElementSibling;do{e=e.parentNode}while(e&&!e.nextElementSibling);return e&&e.nextElementSibling},_checkByline(e,t){if(this._articleByline)return!1;if(void 0!==e.getAttribute)var i=e.getAttribute("rel"),s=e.getAttribute("itemprop");return!(!("author"===i||s&&-1!==s.indexOf("author")||this.REGEXPS.byline.test(t))||!this._isValidByline(e.textContent))&&(this._articleByline=e.textContent.trim(),!0)},_getNodeAncestors(e,t){t=t||0;let i=0,s=[];for(;e.parentNode&&(s.push(e.parentNode),!t||++i!==t);)e=e.parentNode;return s},_grabArticle(e){this.log("**** grabArticle ****");const t=this._doc,i=null!==e;if(!(e=e||this._doc.body))return this.log("No body found in document. Abort."),null;const s=e.innerHTML;for(;;){const r=this._flagIsActive(this.FLAG_STRIP_UNLIKELYS),l=[];let o=this._doc.documentElement;for(;o;){const e=o.className+" "+o.id;if(this._isProbablyVisible(o))if(this._checkByline(o,e))o=this._removeAndGetNext(o);else{if(r){if(this.REGEXPS.unlikelyCandidates.test(e)&&!this.REGEXPS.okMaybeItsACandidate.test(e)&&!this._hasAncestorTag(o,"table")&&"BODY"!==o.tagName&&"A"!==o.tagName){this.log("Removing unlikely candidate - "+e),o=this._removeAndGetNext(o);continue}if("complementary"==o.getAttribute("role")){this.log("Removing complementary content - "+e),o=this._removeAndGetNext(o);continue}}if("DIV"!==o.tagName&&"SECTION"!==o.tagName&&"HEADER"!==o.tagName&&"H1"!==o.tagName&&"H2"!==o.tagName&&"H3"!==o.tagName&&"H4"!==o.tagName&&"H5"!==o.tagName&&"H6"!==o.tagName||!this._isElementWithoutContent(o)){if(-1!==this.DEFAULT_TAGS_TO_SCORE.indexOf(o.tagName)&&l.push(o),"DIV"===o.tagName){let e=null,i=o.firstChild;for(;i;){const s=i.nextSibling;if(this._isPhrasingContent(i))null!==e?e.appendChild(i):this._isWhitespace(i)||(e=t.createElement("p"),o.replaceChild(e,i),e.appendChild(i));else if(null!==e){for(;e.lastChild&&this._isWhitespace(e.lastChild);)e.removeChild(e.lastChild);e=null}i=s}if(this._hasSingleTagInsideElement(o,"P")&&this._getLinkDensity(o)<.25){const e=o.children[0];o.parentNode.replaceChild(e,o),o=e,l.push(o)}else this._hasChildBlockElement(o)||(o=this._setNodeTag(o,"P"),l.push(o))}o=this._getNextNode(o)}else o=this._removeAndGetNext(o)}else this.log("Removing hidden node - "+e),o=this._removeAndGetNext(o)}var n=[];this._forEachNode(l,(function(e){if(!e.parentNode||void 0===e.parentNode.tagName)return;const t=this._getInnerText(e);if(t.length<25)return;const i=this._getNodeAncestors(e,3);if(0===i.length)return;let s=0;s+=1,s+=t.split(",").length,s+=Math.min(Math.floor(t.length/100),3),this._forEachNode(i,(function(e,t){if(e.tagName&&e.parentNode&&void 0!==e.parentNode.tagName){if(void 0===e.readability&&(this._initializeNode(e),n.push(e)),0===t)var i=1;else i=1===t?2:3*t;e.readability.contentScore+=s/i}}))}));const h=[];for(let e=0,t=n.length;e<t;e+=1){const t=n[e],i=t.readability.contentScore*(1-this._getLinkDensity(t));t.readability.contentScore=i,this.log("Candidate:",t,"with score "+i);for(let e=0;e<this._nbTopCandidates;e++){const s=h[e];if(!s||i>s.readability.contentScore){h.splice(e,0,t),h.length>this._nbTopCandidates&&h.pop();break}}}let c=h[0]||null,d=!1;var a;if(null===c||"BODY"===c.tagName){c=t.createElement("DIV"),d=!0;const i=e.childNodes;for(;i.length;)this.log("Moving child out:",i[0]),c.appendChild(i[0]);e.appendChild(c),this._initializeNode(c)}else if(c){const e=[];for(let t=1;t<h.length;t++)h[t].readability.contentScore/c.readability.contentScore>=.75&&e.push(this._getNodeAncestors(h[t]));const t=3;if(e.length>=t)for(a=c.parentNode;"BODY"!==a.tagName;){let i=0;for(let s=0;s<e.length&&i<t;s++)i+=Number(e[s].includes(a));if(i>=t){c=a;break}a=a.parentNode}c.readability||this._initializeNode(c),a=c.parentNode;let i=c.readability.contentScore;const s=i/3;for(;"BODY"!==a.tagName;){if(!a.readability){a=a.parentNode;continue}const e=a.readability.contentScore;if(e<s)break;if(e>i){c=a;break}i=a.readability.contentScore,a=a.parentNode}for(a=c.parentNode;"BODY"!=a.tagName&&1==a.children.length;)c=a,a=c.parentNode;c.readability||this._initializeNode(c)}let g=t.createElement("DIV");i&&(g.id="readability-content");const _=Math.max(10,.2*c.readability.contentScore),m=(a=c.parentNode).children;for(let e=0,t=m.length;e<t;e++){let i=m[e],s=!1;if(this.log("Looking at sibling node:",i,i.readability?"with score "+i.readability.contentScore:""),this.log("Sibling has score",i.readability?i.readability.contentScore:"Unknown"),i===c)s=!0;else{let e=0;if(i.className===c.className&&""!==c.className&&(e+=.2*c.readability.contentScore),i.readability&&i.readability.contentScore+e>=_)s=!0;else if("P"===i.nodeName){const e=this._getLinkDensity(i),t=this._getInnerText(i),n=t.length;(n>80&&e<.25||n<80&&n>0&&0===e&&-1!==t.search(/\.( |$)/))&&(s=!0)}}s&&(this.log("Appending node:",i),-1===this.ALTER_TO_DIV_EXCEPTIONS.indexOf(i.nodeName)&&(this.log("Altering sibling:",i,"to div."),i=this._setNodeTag(i,"DIV")),g.appendChild(i),e-=1,t-=1)}if(this._debug&&this.log("Article content pre-prep: "+g.innerHTML),this._prepArticle(g),this._debug&&this.log("Article content post-prep: "+g.innerHTML),d)c.id="readability-page-1",c.className="page";else{const e=t.createElement("DIV");e.id="readability-page-1",e.className="page";const i=g.childNodes;for(;i.length;)e.appendChild(i[0]);g.appendChild(e)}this._debug&&this.log("Article content after paging: "+g.innerHTML);let p=!0;const u=this._getInnerText(g,!0).length;if(u<this._charThreshold)if(p=!1,e.innerHTML=s,this._flagIsActive(this.FLAG_STRIP_UNLIKELYS))this._removeFlag(this.FLAG_STRIP_UNLIKELYS),this._attempts.push({articleContent:g,textLength:u});else if(this._flagIsActive(this.FLAG_WEIGHT_CLASSES))this._removeFlag(this.FLAG_WEIGHT_CLASSES),this._attempts.push({articleContent:g,textLength:u});else if(this._flagIsActive(this.FLAG_CLEAN_CONDITIONALLY))this._removeFlag(this.FLAG_CLEAN_CONDITIONALLY),this._attempts.push({articleContent:g,textLength:u});else{if(this._attempts.push({articleContent:g,textLength:u}),this._attempts.sort(((e,t)=>t.textLength-e.textLength)),!this._attempts[0].textLength)return null;g=this._attempts[0].articleContent,p=!0}if(p){const e=[a,c].concat(this._getNodeAncestors(a));return this._someNode(e,(function(e){if(!e.tagName)return!1;const t=e.getAttribute("dir");return!!t&&(this._articleDir=t,!0)})),g}}},_isValidByline:e=>("string"==typeof e||e instanceof String)&&((e=e.trim()).length>0&&e.length<100),_unescapeHtmlEntities(e){if(!e)return e;const t=this.HTML_ESCAPE_MAP;return e.replace(/&(quot|amp|apos|lt|gt);/g,((e,i)=>t[i])).replace(/&#(?:x([0-9a-z]{1,4})|([0-9]{1,4}));/gi,((e,t,i)=>{const s=parseInt(t||i,t?16:10);return String.fromCharCode(s)}))},_getArticleMetadata(){const e={},t={},i=this._doc.getElementsByTagName("meta"),s=/\s*(dc|dcterm|og|twitter)\s*:\s*(author|creator|description|title|site_name)\s*/gi,n=/^\s*(?:(dc|dcterm|og|twitter|weibo:(article|webpage))\s*[\.:]\s*)?(author|creator|description|title|site_name)\s*$/i;return this._forEachNode(i,(e=>{const i=e.getAttribute("name"),a=e.getAttribute("property"),r=e.getAttribute("content");if(!r)return;let l=null,o=null;if(a&&(l=a.match(s),l))for(let e=l.length-1;e>=0;e--)o=l[e].toLowerCase().replace(/\s/g,""),t[o]=r.trim();!l&&i&&n.test(i)&&(o=i,r&&(o=o.toLowerCase().replace(/\s/g,"").replace(/\./g,":"),t[o]=r.trim()))})),e.title=t["dc:title"]||t["dcterm:title"]||t["og:title"]||t["weibo:article:title"]||t["weibo:webpage:title"]||t.title||t["twitter:title"],e.title||(e.title=this._getArticleTitle()),e.byline=t["dc:creator"]||t["dcterm:creator"]||t.author,e.excerpt=t["dc:description"]||t["dcterm:description"]||t["og:description"]||t["weibo:article:description"]||t["weibo:webpage:description"]||t.description||t["twitter:description"],e.siteName=t["og:site_name"],e.title=this._unescapeHtmlEntities(e.title),e.byline=this._unescapeHtmlEntities(e.byline),e.excerpt=this._unescapeHtmlEntities(e.excerpt),e.siteName=this._unescapeHtmlEntities(e.siteName),e},_isSingleImage(e){return"IMG"===e.tagName||1===e.children.length&&""===e.textContent.trim()&&this._isSingleImage(e.children[0])},_unwrapNoscriptImages(e){const t=Array.from(e.getElementsByTagName("img"));this._forEachNode(t,(e=>{for(let t=0;t<e.attributes.length;t++){const i=e.attributes[t];switch(i.name){case"src":case"srcset":case"data-src":case"data-srcset":return}if(/\.(jpg|jpeg|png|webp)/i.test(i.value))return}e.parentNode.removeChild(e)}));const i=Array.from(e.getElementsByTagName("noscript"));this._forEachNode(i,(function(t){const i=e.createElement("div");if(i.innerHTML=t.innerHTML,!this._isSingleImage(i))return;const s=t.previousElementSibling;if(s&&this._isSingleImage(s)){let e=s;"IMG"!==e.tagName&&(e=s.getElementsByTagName("img")[0]);const n=i.getElementsByTagName("img")[0];for(let t=0;t<e.attributes.length;t++){const i=e.attributes[t];if(""!==i.value&&("src"===i.name||"srcset"===i.name||/\.(jpg|jpeg|png|webp)/i.test(i.value))){if(n.getAttribute(i.name)===i.value)continue;let e=i.name;n.hasAttribute(e)&&(e="data-old-"+e),n.setAttribute(e,i.value)}}t.parentNode.replaceChild(i.firstElementChild,s)}}))},_removeScripts(e){this._removeNodes(this._getAllNodesWithTag(e,["script"]),(e=>(e.nodeValue="",e.removeAttribute("src"),!0))),this._removeNodes(this._getAllNodesWithTag(e,["noscript"]))},_hasSingleTagInsideElement(e,t){return 1==e.children.length&&e.children[0].tagName===t&&!this._someNode(e.childNodes,(function(e){return e.nodeType===this.TEXT_NODE&&this.REGEXPS.hasContent.test(e.textContent)}))},_isElementWithoutContent(e){return e.nodeType===this.ELEMENT_NODE&&0==e.textContent.trim().length&&(0==e.children.length||e.children.length==e.getElementsByTagName("br").length+e.getElementsByTagName("hr").length)},_hasChildBlockElement(e){return this._someNode(e.childNodes,(function(e){return-1!==this.DIV_TO_P_ELEMS.indexOf(e.tagName)||this._hasChildBlockElement(e)}))},_isPhrasingContent(e){return e.nodeType===this.TEXT_NODE||-1!==this.PHRASING_ELEMS.indexOf(e.tagName)||("A"===e.tagName||"DEL"===e.tagName||"INS"===e.tagName)&&this._everyNode(e.childNodes,this._isPhrasingContent)},_isWhitespace(e){return e.nodeType===this.TEXT_NODE&&0===e.textContent.trim().length||e.nodeType===this.ELEMENT_NODE&&"BR"===e.tagName},_getInnerText(e,t){t=void 0===t||t;const i=e.textContent.trim();return t?i.replace(this.REGEXPS.normalize," "):i},_getCharCount(e,t){return t=t||",",this._getInnerText(e).split(t).length-1},_cleanStyles(e){if(!e||"svg"===e.tagName.toLowerCase())return;for(let t=0;t<this.PRESENTATIONAL_ATTRIBUTES.length;t++)e.removeAttribute(this.PRESENTATIONAL_ATTRIBUTES[t]);-1!==this.DEPRECATED_SIZE_ATTRIBUTE_ELEMS.indexOf(e.tagName)&&(e.removeAttribute("width"),e.removeAttribute("height"));let t=e.firstElementChild;for(;null!==t;)this._cleanStyles(t),t=t.nextElementSibling},_getLinkDensity(e){const t=this._getInnerText(e).length;if(0===t)return 0;let i=0;return this._forEachNode(e.getElementsByTagName("a"),(function(e){i+=this._getInnerText(e).length})),i/t},_getClassWeight(e){if(!this._flagIsActive(this.FLAG_WEIGHT_CLASSES))return 0;let t=0;return"string"==typeof e.className&&""!==e.className&&(this.REGEXPS.negative.test(e.className)&&(t-=25),this.REGEXPS.positive.test(e.className)&&(t+=25)),"string"==typeof e.id&&""!==e.id&&(this.REGEXPS.negative.test(e.id)&&(t-=25),this.REGEXPS.positive.test(e.id)&&(t+=25)),t},_clean(e,t){const i=-1!==["object","embed","iframe"].indexOf(t);this._removeNodes(this._getAllNodesWithTag(e,[t]),(function(e){if(i){for(let t=0;t<e.attributes.length;t++)if(this.REGEXPS.videos.test(e.attributes[t].value))return!1;if("object"===e.tagName&&this.REGEXPS.videos.test(e.innerHTML))return!1}return!0}))},_hasAncestorTag(e,t,i,s){i=i||3,t=t.toUpperCase();let n=0;for(;e.parentNode;){if(i>0&&n>i)return!1;if(e.parentNode.tagName===t&&(!s||s(e.parentNode)))return!0;e=e.parentNode,n++}return!1},_getRowAndColumnCount(e){let t=0,i=0;const s=e.getElementsByTagName("tr");for(let e=0;e<s.length;e++){let n=s[e].getAttribute("rowspan")||0;n&&(n=parseInt(n,10)),t+=n||1;let a=0;const r=s[e].getElementsByTagName("td");for(let e=0;e<r.length;e++){let t=r[e].getAttribute("colspan")||0;t&&(t=parseInt(t,10)),a+=t||1}i=Math.max(i,a)}return{rows:t,columns:i}},_markDataTables(e){const t=e.getElementsByTagName("table");for(let e=0;e<t.length;e++){var i=t[e];if("presentation"==i.getAttribute("role")){i._readabilityDataTable=!1;continue}if("0"==i.getAttribute("datatable")){i._readabilityDataTable=!1;continue}if(i.getAttribute("summary")){i._readabilityDataTable=!0;continue}const s=i.getElementsByTagName("caption")[0];if(s&&s.childNodes.length>0){i._readabilityDataTable=!0;continue}if(["col","colgroup","tfoot","thead","th"].some((function(e){return!!i.getElementsByTagName(e)[0]}))){this.log("Data table because found data-y descendant"),i._readabilityDataTable=!0;continue}if(i.getElementsByTagName("table")[0]){i._readabilityDataTable=!1;continue}const n=this._getRowAndColumnCount(i);n.rows>=10||n.columns>4?i._readabilityDataTable=!0:i._readabilityDataTable=n.rows*n.columns>10}},_fixLazyImages(e){this._forEachNode(this._getAllNodesWithTag(e,["img","picture","figure"]),(function(e){if(e.src&&this.REGEXPS.b64DataUrl.test(e.src)){if("image/svg+xml"===this.REGEXPS.b64DataUrl.exec(e.src)[1])return;let i=!1;for(let s=0;s<e.attributes.length;s++){var t=e.attributes[s];if("src"!==t.name&&/\.(jpg|jpeg|png|webp)/i.test(t.value)){i=!0;break}}if(i){const t=e.src.search(/base64\s*/i)+7;e.src.length-t<133&&e.removeAttribute("src")}}if(!(e.src||e.srcset&&"null"!=e.srcset)||-1!==e.className.toLowerCase().indexOf("lazy"))for(let i=0;i<e.attributes.length;i++){if("src"===(t=e.attributes[i]).name||"srcset"===t.name)continue;let s=null;if(/\.(jpg|jpeg|png|webp)\s+\d/.test(t.value)?s="srcset":/^\s*\S+\.(jpg|jpeg|png|webp)\S*\s*$/.test(t.value)&&(s="src"),s)if("IMG"===e.tagName||"PICTURE"===e.tagName)e.setAttribute(s,t.value);else if("FIGURE"===e.tagName&&!this._getAllNodesWithTag(e,["img","picture"]).length){const i=this._doc.createElement("img");i.setAttribute(s,t.value),e.appendChild(i)}}}))},_cleanConditionally(e,t){if(!this._flagIsActive(this.FLAG_CLEAN_CONDITIONALLY))return;const i="ul"===t||"ol"===t;this._removeNodes(this._getAllNodesWithTag(e,[t]),(function(e){const s=function(e){return e._readabilityDataTable};if("table"===t&&s(e))return!1;if(this._hasAncestorTag(e,"table",-1,s))return!1;const n=this._getClassWeight(e);if(this.log("Cleaning Conditionally",e),n+0<0)return!0;if(this._getCharCount(e,",")<10){const t=e.getElementsByTagName("p").length,s=e.getElementsByTagName("img").length,a=e.getElementsByTagName("li").length-100,r=e.getElementsByTagName("input").length;let l=0;const o=this._getAllNodesWithTag(e,["object","embed","iframe"]);for(let e=0;e<o.length;e++){for(let t=0;t<o[e].attributes.length;t++)if(this.REGEXPS.videos.test(o[e].attributes[t].value))return!1;if("object"===o[e].tagName&&this.REGEXPS.videos.test(o[e].innerHTML))return!1;l++}const h=this._getLinkDensity(e),c=this._getInnerText(e).length;return s>1&&t/s<.5&&!this._hasAncestorTag(e,"figure")||!i&&a>t||r>Math.floor(t/3)||!i&&c<25&&(0===s||s>2)&&!this._hasAncestorTag(e,"figure")||!i&&n<25&&h>.2||n>=25&&h>.5||1===l&&c<75||l>1}return!1}))},_cleanMatchedNodes(e,t){const i=this._getNextNode(e,!0);let s=this._getNextNode(e);for(;s&&s!=i;)s=t.call(this,s,s.className+" "+s.id)?this._removeAndGetNext(s):this._getNextNode(s)},_cleanHeaders(e){this._removeNodes(this._getAllNodesWithTag(e,["h1","h2"]),(function(e){return this._getClassWeight(e)<0}))},_flagIsActive(e){return(this._flags&e)>0},_removeFlag(e){this._flags=this._flags&~e},_isProbablyVisible:e=>(!e.style||"none"!=e.style.display)&&!e.hasAttribute("hidden")&&(!e.hasAttribute("aria-hidden")||"true"!=e.getAttribute("aria-hidden")||e.className&&e.className.indexOf&&-1!==e.className.indexOf("fallback-image")),parse(){if(this._maxElemsToParse>0){const e=this._doc.getElementsByTagName("*").length;if(e>this._maxElemsToParse)throw new Error("Aborting parsing document; "+e+" elements found")}this._unwrapNoscriptImages(this._doc),this._removeScripts(this._doc),this._prepDocument();const e=this._getArticleMetadata();this._articleTitle=e.title;const t=this._grabArticle();if(!t)return null;if(this.log("Grabbed: "+t.innerHTML),this._postProcessContent(t),!e.excerpt){const i=t.getElementsByTagName("p");i.length>0&&(e.excerpt=i[0].textContent.trim())}const i=t.textContent;return{title:this._articleTitle,byline:e.byline||this._articleByline,dir:this._articleDir,content:t.innerHTML,textContent:i,length:i.length,excerpt:e.excerpt,siteName:e.siteName||this._articleSiteName}}};
return Readability;
}
})();
@eoureo
Copy link
Author

eoureo commented Apr 1, 2023

제 블로그 글 옵시디언 Web Clipper Bookmarklet 고침 - CORS 문제 해결에서 내용을 볼 수 있습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment