Browse Source

默认携带信息到插件页,针对数据同步的逻辑优化,原来事件监听的方式不靠谱,直接换成页面加载完成后再主动去索取,这样能减少很多console error

[email protected] 3 năm trước cách đây
mục cha
commit
23be95e178

+ 9 - 12
apps/background/background.js

@@ -197,18 +197,16 @@ let BgPageInstance = (function () {
                     }
                 }
 
-                let messageData = {
-                    type: MSG_TYPE.TAB_CREATED_OR_UPDATED,
-                    content: withContent,
-                    event: tool
-                };
                 if (!isOpened) {
                     chrome.tabs.create({
                         url: `/${tool}/index.html` + (query ? "?" + query : ''),
                         active: true
-                    }).then(tab => { FeJson[tab.id] = messageData; });
+                    }).then(tab => { FeJson[tab.id] = { content: withContent }; });
                 } else {
-                    chrome.tabs.update(tabId, {highlighted: true}).then(tab => { FeJson[tab.id] = messageData; });
+                    chrome.tabs.update(tabId, {highlighted: true}).then(tab => {
+                        FeJson[tab.id] = { content: withContent };
+                        chrome.tabs.reload(tabId);
+                    });
                 }
 
             });
@@ -345,6 +343,10 @@ let BgPageInstance = (function () {
                             query: `mode=decode`
                         });
                         break;
+                    case 'request-page-content':
+                        request.params = FeJson[request.tabId];
+                        delete FeJson[request.tabId];
+                        break;
                 }
                 callback && callback(request.params);
             } else {
@@ -363,11 +365,6 @@ let BgPageInstance = (function () {
                 if(/^(http(s)?|file):\/\//.test(tab.url) && blacklist.every(reg => !reg.test(tab.url))){
                     injectScriptIfTabExists(tabId, { code: `window.__FH_TAB_ID__=${tabId};` });
                     _injectContentScripts(tabId);
-                }else if(/^chrome\-extension\:\/\//.test(tab.url)){
-                    if(FeJson[tab.id]) {
-                        chrome.runtime.sendMessage(FeJson[tab.id]);
-                        delete FeJson[tab.id];
-                    }
                 }
             }
         });

+ 3 - 6
apps/background/menu.js

