the.mk-site/the_files/wombat.js

22 lines
124 KiB
JavaScript
Raw Permalink Normal View History

2024-06-15 13:40:07 -04:00
/*
Wombat.js client-side rewriting engine for web archive replay
Copyright (C) 2014-2023 Webrecorder Software, Rhizome, and Contributors. Released under the GNU Affero General Public License.
This file is part of wombat.js, see https://github.com/webrecorder/wombat.js for the full source
Wombat.js is part of the Webrecorder project (https://github.com/webrecorder)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
(function(){"use strict";function FuncMap(){this._map=[]}function ensureNumber(maybeNumber){try{switch(typeof maybeNumber){case"number":case"bigint":return maybeNumber;}var converted=Number(maybeNumber);return isNaN(converted)?null:converted}catch(e){}return null}function addToStringTagToClass(clazz,tag){typeof self.Symbol!=="undefined"&&typeof self.Symbol.toStringTag!=="undefined"&&Object.defineProperty(clazz.prototype,self.Symbol.toStringTag,{value:tag,enumerable:false})}function autobind(clazz){for(var prop,propValue,proto=clazz.__proto__||clazz.constructor.prototype||clazz.prototype,clazzProps=Object.getOwnPropertyNames(proto),len=clazzProps.length,i=0;i<len;i++)prop=clazzProps[i],propValue=clazz[prop],prop!=="constructor"&&typeof propValue==="function"&&(clazz[prop]=propValue.bind(clazz))}function Storage(wombat,type,initData){if(ThrowExceptions.yes)throw new TypeError("Illegal constructor");if(initData&&initData.length)for(var i=0;i<initData.length;i++)this[initData[i][0]]=initData[i][1].toString();Object.defineProperty(this,WOMBAT,{value:wombat,enumerable:false}),Object.defineProperty(this,TYPE,{value:type,enumerable:false})}function storageProxyHandler(){return{get:function(target,prop){var proto=target.__proto__;if(prop==="__proto__")return proto;if(proto.hasOwnProperty(prop)||proto.__proto__&&proto.__proto__.hasOwnProperty(prop)){var res=target[prop];return typeof res==="function"&&(res=res.bind(target)),res}return target.hasOwnProperty(prop)?target.getItem(prop):undefined},set:function(target,prop,value){return target.__proto__.hasOwnProperty(prop)?(target[prop]=value,true):(target.setItem(prop,value),true)}}}function createStorage(wombat,type,initData){var storage=new Storage(wombat,type,initData);return wombat.$wbwindow.Proxy&&(storage=new wombat.$wbwindow.Proxy(storage,storageProxyHandler())),wombat.defGetterProp(wombat.$wbwindow,type,function(){return storage}),storage}function WombatLocation(orig_loc,wombat){for(var prop in Object.defineProperties(this,{_orig_loc:{configurable:true,enumerable:false,value:orig_loc},wombat:{configurable:true,enumerable:false,value:wombat},orig_getter:{enumerable:false,value:function(prop){return this._orig_loc[prop]}},orig_setter:{enumerable:false,value:function(prop,value){this._orig_loc[prop]=value}}}),wombat.initLocOverride(this,this.orig_setter,this.orig_getter),wombat.setLoc(this,orig_loc.href),orig_loc)this.hasOwnProperty(prop)||typeof orig_loc[prop]==="function"||(this[prop]=orig_loc[prop])}function AutoFetcher(wombat,config){return this instanceof AutoFetcher?void(this.elemSelector="img[srcset], img[data-srcset], img[data-src], video[srcset], video[data-srcset], video[data-src], audio[srcset], audio[data-srcset], audio[data-src], picture > source[srcset], picture > source[data-srcset], picture > source[data-src], video > source[srcset], video > source[data-srcset], video > source[data-src], audio > source[srcset], audio > source[data-srcset], audio > source[data-src]",this.wombat=wombat,this.$wbwindow=wombat.$wbwindow,this.worker=null,autobind(this),this._initWorker(config)):new AutoFetcher(wombat,config)}function wrapSameOriginEventListener(origListener,win){return function wrappedSameOriginEventListener(event){return window==win?origListener(event):void 0}}function wrapEventListener(origListener,obj,wombat){var origListenerFunc;return origListenerFunc=typeof origListener==="function"?origListener:typeof origListener==="object"?origListener.handleEvent.bind(origListener):function(){},function wrappedEventListener(event){var ne;if(event.data&&event.data.from&&event.data.message){if(event.data.to_origin!=="*"&&obj.WB_wombat_location&&!wombat.startsWith(event.data.to_origin,obj.WB_wombat_location.origin))return void console.warn("Skipping message event to "+event.data.to_origin+" doesn't start with origin "+obj.WB_wombat_location.origin);var source=event.source;event.data.from_top?source=obj.__WB_top_frame:event.data.src_id&&obj.__WB_win_id&&obj.__WB_win_id[event.data.src_id]&&(source=obj.__WB_win_id[event.data.src_id]),ne=new MessageEvent("message",{bubbles:event.bu