1 line
4.6 KiB
JavaScript
1 line
4.6 KiB
JavaScript
"use strict";!function(){const e={};function t(t){const n=t.tagName.toLowerCase();if("iframe"===n){const n=e[t.src];if(!n)return;const o=document.createElement("div");o.className="omnivore-instagram-embed",o.innerHTML=n;const r=t.parentNode;if(!r)return;return void r.replaceChild(o,t)}if("img"===n||"image"===n){if(-1===window.getComputedStyle(t).getPropertyValue("filter").indexOf("blur("))return;return void t.remove()}const o=window.getComputedStyle(t),r=o.getPropertyValue("background-image");if(r&&"none"!==r)return;const i=o.getPropertyValue("filter");if(i&&-1!==i.indexOf("blur("))return void t.remove();if(t.src)return;if(t.innerHTML.length>24)return;const a=/url\("(.+?)"\)/gi,c=a.exec(r);a.lastIndex=0;const l=c&&c[1];if(!l)return;const s=document.createElement("img");s.src=l;const d=t.parentNode;d&&d.replaceChild(s,t)}function n(){const e=document.createElement("div");e.style.position="absolute",e.style.left="-2000px",e.style.zIndex="-2000",e.innerHTML=document.body.innerHTML,document.documentElement.appendChild(e),Array.from(e.getElementsByTagName("*")).forEach(t);const n=`<html><head>${document.head.innerHTML}</head><body>${e.innerHTML}</body></html>`;return e.remove(),n}browserApi.runtime.onMessage.addListener((({action:t,payload:n},o,r)=>{if(t!==ACTIONS.AddIframeContent)return;const{url:i,content:a}=n;e[i]=a,r({})}));const o=e=>{const t=/^(a|b|basefont|bdo|big|em|font|i|s|small|span|strike|strong|su[bp]|tt|u|code|mark)$/i;let n="";const o=r=>{let i=!1;const a=r instanceof HTMLElement?r:r.parentElement;if(a&&(i=window.getComputedStyle(a).whiteSpace.startsWith("pre")),3==r.nodeType){const e=i?r.nodeValue:r.nodeValue.replace(/\n/g,"");n+=e}else r!=e&&(t.test(r.tagName)||(n+="\n\n"));r.childNodes.forEach((function(e){o(e)}))};return o(e),n.trim()};function r(){const e=document.querySelectorAll(".webext-omnivore-backdrop");for(let t=0;t<e.length;t++)e[t].style.setProperty("opacity","0","important");setTimeout((()=>{for(let t=0;t<e.length;t++)e[t].remove()}),500)}window.prepareContent=async function(e){const t=await async function(){const e=".pdf"===window.location.pathname.slice(-4).toLowerCase(),t=-1!==["application/acrobat","application/pdf","application/x-pdf","applications/vnd.pdf","text/pdf","text/x-pdf"].indexOf(document.contentType);if(!e&&!t)return Promise.resolve(null);const n=document.querySelector("embed");return n&&"application/pdf"!==n.type?Promise.resolve(null):ENV_DOES_NOT_SUPPORT_BLOB_URL_ACCESS&&n.src?Promise.resolve({type:"url",uploadContentObjUrl:n.src}):new Promise(((e,t)=>{const n=new XMLHttpRequest;n.open("GET","",!0),n.responseType="blob",n.onload=function(n){200===this.status?e({type:"pdf",uploadContentObjUrl:URL.createObjectURL(this.response)}):t(n)},n.send()}))}();if(t)return t;const i=window.location.href;try{if(!e&&handleBackendUrl(i))return{type:"url"}}catch{console.log("error checking url")}if(console.log("get content: ",e),e){console.log("creating highlight while saving");const e=(()=>{try{const e=window.document.querySelectorAll('span[data-omnivore-highlight-start="true"],\n span[data-omnivore-highlight-end="true"]');for(let t=0;t<e.length;t++)e[t].remove()}catch(e){console.log("remove marker error: ",e)}try{const r=window.getSelection();if(r.rangeCount){const i=r.getRangeAt(0),a=document.createElement("span"),c=document.createElement("span");a.setAttribute("data-omnivore-highlight-end","true"),c.setAttribute("data-omnivore-highlight-start","true");for(var e=document.createElement("div"),t=0,n=r.rangeCount;t<n;++t)e.appendChild(r.getRangeAt(t).cloneContents());const l=i.cloneRange();return l.collapse(!1),l.insertNode(a),i.insertNode(c),{highlightHTML:e.innerHTML,highlightText:o(e)}}}catch(e){console.log("get text error",e)}return null})();console.log("highlightSelection",e)}return await async function(e){const t=document.scrollingElement||document.body,n=t.scrollTop,o=t.scrollHeight;r();const i=function(){const e=document.createElement("div");return e.className="webext-omnivore-backdrop",e.style.cssText="all: initial !important;\n position: fixed !important;\n top: 0 !important;\n right: 0 !important;\n bottom: 0 !important;\n left: 0 !important;\n z-index: 99999 !important;\n background: #fff !important;\n opacity: 0.8 !important;\n transition: opacity 0.3s !important;\n -webkit-backdrop-filter: blur(4px) !important;\n backdrop-filter: blur(4px) !important;\n ",e}();for(document.body.appendChild(i);t.scrollTop<=o-500&&window.location.href===e;){const e=t.scrollTop;if(t.scrollTop+=500,await new Promise((e=>{setTimeout(e,10)})),t.scrollTop===e)break}t.scrollTop=n,await new Promise((e=>{setTimeout(e,10)}))}(i),r(),{type:"html",content:n()}}}(); |