aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-22 15:49:24 -0400
committerGitHub <noreply@github.com>2020-08-22 15:49:24 -0400
commitf0c974d319d9fb4c50c9a4a8f665a642edb77d58 (patch)
tree71855fd155b8072e9ce627a6643938065ef44b5d /ext
parent9fa0f2a56a79159227f1f42455157fe9c84132d3 (diff)
Move generateId to core.js (#748)
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/backend.js2
-rw-r--r--ext/bg/js/settings/settings-controller.js2
-rw-r--r--ext/fg/js/frame-offset-forwarder.js2
-rw-r--r--ext/fg/js/frontend.js2
-rw-r--r--ext/fg/js/popup-factory.js2
-rw-r--r--ext/mixed/js/core.js10
-rw-r--r--ext/mixed/js/display-history.js2
-rw-r--r--ext/mixed/js/frame-client.js2
-rw-r--r--ext/mixed/js/frame-endpoint.js2
-rw-r--r--ext/mixed/js/yomichan.js10
10 files changed, 18 insertions, 18 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 65f4d6b3..810370c4 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -739,7 +739,7 @@ class Backend {
if (typeof tabId !== 'number') { throw new Error('Sender has invalid tab ID'); }
const frameId = sender.frameId;
- const id = yomichan.generateId(16);
+ const id = generateId(16);
const details = {
name: 'action-port',
id
diff --git a/ext/bg/js/settings/settings-controller.js b/ext/bg/js/settings/settings-controller.js
index 6479714d..4825d348 100644
--- a/ext/bg/js/settings/settings-controller.js
+++ b/ext/bg/js/settings/settings-controller.js
@@ -25,7 +25,7 @@ class SettingsController extends EventDispatcher {
constructor(profileIndex=0) {
super();
this._profileIndex = profileIndex;
- this._source = yomichan.generateId(16);
+ this._source = generateId(16);
this._pageExitPreventions = new Set();
this._pageExitPreventionEventListeners = new EventListenerCollection();
}
diff --git a/ext/fg/js/frame-offset-forwarder.js b/ext/fg/js/frame-offset-forwarder.js
index 94775105..e2c34736 100644
--- a/ext/fg/js/frame-offset-forwarder.js
+++ b/ext/fg/js/frame-offset-forwarder.js
@@ -42,7 +42,7 @@ class FrameOffsetForwarder {
return [0, 0];
}
- const uniqueId = yomichan.generateId(16);
+ const uniqueId = generateId(16);
const frameOffsetPromise = yomichan.getTemporaryListenerResult(
chrome.runtime.onMessage,
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 981852db..caa2bd3e 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -33,7 +33,7 @@ class Frontend {
isSearchPage,
allowRootFramePopupProxy
}) {
- this._id = yomichan.generateId(16);
+ this._id = generateId(16);
this._popup = null;
this._disabledOverride = false;
this._options = null;
diff --git a/ext/fg/js/popup-factory.js b/ext/fg/js/popup-factory.js
index ab450b26..03ac603b 100644
--- a/ext/fg/js/popup-factory.js
+++ b/ext/fg/js/popup-factory.js
@@ -86,7 +86,7 @@ class PopupFactory {
if (frameId === this._frameId) {
// New unique id
if (id === null) {
- id = yomichan.generateId(16);
+ id = generateId(16);
}
const popup = new Popup(id, depth, frameId, ownerFrameId);
if (parent !== null) {
diff --git a/ext/mixed/js/core.js b/ext/mixed/js/core.js
index 7cdd62d8..9142a846 100644
--- a/ext/mixed/js/core.js
+++ b/ext/mixed/js/core.js
@@ -197,6 +197,16 @@ if (typeof window === 'object' && window !== null) {
window.clone = clone;
}
+function generateId(length) {
+ const array = new Uint8Array(length);
+ crypto.getRandomValues(array);
+ let id = '';
+ for (const value of array) {
+ id += value.toString(16).padStart(2, '0');
+ }
+ return id;
+}
+
/*
* Async utilities
diff --git a/ext/mixed/js/display-history.js b/ext/mixed/js/display-history.js
index cf2db8d5..a369e6fa 100644
--- a/ext/mixed/js/display-history.js
+++ b/ext/mixed/js/display-history.js
@@ -166,7 +166,7 @@ class DisplayHistory extends EventDispatcher {
}
_generateId() {
- return yomichan.generateId(16);
+ return generateId(16);
}
_clear() {
diff --git a/ext/mixed/js/frame-client.js b/ext/mixed/js/frame-client.js
index 6ea344e2..632c50d4 100644
--- a/ext/mixed/js/frame-client.js
+++ b/ext/mixed/js/frame-client.js
@@ -90,7 +90,7 @@ class FrameClient {
case 'frameEndpointReady':
{
const {secret} = params;
- const token = yomichan.generateId(16);
+ const token = generateId(16);
tokenMap.set(secret, token);
postMessage('frameEndpointConnect', {secret, token, hostFrameId});
}
diff --git a/ext/mixed/js/frame-endpoint.js b/ext/mixed/js/frame-endpoint.js
index 1cd25bb5..1414442d 100644
--- a/ext/mixed/js/frame-endpoint.js
+++ b/ext/mixed/js/frame-endpoint.js
@@ -21,7 +21,7 @@
class FrameEndpoint {
constructor() {
- this._secret = yomichan.generateId(16);
+ this._secret = generateId(16);
this._token = null;
this._eventListeners = new EventListenerCollection();
this._eventListenersSetup = false;
diff --git a/ext/mixed/js/yomichan.js b/ext/mixed/js/yomichan.js
index 2de82274..9e049d41 100644
--- a/ext/mixed/js/yomichan.js
+++ b/ext/mixed/js/yomichan.js
@@ -84,16 +84,6 @@ const yomichan = (() => {
this.sendMessage({action: 'yomichanReady'});
}
- generateId(length) {
- const array = new Uint8Array(length);
- crypto.getRandomValues(array);
- let id = '';
- for (const value of array) {
- id += value.toString(16).padStart(2, '0');
- }
- return id;
- }
-
isExtensionUrl(url) {
try {
return url.startsWith(chrome.runtime.getURL('/'));