diff --git a/src/platform/$.ts b/src/platform/$.ts index 3d00887..66aefa6 100644 --- a/src/platform/$.ts +++ b/src/platform/$.ts @@ -592,17 +592,12 @@ $.queueTask = (() => { } })() -$.global = function (fn: Function, data?: any) { - const d = document - if (d) { - const script = $.el('script', { - textContent: `(${fn}).call(document.currentScript.dataset);`, - }) - if (data) { - $.extend(script.dataset, data) - } - const target = d.head || d - $.add(target, script) +$.global = function (fn, data) { + if (doc) { + const script = $.el('script', + { textContent: `(${fn}).call(document.currentScript.dataset);` }) + if (data) { $.extend(script.dataset, data) } + $.add((d.head || doc), script) $.rm(script) return script.dataset } else { @@ -672,10 +667,13 @@ $.item = function (key: string, val: string | JSON) { return item } -$.oneItemSugar = (fn: (item: any, cb?) => any) => (key: string | any, val?: JSON | string, cb?) => { - const item = typeof key === 'string' ? $.item(key, val) : key - return fn(item, cb) -} +$.oneItemSugar = (fn: Function) => (function (key: string, val: JSON | string, cb) { + if (typeof key === 'string') { + return fn($.item(key, val), cb) + } else { + return fn(key, val) + } +}) $.syncing = dict() @@ -704,12 +702,7 @@ if (platform === 'crx') { } }) $.sync = (key: string, cb) => $.syncing[key] = cb - $.forceSync = (key: string, cb) => { - $.syncing[key] = cb - chrome.storage.local.get(key, function (data) { - cb(data[key], key) - }) - } + $.forceSync = function () {/* emptey */ } $.crxWorking = function () { try {