tablink
Version:
Dispatch data and events to other browser tabs on the same domain.
3 lines (2 loc) • 919 B
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.tablink=n()}(this,function(){var e="TABLINK",n={},t=new Set,o=(crypto||msCrypto).getRandomValues(new Uint16Array(5)).join("-");function r(r){if(r.key===e&&null!==r.newValue){var i=JSON.parse(r.newValue),a=i.type,u=i.message;if(o===i.tabId)return;(n[a]||[]).forEach(function(e){return e(u)}),t.forEach(function(e){return e(a,u)})}}return window.addEventListener("storage",r),{dispatch:function(n,t,i){void 0===i&&(i=!1);var a={tabId:o,type:n,message:t};i&&delete a.tabId,a=JSON.stringify(a),i&&r({key:e,newValue:a}),window.localStorage.setItem(e,a),localStorage.removeItem(e)},on:function(e,t){return n[e]||(n[e]=new Set),n[e].add(t),function(){return n[e].delete(t)}},subscribe:function(e){return t.add(e),function(){return t.delete(e)}}}});
//# sourceMappingURL=tablink.umd.js.map