aboutsummaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-14 18:04:19 -0400
committerGitHub <noreply@github.com>2021-03-14 18:04:19 -0400
commit52a4d874eada5be121e15d73d1d10e9a8d84bdb8 (patch)
tree0a8c2afe9ac507701b954c0510c3f38d14d999a0 /ext/js
parent06b02c3cf2ce725383f9a0bae87d3ef084ed8809 (diff)
Make MediaUtil a static class (#1525)
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/background/backend.js10
-rw-r--r--ext/js/comm/clipboard-reader.js10
-rw-r--r--ext/js/language/dictionary-importer.js3
-rw-r--r--ext/js/media/media-util.js8
4 files changed, 15 insertions, 16 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index f3568694..a2a93375 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -47,13 +47,11 @@ class Backend {
});
this._anki = new AnkiConnect();
this._mecab = new Mecab();
- this._mediaUtil = new MediaUtil();
this._clipboardReader = new ClipboardReader({
// eslint-disable-next-line no-undef
document: (typeof document === 'object' && document !== null ? document : null),
pasteTargetSelector: '#clipboard-paste-target',
- imagePasteTargetSelector: '#clipboard-image-paste-target',
- mediaUtil: this._mediaUtil
+ imagePasteTargetSelector: '#clipboard-image-paste-target'
});
this._clipboardMonitor = new ClipboardMonitor({
japaneseUtil: this._japaneseUtil,
@@ -1750,7 +1748,7 @@ class Backend {
return null;
}
- let extension = this._mediaUtil.getFileExtensionFromAudioMediaType(contentType);
+ let extension = MediaUtil.getFileExtensionFromAudioMediaType(contentType);
if (extension === null) { extension = '.mp3'; }
let fileName = this._generateAnkiNoteMediaFileName('yomichan_audio', extension, timestamp, definitionDetails);
fileName = fileName.replace(/\]/g, '');
@@ -1764,7 +1762,7 @@ class Backend {
const dataUrl = await this._getScreenshot(tabId, frameId, format, quality);
const {mediaType, data} = this._getDataUrlInfo(dataUrl);
- const extension = this._mediaUtil.getFileExtensionFromImageMediaType(mediaType);
+ const extension = MediaUtil.getFileExtensionFromImageMediaType(mediaType);
if (extension === null) {
throw new Error('Unknown media type for screenshot image');
}
@@ -1782,7 +1780,7 @@ class Backend {
}
const {mediaType, data} = this._getDataUrlInfo(dataUrl);
- const extension = this._mediaUtil.getFileExtensionFromImageMediaType(mediaType);
+ const extension = MediaUtil.getFileExtensionFromImageMediaType(mediaType);
if (extension === null) {
throw new Error('Unknown media type for clipboard image');
}
diff --git a/ext/js/comm/clipboard-reader.js b/ext/js/comm/clipboard-reader.js
index 6d4f5abc..9336efe5 100644
--- a/ext/js/comm/clipboard-reader.js
+++ b/ext/js/comm/clipboard-reader.js
@@ -15,6 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+/* global
+ * MediaUtil
+ */
+
/**
* Class which can read text and images from the clipboard.
*/
@@ -25,14 +29,13 @@ class ClipboardReader {
* @param pasteTargetSelector The selector for the paste target element.
* @param imagePasteTargetSelector The selector for the image paste target element.
*/
- constructor({document=null, pasteTargetSelector=null, imagePasteTargetSelector=null, mediaUtil=null}) {
+ constructor({document=null, pasteTargetSelector=null, imagePasteTargetSelector=null}) {
this._document = document;
this._browser = null;
this._pasteTarget = null;
this._pasteTargetSelector = pasteTargetSelector;
this._imagePasteTarget = null;
this._imagePasteTargetSelector = imagePasteTargetSelector;
- this._mediaUtil = mediaUtil;
}
/**
@@ -107,7 +110,6 @@ class ClipboardReader {
// See browser-specific notes in getText
if (
this._isFirefox() &&
- this._mediaUtil !== null &&
typeof navigator.clipboard !== 'undefined' &&
typeof navigator.clipboard.read === 'function'
) {
@@ -120,7 +122,7 @@ class ClipboardReader {
}
for (const file of files) {
- if (this._mediaUtil.getFileExtensionFromImageMediaType(file.type) !== null) {
+ if (MediaUtil.getFileExtensionFromImageMediaType(file.type) !== null) {
return await this._readFileAsDataURL(file);
}
}
diff --git a/ext/js/language/dictionary-importer.js b/ext/js/language/dictionary-importer.js
index c23a93e3..b4429315 100644
--- a/ext/js/language/dictionary-importer.js
+++ b/ext/js/language/dictionary-importer.js
@@ -25,7 +25,6 @@ class DictionaryImporter {
constructor() {
this._schemas = new Map();
this._jsonSchemaValidator = new JsonSchemaValidator();
- this._mediaUtil = new MediaUtil();
}
async importDictionary(dictionaryDatabase, archiveSource, details, onProgress) {
@@ -325,7 +324,7 @@ class DictionaryImporter {
}
const content = await file.async('base64');
- const mediaType = this._mediaUtil.getImageMediaTypeFromFileName(path);
+ const mediaType = MediaUtil.getImageMediaTypeFromFileName(path);
if (mediaType === null) {
throw new Error(`Could not determine media type for image at path ${JSON.stringify(path)} for ${errorSource}`);
}
diff --git a/ext/js/media/media-util.js b/ext/js/media/media-util.js
index 25bcdd18..11172c5c 100644
--- a/ext/js/media/media-util.js
+++ b/ext/js/media/media-util.js
@@ -26,7 +26,7 @@ class MediaUtil {
* @returns The file extension, including the '.', or an empty string
* if there is no file extension.
*/
- getFileNameExtension(path) {
+ static getFileNameExtension(path) {
const match = /\.[^./\\]*$/.exec(path);
return match !== null ? match[0] : '';
}
@@ -37,7 +37,7 @@ class MediaUtil {
* @returns The media type string if it can be determined from the file path,
* otherwise null.
*/
- getImageMediaTypeFromFileName(path) {
+ static getImageMediaTypeFromFileName(path) {
switch (this.getFileNameExtension(path).toLowerCase()) {
case '.apng':
return 'image/apng';
@@ -74,7 +74,7 @@ class MediaUtil {
* @returns A file extension including the dot for the media type,
* otherwise null.
*/
- getFileExtensionFromImageMediaType(mediaType) {
+ static getFileExtensionFromImageMediaType(mediaType) {
switch (mediaType) {
case 'image/apng':
return '.apng';
@@ -105,7 +105,7 @@ class MediaUtil {
* @returns A file extension including the dot for the media type,
* otherwise null.
*/
- getFileExtensionFromAudioMediaType(mediaType) {
+ static getFileExtensionFromAudioMediaType(mediaType) {
switch (mediaType) {
case 'audio/mpeg':
case 'audio/mp3':