@@ -68,7 +68,7 @@ export default (function () {
                     toolMap[tool].menuConfig[0].onClick = function (info, tab) {
                         chrome.scripting.executeScript({
                             target: {tabId:tab.id,allFrames:false},
-                            args: [info.linkUrl || info.srcUrl || info.selectionText || info.pageUrl],
+                            args: [info.linkUrl || info.srcUrl || info.selectionText || info.pageUrl || tab.url],
                             func: (text) => text
                         }, resp => chrome.DynamicToolRunner({
                             tool, withContent: resp[0].result
@@ -123,14 +123,12 @@ export default (function () {
                 parentId: FeJson.contextMenuId
             });
 
-            chrome.contextMenus.onClicked.addListener(((tName,mId,mFunc) => (info, tab) => {
+            chrome.contextMenus.onClicked.addListener(((tool,mId,mFunc) => (info, tab) => {
                 if(info.menuItemId === mId) {
                     if(mFunc) {
                         mFunc(info,tab);
                     }else{
-                        chrome.DynamicToolRunner({
-                            query: `tool=${tName}`
-                        });
+                        chrome.DynamicToolRunner({ tool });
                     }
                 }
             })(toolName,_menu_id,menu.onClick));
@@ -202,7 +200,6 @@ export default (function () {
      */
     let _createOrRemoveContextMenu = function (_settings) {
         _settings.getOptions((opts) => {
-            console.log(String(opts['OPT_ITEM_CONTEXTMENUS']))
             if (String(opts['OPT_ITEM_CONTEXTMENUS']) !== 'false') {
                 _createContextMenu();
             } else {

+ 26 - 25
apps/code-beautify/content-script.js

@@ -1,9 +1,9 @@
 
-let highlightWebWorker = () => {
+window.codebeautifyContentScript = (() => {
     let __importScript = (filename) => {
         let url = filename;
 
-        if (location.protocol === 'chrome-extension:' || typeof chrome !='undefined' && chrome.runtime && chrome.runtime.getURL) {
+        if (location.protocol === 'chrome-extension:' || chrome.runtime && chrome.runtime.getURL) {
             url = chrome.runtime.getURL('code-beautify/' + filename);
         }
         fetch(url).then(resp => resp.text()).then(jsText => {
@@ -16,34 +16,35 @@ let highlightWebWorker = () => {
         });
     };
 
-    let site = 'chrome-extension://mnaedlmagdcfmejjndjhffalddfofeim';
-    __importScript(site + '/static/vendor/highlight/highlight.js');
+    __importScript('beautify.js');
+    __importScript('beautify-css.js');
 
-    self.onmessage = (event) => {
-        const result = self.hljs.highlightAuto(event.data);
-        postMessage(result.value);
-    };
-};
 
-window.codebeautifyContentScript = (() => {
-    let __importScript = (filename) => {
-        let url = filename;
+    let highlightWebWorker = () => {
+        let __importScript = (filename) => {
+            let url = filename;
 
-        if (location.protocol === 'chrome-extension:' || chrome.runtime && chrome.runtime.getURL) {
-            url = chrome.runtime.getURL('code-beautify/' + filename);
-        }
-        fetch(url).then(resp => resp.text()).then(jsText => {
-            if(window.evalCore && window.evalCore.getEvalInstance){
-                return window.evalCore.getEvalInstance(window)(jsText);
+            if (location.protocol === 'chrome-extension:' || typeof chrome !='undefined' && chrome.runtime && chrome.runtime.getURL) {
+                url = chrome.runtime.getURL('code-beautify/' + filename);
             }
-            let el = document.createElement('script');
-            el.textContent = jsText;
-            document.head.appendChild(el);
-        });
-    };
+            fetch(url).then(resp => resp.text()).then(jsText => {
+                if(window.evalCore && window.evalCore.getEvalInstance){
+                    return window.evalCore.getEvalInstance(window)(jsText);
+                }
+                let el = document.createElement('script');
+                el.textContent = jsText;
+                document.head.appendChild(el);
+            });
+        };
 
-    __importScript('beautify.js');
-    __importScript('beautify-css.js');
+        let site = 'chrome-extension://mnaedlmagdcfmejjndjhffalddfofeim';
+        __importScript(site + '/static/vendor/highlight/highlight.js');
+
+        self.onmessage = (event) => {
+            const result = self.hljs.highlightAuto(event.data);
+            postMessage(result.value);
+        };
+    };
 
     let formattedCodes = '';
 

+ 3 - 2
apps/code-beautify/index.html

@@ -51,12 +51,13 @@
         <div class="row" id="jfContent" ref="jfContentBox" v-html="resultContent"></div>
     </div>
 </div>
+<script src="../static/vendor/jquery/jquery-3.3.1.min.js"></script>
 <script type="text/javascript" src="beautify-html.js"></script>
 <script type="text/javascript" src="beautify-vk.js"></script>
-<script type="text/javascript" src="content-script.js"></script>
+<script type="text/javascript" src="beautify.js"></script>
+<script type="text/javascript" src="beautify-css.js"></script>
 <script type="text/javascript" src="../static/vendor/prism/prism.js"></script>
 <script type="text/javascript" src="index.js"></script>
 
-<script src="../static/vendor/jquery/jquery-3.3.1.min.js"></script>
 </body>
 </html>

+ 10 - 6
apps/code-beautify/index.js

@@ -13,13 +13,17 @@ new Vue({
     mounted: function () {
         // 在tab创建或者更新时候,监听事件,看看是否有参数传递过来
         if (location.protocol === 'chrome-extension:') {
-            chrome.runtime.onMessage.addListener((request, sender, callback) => {
-                if (request.type === 'TAB_CREATED_OR_UPDATED' && request.content && request.event === location.pathname.split('/')[1]) {
-                    this.sourceContent = request.content;
+            chrome.tabs.query({currentWindow: true,active: true, }, (tabs) => {
+                let activeTab = tabs.filter(tab => tab.active)[0];
+                chrome.runtime.sendMessage({
+                    type: 'fh-dynamic-any-thing',
+                    thing: 'request-page-content',
+                    tabId: activeTab.id
+                }).then(resp => {
+                    if(!resp && !resp.content) return ;
+                    this.sourceContent = resp.content;
                     this.format();
-                }
-                callback && callback();
-                return true;
+                });
             });
         }
 

+ 10 - 9
apps/en-decode/endecode-lib.js

@@ -6,7 +6,11 @@
  * 4、enDecodeTools.utf8Encode(text); 将文字进行utf-8编码并输出
  * 5、enDecodeTools.utf8Decode(text); 将经过utf-8编码的文字进行utf-8解码并输出
  */
-module.exports = (() => {
+
+ import Pako from './pako.js';
+ import Md5Utils from './md5.js';
+
+let EncodeUtils = (() => {
     //base64编码字符集
     let _base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
     //base64解码字符集
@@ -235,8 +239,7 @@ module.exports = (() => {
      * @param str
      */
     let md5 = (str) => {
-        let md5 = Tarp.require('./md5');
-        return md5(str);
+        return Md5Utils.md5(str);
     };
 
     /**
@@ -245,9 +248,8 @@ module.exports = (() => {
      * @returns {*}
      */
     let gzipEncode = str => {
-        let pako = Tarp.require('./pako');
         try {
-            return window.btoa(pako.gzip(escape(str), {to: "string"}));
+            return window.btoa(Pako.gzip(escape(str), {to: "string"}));
         } catch (e) {
             return 'Error: 当前字符串不能被Gzip加密';
         }
@@ -259,11 +261,9 @@ module.exports = (() => {
      * @returns {string}
      */
     let gzipDecode = str => {
-        let pako = Tarp.require('./pako');
-
         try {
             let charData = window.atob(str).split('').map(x => x.charCodeAt(0));
-            let data = pako.inflate(new Uint8Array(charData));
+            let data = Pako.inflate(new Uint8Array(charData));
             let result = String.fromCharCode.apply(null, new Uint16Array(data));
             try {
                 return unescape(result);
@@ -301,7 +301,7 @@ module.exports = (() => {
                     back.push((128 | (63 & code)))
                 }
             }
-            for (i = 0; i < back.length; i++) {
+            for (let i = 0; i < back.length; i++) {
                 back[i] &= 0xff;
             }
             if (isGetBytes) {
@@ -488,3 +488,4 @@ module.exports = (() => {
     };
 })();
 
+export default EncodeUtils;

+ 1 - 2
apps/en-decode/index.html

@@ -7,7 +7,6 @@
         <link rel="stylesheet" href="index.css" />
         <script type="text/javascript" src="../static/vendor/evalCore.min.js"></script>
         <script type="text/javascript" src="../static/vendor/vue/vue.js"></script>
-        <script src="../static/vendor/require/require.js"></script>
     </head>
     <body>
 
@@ -134,6 +133,6 @@
     </div>
     <script type="text/javascript" src="he.js"></script>
     <script src="../static/vendor/jquery/jquery-3.3.1.min.js"></script>
-    <script type="text/javascript" src="index.js"></script>
+    <script type="module" src="index.js"></script>
     </body>
 </html>

+ 27 - 23
apps/en-decode/index.js

@@ -1,6 +1,8 @@
 /**
  * FeHelper 信息编解码
  */
+import EncodeUtils from './endecode-lib.js';
+
 new Vue({
     el: '#pageContainer',
     data: {
@@ -14,13 +16,17 @@ new Vue({
 
         // 在tab创建或者更新时候,监听事件,看看是否有参数传递过来
         if (location.protocol === 'chrome-extension:') {
-            chrome.runtime.onMessage.addListener((request, sender, callback) => {
-                if (request.type === 'TAB_CREATED_OR_UPDATED' && request.content && request.event === location.pathname.split('/')[1]) {
-                    this.sourceContent = request.content;
+            chrome.tabs.query({currentWindow: true,active: true, }, (tabs) => {
+                let activeTab = tabs.filter(tab => tab.active)[0];
+                chrome.runtime.sendMessage({
+                    type: 'fh-dynamic-any-thing',
+                    thing: 'request-page-content',
+                    tabId: activeTab.id
+                }).then(resp => {
+                    if(!resp && !resp.content) return ;
+                    this.sourceContent = resp.content;
                     this.convert();
-                }
-                callback && callback();
-                return true;
+                });
             });
         }
 
@@ -31,14 +37,12 @@ new Vue({
             this.$nextTick(() => {
                 this.urlResult = null;
 
-                let tools = Tarp.require('./endecode-lib');
-
                 if (this.selectedType === 'uniEncode') {
 
-                    this.resultContent = tools.uniEncode(this.sourceContent);
+                    this.resultContent = EncodeUtils.uniEncode(this.sourceContent);
                 } else if (this.selectedType === 'uniDecode') {
 
-                    this.resultContent = tools.uniDecode(this.sourceContent.replace(/\\U/g, '\\u'));
+                    this.resultContent = EncodeUtils.uniDecode(this.sourceContent.replace(/\\U/g, '\\u'));
                 } else if (this.selectedType === 'utf8Encode') {
 
                     this.resultContent = encodeURIComponent(this.sourceContent);
@@ -47,37 +51,37 @@ new Vue({
                     this.resultContent = decodeURIComponent(this.sourceContent);
                 } else if (this.selectedType === 'utf16Encode') {
 
-                    this.resultContent = tools.utf8to16(encodeURIComponent(this.sourceContent));
+                    this.resultContent = EncodeUtils.utf8to16(encodeURIComponent(this.sourceContent));
                 } else if (this.selectedType === 'utf16Decode') {
 
-                    this.resultContent = decodeURIComponent(tools.utf16to8(this.sourceContent));
+                    this.resultContent = decodeURIComponent(EncodeUtils.utf16to8(this.sourceContent));
                 } else if (this.selectedType === 'base64Encode') {
 
-                    this.resultContent = tools.base64Encode(tools.utf8Encode(this.sourceContent));
+                    this.resultContent = EncodeUtils.base64Encode(EncodeUtils.utf8Encode(this.sourceContent));
                 } else if (this.selectedType === 'base64Decode') {
 
-                    this.resultContent = tools.utf8Decode(tools.base64Decode(this.sourceContent));
+                    this.resultContent = EncodeUtils.utf8Decode(EncodeUtils.base64Decode(this.sourceContent));
                 } else if (this.selectedType === 'md5Encode') {
 
-                    this.resultContent = tools.md5(this.sourceContent);
+                    this.resultContent = EncodeUtils.md5(this.sourceContent);
                 } else if (this.selectedType === 'hexEncode') {
 
-                    this.resultContent = tools.hexEncode(this.sourceContent);
+                    this.resultContent = EncodeUtils.hexEncode(this.sourceContent);
                 } else if (this.selectedType === 'hexDecode') {
 
-                    this.resultContent = tools.hexDecode(this.sourceContent);
+                    this.resultContent = EncodeUtils.hexDecode(this.sourceContent);
                 } else if (this.selectedType === 'gzipEncode') {
 
-                    this.resultContent = tools.gzipEncode(this.sourceContent);
+                    this.resultContent = EncodeUtils.gzipEncode(this.sourceContent);
                 } else if (this.selectedType === 'gzipDecode') {
 
-                    this.resultContent = tools.gzipDecode(this.sourceContent);
+                    this.resultContent = EncodeUtils.gzipDecode(this.sourceContent);
                 } else if (this.selectedType === 'html2js') {
 
-                    this.resultContent = tools.html2js(this.sourceContent);
+                    this.resultContent = EncodeUtils.html2js(this.sourceContent);
                 } else if (this.selectedType === 'sha1Encode') {
 
-                    this.resultContent = tools.sha1Encode(this.sourceContent);
+                    this.resultContent = EncodeUtils.sha1Encode(this.sourceContent);
                 } else if (this.selectedType === 'htmlEntityEncode') {
 
                     this.resultContent = he.encode(this.sourceContent, {
@@ -97,7 +101,7 @@ new Vue({
                         'isAttributeValue': false
                     });
                 } else if (this.selectedType === 'urlParamsDecode') {
-                    let res = tools.urlParamsDecode(this.sourceContent);
+                    let res = EncodeUtils.urlParamsDecode(this.sourceContent);
                     if (res.error) {
                         this.resultContent = res.error;
                     } else {
@@ -117,4 +121,4 @@ new Vue({
             this.$refs.rstCode.select();
         }
     }
-});
+});

+ 5 - 11
apps/en-decode/md5.js

@@ -19,7 +19,7 @@
 
 /* global define */
 
-;(function ($) {
+let Md5Utils = (function ($) {
     'use strict'
 
     /*
@@ -268,13 +268,7 @@
         return rawHMACMD5(key, string)
     }
 
-    if (typeof define === 'function' && define.amd) {
-        define(function () {
-            return md5
-        })
-    } else if (typeof module === 'object' && module.exports) {
-        module.exports = md5
-    } else {
-        $.md5 = md5
-    }
-})(this)
+    return {md5};
+})(this)
+
+export default Md5Utils;

+ 1 - 1
apps/en-decode/pako.js

@@ -1,4 +1,4 @@
-module.exports = (function () {
+export default (function () {
     var define, module, exports;
     return (function () {
         function r(e, n, t) {

+ 11 - 7
apps/image-base64/index.js

@@ -36,19 +36,23 @@ new Vue({
 
         // 在tab创建或者更新时候,监听事件,看看是否有参数传递过来
         if (location.protocol === 'chrome-extension:') {
-            chrome.runtime.onMessage.addListener((request, sender, callback) => {
-                if (request.type === 'TAB_CREATED_OR_UPDATED' && request.content && request.event === location.pathname.split('/')[1]) {
+            chrome.tabs.query({currentWindow: true,active: true, }, (tabs) => {
+                let activeTab = tabs.filter(tab => tab.active)[0];
+                chrome.runtime.sendMessage({
+                    type: 'fh-dynamic-any-thing',
+                    thing: 'request-page-content',
+                    tabId: activeTab.id
+                }).then(resp => {
+                    if(!resp && !resp.content) return ;
                     if (this.curType !== 'image') {
                         this.trans();
                     }
-                    this.convertOnline(request.content, flag => {
+                    this.convertOnline(resp.content, flag => {
                         if (!flag) {
-                            alert('抱歉,' + request.content + ' 对应的图片未转码成功!');
+                            alert('抱歉,' + resp.content + ' 对应的图片未转码成功!');
                         }
                     });
-                    callback && callback();
-                    return true;
-                }
+                });
             });
         }
 

+ 13 - 6
apps/json-format/index.js

@@ -62,13 +62,17 @@ new Vue({
 
         // 在tab创建或者更新时候,监听事件,看看是否有参数传递过来
         if (location.protocol === 'chrome-extension:') {
-            chrome.runtime.onMessage.addListener((request, sender, callback) => {
-                if (request.type === 'TAB_CREATED_OR_UPDATED' && request.content && request.event === location.pathname.split('/')[1]) {
-                    editor.setValue(request.content || this.defaultResultTpl);
+            chrome.tabs.query({currentWindow: true,active: true, }, (tabs) => {
+                let activeTab = tabs.filter(tab => tab.active)[0];
+                chrome.runtime.sendMessage({
+                    type: 'fh-dynamic-any-thing',
+                    thing: 'request-page-content',
+                    tabId: activeTab.id
+                }).then(resp => {
+                    if(!resp && !resp.content) return ;
+                    editor.setValue(resp.content || this.defaultResultTpl);
                     this.format();
-                    callback && callback();
-                }
-                return true;
+                });
             });
         }
     },
@@ -275,6 +279,9 @@ new Vue({
         setDemo: function () {
             let demo = '{"BigIntSupported":995815895020119788889,"date":"20180322","message":"Success !","status":200,"city":"北京","count":632,"data":{"shidu":"34%","pm25":73,"pm10":91,"quality":"良","wendu":"5","ganmao":"极少数敏感人群应减少户外活动","yesterday":{"date":"21日星期三","sunrise":"06:19","high":"高温 11.0℃","low":"低温 1.0℃","sunset":"18:26","aqi":85,"fx":"南风","fl":"<3级","type":"多云","notice":"阴晴之间,谨防紫外线侵扰"},"forecast":[{"date":"22日星期四","sunrise":"06:17","high":"高温 17.0℃","low":"低温 1.0℃","sunset":"18:27","aqi":98,"fx":"西南风","fl":"<3级","type":"晴","notice":"愿你拥有比阳光明媚的心情"},{"date":"23日星期五","sunrise":"06:16","high":"高温 18.0℃","low":"低温 5.0℃","sunset":"18:28","aqi":118,"fx":"无持续风向","fl":"<3级","type":"多云","notice":"阴晴之间,谨防紫外线侵扰"},{"date":"24日星期六","sunrise":"06:14","high":"高温 21.0℃","low":"低温 7.0℃","sunset":"18:29","aqi":52,"fx":"西南风","fl":"<3级","type":"晴","notice":"愿你拥有比阳光明媚的心情"},{"date":"25日星期日","sunrise":"06:13","high":"高温 22.0℃","low":"低温 7.0℃","sunset":"18:30","aqi":71,"fx":"西南风","fl":"<3级","type":"晴","notice":"愿你拥有比阳光明媚的心情"},{"date":"26日星期一","sunrise":"06:11","high":"高温 21.0℃","low":"低温 8.0℃","sunset":"18:31","aqi":97,"fx":"西南风","fl":"<3级","type":"多云","notice":"阴晴之间,谨防紫外线侵扰"}]}}';
             editor.setValue(demo);
+            this.$nextTick(() => {
+                this.format();
+            })
         }
     }
 });

+ 0 - 1
apps/qr-code/index.html

@@ -102,7 +102,6 @@
     <script type="text/javascript" src="../static/vendor/jquery/jquery.colorpicker.js"></script>
     <script type="text/javascript" src="../static/vendor/jquery/jquery.qrcode.min.js"></script>
     <script type="text/javascript" src="../static/vendor/zxing/zxing.min.js"></script>
-    <script type="text/javascript" src="content-script.js"></script>
     <script type="text/javascript" src="index.js"></script>
 </body>
 </html>

+ 11 - 9
apps/qr-code/index.js

@@ -20,10 +20,15 @@ new Vue({
 
         // 在tab创建或者更新时候,监听事件,看看是否有参数传递过来
         if (location.protocol === 'chrome-extension:') {
-            chrome.runtime.onMessage.addListener((request, sender, callback) => {
-                if (request.type === 'TAB_CREATED_OR_UPDATED' && request.event === location.pathname.split('/')[1]) {
-
-                    let text = request.content || (request.fromTab ? request.fromTab.url : '');
+            chrome.tabs.query({currentWindow: true,active: true, }, (tabs) => {
+                let activeTab = tabs.filter(tab => tab.active)[0];
+                chrome.runtime.sendMessage({
+                    type: 'fh-dynamic-any-thing',
+                    thing: 'request-page-content',
+                    tabId: activeTab.id
+                }).then(resp => {
+                    if(!resp) return ;
+                    let text = resp.content || (resp.tab ? (resp.tab.fromTab ? resp.tab.fromTab.url : '') : '');
                     if (text) {
                         if (!this.qrEncodeMode) {
                             // 解码模式
@@ -33,10 +38,7 @@ new Vue({
                             this.convert();
                         }
                     }
-
-                    callback && callback();
-                    return true;
-                }
+                });
             });
         }
 
@@ -245,4 +247,4 @@ new Vue({
             this.resultContent = txt;
         }
     }
-});
+});

+ 2 - 2
apps/static/js/utils.js

@@ -130,7 +130,7 @@ window.toast = function (content) {
  * 获取当前脚本的绝对路径
  * @returns {string}
  */
-module.exports.getCurrAbsPath = function () {
+window.getCurrAbsPath = function () {
     let rExtractUri = /((?:http|https|file|chrome-extension):\/\/.*?\/[^:]+)(?::\d+)?:\d+/;
     let stack;
     try {
@@ -142,4 +142,4 @@ module.exports.getCurrAbsPath = function () {
     if (stack) {
         return rExtractUri.exec(stack)[1];
     }
-};
+};

+ 0 - 188
apps/static/vendor/require/require.js

@@ -1,188 +0,0 @@
-//
-// This file is part of //\ Tarp.
-//
-// Copyright (C) 2013-2018 Torben Haase <https://pixelsvsbytes.com>
-//
-// Tarp is free software: you can redistribute it and/or modify it under the
-// terms of the GNU Lesser General Public License as published by the Free
-// Software Foundation, either version 3 of the License, or (at your option) any
-// later version.
-//
-// Tarp 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 Lesser General Public License for more
-// details.You should have received a copy of the GNU Lesser General Public
-// License along with Tarp.  If not, see <http://www.gnu.org/licenses/>.
-//
-////////////////////////////////////////////////////////////////////////////////
-
-// NOTE The load parameter points to the function, which prepares the
-//      environment for each module and runs its code. Scroll down to the end of
-//      the file to see the function definition.
-(function () {
-    "use strict";
-
-    var cache, root;
-    cache = Object.create(null);
-
-    function getRoot() {
-        var config = (self.Tarp && self.Tarp.require && self.Tarp.require.config) || {};
-        root = {
-            children: [],
-            paths: config.paths || [(new URL("./node_modules/", location.href)).href],
-            uri: config.uri || location.href
-        };
-        return root;
-    }
-
-    function load(id, pwd, asyn) {
-        var matches, href, cached, request;
-        // NOTE resolve href from id
-        matches = id.match(/^((\.)?.*\/|)(.[^.]*|)(\..*|)$/);
-        href = (new URL(
-            matches[1] + matches[3] + (matches[3] && (matches[4] || ".js")),
-            matches[2] ? pwd : root.paths[0] // TODO Can we get rid of this check with more intelligent pwd setting in the engine?
-        )).href;
-
-        // NOTE create cache item if required
-        cached = cache[href] = cache[href] || {
-            e: undefined, // error
-            m: undefined, // module
-            p: undefined, // promise
-            r: undefined, // request
-            s: undefined, // source
-            t: undefined, // type
-            u: href, // url
-        };
-        if (!cached.p) {
-            cached.p = new Promise(function (res, rej) {
-                request = cached.r = new XMLHttpRequest();
-                request.onload = request.onerror = request.ontimeout = function () {
-                    var tmp, done, pattern, match, loading = 0;
-                    // `request` might have been changed by line 60ff
-                    if (request = cached.r) {
-                        cached.r = null;
-                        if ((request.status > 99) && ((href = request.responseURL) != cached.u)) {
-                            if (cache[href]) {
-                                cached = cache[cached.u] = cache[href];
-                                cached.p.then(res, rej);
-                                // NOTE Replace pending request of actual module with the already completed request and abort the
-                                //      pending request.
-                                if (cached.r) {
-                                    tmp = cached.r;
-                                    cached.r = request;
-                                    tmp.abort();
-                                    tmp.onload();
-                                }
-                                return;
-                            }
-                            else {
-                                cache[href] = cached;
-                            }
-                        }
-                        if ((request.status > 99) && (request.status < 400)) {
-                            cached.s = request.responseText;
-                            cached.t = request.getResponseHeader("Content-Type");
-                            done = function () {
-                                if (--loading < 0) res(cached);
-                            };
-                            // NOTE Pre-load submodules if the request is asynchronous (timeout > 0).
-                            if (request.timeout) {
-                                // TODO Write a real parser that returns all modules that are preloadable
-                                pattern = /require(?:\.resolve)?\((?:"((?:[^"\\]|\\.)+)"|'((?:[^'\\]|\\.)+)')\)/g;
-                                while ((match = pattern.exec(cached.s)) !== null) {
-                                    // NOTE Only add modules to the loading-queue that are still pending
-                                    if ((tmp = load(match[1] || match[2], href, true)).r) {
-                                        loading++;
-                                        tmp.p.then(done, done);
-                                    }
-                                }
-                            }
-                            done();
-                        }
-                        else {
-                            rej(cached.e = new Error(href + " " + request.status));
-                        }
-                    }
-                };
-            });
-        }
-        // NOTE `request` is only defined if the module is requested for the first time.
-        if (request = request || (!asyn && cached.r)) {
-            try {
-                request.abort();
-                request.timeout = asyn ? 10000 : 0;
-                request.open("GET", href, asyn);
-                request.send();
-            }
-            catch (e) {
-                request.onerror();
-            }
-        }
-        if (cached.e)
-            throw cached.e;
-        return cached;
-    }
-
-    function evaluate(cached, parent) {
-        var module;
-        if (!cached.m) {
-            module = cached.m = {
-                children: new Array(),
-                exports: Object.create(null),
-                filename: cached.u,
-                id: cached.u,
-                loaded: false,
-                parent: parent,
-                paths: parent.paths.slice(),
-                require: undefined,
-                uri: cached.u
-            },
-                module.require = factory(module);
-            parent.children.push(module);
-            if (cached.t == "application/json")
-                module.exports = JSON.parse(cached.s);
-            else
-                (new Function(
-                    "exports,require,module,__filename,__dirname",
-                    cached.s + "\n//# sourceURL=" + module.uri
-                ))(module.exports, module.require, module, module.uri, module.uri.match(/.*\//)[0]);
-            module.loaded = true;
-        }
-        return cached.m;
-    }
-
-    function factory(parent) {
-        function requireEngine(mode, id, asyn) {
-
-            parent = parent === -1 ? getRoot() : parent;
-
-            function afterLoad(cached) {
-                var regex = /package\.json$/;
-                if (regex.test(cached.u) && !regex.test(id)) {
-                    parent = evaluate(cached, parent);
-                    return requireEngine(mode, parent.exports.main, asyn);
-                }
-                else if (mode === 1)
-                    return cached.u;
-                else if (mode === 2)
-                    return [id[0] === "." ? parent.uri.match(/.*\//)[0] : root.uri]; // TODO Can this be cleaned up?
-                else
-                    return evaluate(cached, parent).exports;
-            }
-
-            return asyn ?
-                new Promise(function (res, rej) {
-                    load(id, parent.uri, asyn).p.then(afterLoad).then(res, rej);
-                }) :
-                afterLoad(load(id, parent.uri, asyn));
-        }
-
-        var require = requireEngine.bind(undefined, 0);
-        require.resolve = requireEngine.bind(require, 1);
-        require.resolve.paths = requireEngine.bind(require.resolve, 2);
-        return require;
-    }
-
-    (self.Tarp = self.Tarp || {}).require = factory(-1);
-})();

+ 2 - 1
apps/timestamp/index.html

@@ -183,8 +183,9 @@
         </table>
         </div>
     </div>
+    <script src="../static/vendor/jquery/jquery-3.3.1.min.js"></script>
+    <script type="text/javascript" src="../static/js/utils.js"></script>
     <script type="text/javascript" src="index.js"></script>
 
-    <script src="../static/vendor/jquery/jquery-3.3.1.min.js"></script>
     </body>
 </html>

+ 0 - 2
apps/timestamp/index.js

@@ -1,8 +1,6 @@
 /**
  * FeHelper Timestamp Tools
  */
-
-Tarp.require('../static/js/utils');
 new Vue({
     el: '#pageContainer',
     data: {