1558522-1.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <html>
  2. <head>
  3. <script id='worker' type='javascript/worker'>
  4. onmessage = function (e) {
  5. const file = e.data[0]
  6. const db = indexedDB.open('', {})
  7. db.onupgradeneeded = function (event) {
  8. const store = event.target.result.createObjectStore('IDBStore_0', {})
  9. store.add({}, '')
  10. }
  11. db.onsuccess = function (event) {
  12. const transaction = event.target.result.transaction('IDBStore_0', 'readwrite')
  13. const store = transaction.objectStore('IDBStore_0')
  14. const cursor = store.openCursor()
  15. cursor.onsuccess = function (event) {
  16. event.target.result.update({
  17. data: file
  18. })
  19. event.target.result.advance(1)
  20. }
  21. event.target.result.close()
  22. }
  23. }
  24. </script>
  25. <script>
  26. let worker;
  27. function start () {
  28. const file = new File([], 'x')
  29. const blob = new Blob([document.getElementById('worker').textContent], { type: 'text/javascript' })
  30. worker = new Worker(window.URL.createObjectURL(blob))
  31. worker.postMessage([file], [])
  32. }
  33. document.addEventListener('DOMContentLoaded', start)
  34. </script>
  35. </head>
  36. </html>