fixed cacheing bug

This commit is contained in:
Lalle 2023-05-05 12:48:04 +02:00
parent 8468e225a8
commit 87903aab6b
No known key found for this signature in database
GPG Key ID: A6583D207A8F6B0D

View File

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