PageSourceSearch

https://www.wolframscience.com/common/js/c2c/1.0/WolframC2C.js

js wolframscience.com collected 2026-10-02 02:16:14 UTC 6,639 bytes, 1 lines download raw bytes

1class WolframC2C{file="";inline="";uniqueCounter=0;uniqueIdPrefix="";selectable=null;fileCache={};fallbackData=null;validTypes=["text/plain","text/html","image/png"];stringTypes=["text/plain","text/html"];clipboardApiTypes=["image/png"];constructor(e="data-C2C-file",t="data-C2C-Inline",i="wolframC2C-"){if(!this.setDataFileAttribute(e))throw new Error("file is invalid");if(!this.setInlineAttribute(t))throw new Error("inline is invalid");if(!this.setUniqueIdPrefix(i))throw new Error("inline is uniqueIdPrefix");let l=this;document.addEventListener("copy",(function(e){l.useExecCommandCopyHandler(e)}))}generateUniqueId(){return this.uniqueIdPrefix+this.uniqueCounter++}setUniqueIdPrefix(e){if("string"==typeof e){if(/^[A-Za-z]+[\w\-\:\.]*$/.test(e))return this.uniqueIdPrefix=e,!0}return!1}setDataFileAttribute(e){return!("string"!=typeof e||!e.startsWith("data-"))&&(this.file=e,!0)}setInlineAttribute(e){return!("string"!=typeof e||!e.startsWith("data-"))&&(this.inline=e,!0)}quantifyUrl(e){if(e.startsWith("http:")||e.startsWith("https:"))return e;let t=new URL(window.location.href);if(e.startsWith("//"))return t.protocol+e;if(e.startsWith("/"))return t.protocol+"//"+t.host+e;let i=t.pathname.split("/"),l=i[i.length-1];if(""===l){let l=i.join("/");return t.protocol+"//"+t.host+l+e}let s=["html","php","cgi"],a=["en","de","es","fr","ja","ko","pt-br","ru","zh","zh-tw"];for(var n=0;n<s.length;n++)if(l.endsWith("."+s[n])){i.pop();let l=i.join("/");return t.protocol+"//"+t.host+l+"/"+e}for(n=0;n<s.length;n++)for(var r=0;r<a.length;r++)if(l.endsWith("."+s[n]+"."+a[r])||l.endsWith("."+a[r]+"."+s[n])){i.pop();let l=i.join("/");return t.protocol+"//"+t.host+l+"/"+e}return e}async getFile(e,t,i){e=this.quantifyUrl(e);let l=this;try{let s=await fetch(e);if(200==s.status){let e=await s.arrayBuffer();l.cacheFile(e,t,i)}
1else l.cacheFile(!1,t,i)}catch(e){l.cacheFile(!1,t,i)}}cacheFile(e,t,i){if(!1!==e)return this.fileCache[t]=e,void(null!==i&&i({id:t,status:!0,message:"the file has been cached"}));null!==i&&i({id:t,status:!1,message:"the file failed to load"})}cacheFileById(e,t=null){let i=document.getElementById(e);if(null===i)return void(null!==t&&t({id:e,status:!1,message:"id does not exist"}));if(this.isFileInCache(e))return void(null!==t&&t({id:e,status:!0,message:"the file is already cached"}));if(void 0===i.attributes)return void(null!==t&&t({id:e,status:!1,message:"element has no attributes"}));let l=i.getAttribute(this.file);null!==l?this.getFile(l,e,t):null!==t&&t({id:e,status:!1,message:"element does not have the "+this.file+" attribute"})}cacheFileByClass(e,t=null){let i=document.getElementsByClassName(e);if(0!==i.length)for(var l=0;l<i.length;l++)null===i[l].getAttribute("id")&&(i[l].id=this.generateUniqueId()),this.cacheFileById(i[l].id,t);else null!==t&&t({id:null,status:!1,message:"no elements with class "+e+" found"})}cacheFileByElement(e,t=null){null===e.getAttribute("id")&&(e.id=this.generateUniqueId()),this.cacheFileById(e.id,t)}isFileInCache(e){return!!this.fileCache.hasOwnProperty(e)}uncacheFileById(e,t=null){if(this.fileCache.hasOwnProperty(e))return delete this.fileCache[e],void(null!==t&&t({id:e,status:!0,message:"the file has been removed from cache"}));null!==t&&t({id:e,status:!1,message:"the file was not in cache"})}uncacheFileByClass(e,t=null){let i=document.getElementsByClassName(e);if(0!==i.length)for(var l=0;l<i.length;l++){let e=i[l].getAttribute("id");null!==e&&this.uncacheFileById(e,t)}else null!==t&&t({id:null,status:!1,message:"no elements with class "+e+" found"})}uncacheFileByElement(e,t=null){let i=e.getAttribute("id");null!==i&&this.uncacheFileById(i,t)}clipboardApiSupported(){return"undefined"!=typeof ClipboardItem&&void 0!==navigator.clipboard}async useClipboardApi(e,t,i,l=null){if(!this.clipboardApiTypes.includes(t)||this.clipboardApiSupported())if(this.clipboardApiSupported()){let s=await new Blob([e],{type:t}),a=[new ClipboardItem({[t]:s})];navigator.clipboard.write(a).then((function(){null!==l&&l({id:i,status:!0,message:"the data has been copied to the clipboard"})}),(function(e){null!==l&&l({id:i,status:!1,message:"the data failed to copy to the clipboard using the clipboard api"})}))}else this.useExecCommand(e,t,i,l);else null!==l&&l({id:i,status:!1,message:"support for the clipboard api is required for this action"})}useExecCommand(e,t,i,l=null){this.fallbackData={data:e,type:t,id:i,callback:l};let s=document.execCommand("copy");!0!==s?(this.makeselectableElement(),s=document.execCommand("copy"),!0!==s?null!==l&&l({id:i,status:!1,message:"the data failed to copy to the clipboard"}):null!==l&&l({id:i,status:!0,message:"the data has been copied to the clipboard"})):null!==l&&l({id:i,status:!0,message:"the data has been copied to the clipboard"})}makeselectableElement(){null===this.selectable&&(this.selectable=document.createElement("textarea"),this.selectable.style.position="absolute",this.selectable.style.left="-9999px",this.selectable.style.top="0",this.selectable.id=this.selectableId,this.selectable.textContent="placeholder text to select",document.body.appendChild(this.selectable)),this.selectable.select()}useExecCommandCopyHandler(e){null!=this.fallbackData&&(e.clipboardData.setData(this.fallbackData.type,this.fallbackData.data),e.preventDefault(),this.fallbackData=null)}copytoClipboard(e,t,i,l=null){if(this.validTypes.includes(t)){if(this.stringTypes.includes(t)&&"string"!=typeof e&&(e=(new TextDecoder).decode(new Uint8Array(e))),"text/html"===t){let t=e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/\'/g,"&#039;");e.replace(/</g,"&lt;").replace(/>/g,"&gt;");e='<span data-expression="'+t+'">'+e+"</span>"}this.useClipboardApi(e,t,i,l)}else null!==l&&l({id:i,status:!1,message:"type is not a valid value"})}copyById(e,t,i=null){let l=document.getElementById(e);if(null===l)return void(null!==i&&i({id:e,status:!1,message:"id does not exist"}));if(this.isFileInCache(e))return void this.copytoClipboard(this.fileCache[e],t,e,i);if(void 0===l.attributes)return void(null!==i&&i({id:e,status:!1,message:"element has no attributes"}));
1let s=l.getAttribute(this.inline);null!==s?this.copytoClipboard(s,t,e,i):null!==i&&i({id:e,status:!1,message:"element is not in cache, and does not have the "+this.inline+" attribute"})}copyByClass(e,t,i=null){let l=document.getElementsByClassName(e);0!==l.length?(null===l[0].getAttribute("id")&&(l[0].id=this.generateUniqueId()),this.copyById(l[0].id,t,i)):null!==i&&i({id:null,status:!1,message:"no elements with class "+e+" found"})}copyByElement(e,t,i=null){null===e.getAttribute("id")&&(e.id=this.generateUniqueId()),this.copyById(e.id,t,i)}}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.