Greasy Fork is available in English.

Photo Viewer DB Interface

IndexedDB interface for WMEPIE Photo Viewer tool

Ezt a szkriptet nem ajánlott közvetlenül telepíteni. Ez egy könyvtár más szkriptek számára, amik tartalmazzák a // @require https://update.greasyfork.org/scripts/375202/651025/Photo%20Viewer%20DB%20Interface.js hivatkozást.

  1. // ==UserScript==
  2. // @name Photo Viewer DB Interface
  3. // @namespace https://greasyfork.org/en/users/166843-wazedev
  4. // @version 2018.12.05.01
  5. // @description IndexedDB interface for WMEPIE Photo Viewer tool
  6. // @author WazeDev
  7. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  8. // @license GNU GPLv3
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. (function() {
  14. 'use strict';
  15. var pvdb;
  16.  
  17. function getDB() {
  18. if (!pvdb) {
  19. pvdb= new Promise(function(resolve, reject) {
  20. var openreq = indexedDB.open('WMEPIEPhotoViewer', 1);
  21.  
  22. openreq.onerror = function() {
  23. reject(openreq.error);
  24. };
  25.  
  26. openreq.onupgradeneeded = function() {
  27. // First time setup: create an empty object store
  28. //openreq.result.createObjectStore(dbName, { keyPath: "placeID" });
  29. if(!openreq.result.objectStoreNames.contains("Places")) {
  30. openreq.result.createObjectStore("Places", { keyPath: "placeID" });
  31. }
  32. };
  33.  
  34. openreq.onsuccess = function() {
  35. resolve(openreq.result);
  36. };
  37. });
  38. }
  39. return pvdb;
  40. }
  41.  
  42. function withStore(storeName, type, callback) {
  43. return getDB().then(function(pvdb) {
  44. return new Promise(function(resolve, reject) {
  45. var transaction = pvdb.transaction(storeName, type);
  46. transaction.oncomplete = function() {
  47. resolve();
  48. };
  49. transaction.onerror = function() {
  50. reject(transaction.error);
  51. };
  52. callback(transaction.objectStore(storeName));
  53. });
  54. });
  55. }
  56.  
  57. var idbPVKeyval = {
  58. get: function(storeName, key) {
  59. var req;
  60. return withStore(storeName, 'readonly', function(store) {
  61. req = store.get(key);
  62. }).then(function() {
  63. return req.result;
  64. });
  65. },
  66. set: function(storeName, value) {
  67. return withStore(storeName, 'readwrite', function(store) {
  68. store.put(value);
  69. });
  70. },
  71. delete: function(storeName, key) {
  72. return withStore(storeName, 'readwrite', function(store) {
  73. store.delete(key);
  74. });
  75. },
  76. clear: function(storeName) {
  77. return withStore(storeName, 'readwrite', function(store) {
  78. store.clear();
  79. });
  80. },
  81. keys: function(storeName) {
  82. var keys = [];
  83. return withStore(storeName, 'readonly', function(store) {
  84. // This would be store.getAllKeys(), but it isn't supported by Edge or Safari.
  85. // And openKeyCursor isn't supported by Safari.
  86. (store.openKeyCursor || store.openCursor).call(store).onsuccess = function() {
  87. if (!this.result) return;
  88. keys.push(this.result.key);
  89. this.result.continue();
  90. };
  91. }).then(function() {
  92. return keys;
  93. });
  94. }
  95. };
  96.  
  97. if (typeof module != 'undefined' && module.exports) {
  98. module.exports = idbPVKeyval ;
  99. } else if (typeof define === 'function' && define.amd) {
  100. define('idbPVKeyval ', [], function() {
  101. return idbPVKeyval ;
  102. });
  103. } else {
  104. self.idbPVKeyval = idbPVKeyval ;
  105. }
  106. }());