summaryrefslogtreecommitdiff
path: root/ext/js/data/permissions-util.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/data/permissions-util.js')
-rw-r--r--ext/js/data/permissions-util.js21
1 files changed, 6 insertions, 15 deletions
diff --git a/ext/js/data/permissions-util.js b/ext/js/data/permissions-util.js
index bd3a18ce..3a5b5de5 100644
--- a/ext/js/data/permissions-util.js
+++ b/ext/js/data/permissions-util.js
@@ -15,13 +15,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+/* global
+ * AnkiUtil
+ */
+
class PermissionsUtil {
constructor() {
this._ankiFieldMarkersRequiringClipboardPermission = new Set([
'clipboard-image',
'clipboard-text'
]);
- this._ankiMarkerPattern = /\{([\w-]+)\}/g;
}
hasPermissions(permissions) {
@@ -69,7 +72,7 @@ class PermissionsUtil {
}
getRequiredPermissionsForAnkiFieldValue(fieldValue) {
- const markers = this._getAnkiFieldMarkers(fieldValue);
+ const markers = AnkiUtil.getFieldMarkers(fieldValue);
const markerPermissions = this._ankiFieldMarkersRequiringClipboardPermission;
for (const marker of markers) {
if (markerPermissions.has(marker)) {
@@ -99,7 +102,7 @@ class PermissionsUtil {
];
for (const fields of fieldsList) {
for (const fieldValue of Object.values(fields)) {
- const markers = this._getAnkiFieldMarkers(fieldValue);
+ const markers = AnkiUtil.getFieldMarkers(fieldValue);
for (const marker of markers) {
if (fieldMarkersRequiringClipboardPermission.has(marker)) {
return false;
@@ -111,16 +114,4 @@ class PermissionsUtil {
return true;
}
-
- // Private
-
- _getAnkiFieldMarkers(fieldValue) {
- const pattern = this._ankiMarkerPattern;
- const markers = [];
- let match;
- while ((match = pattern.exec(fieldValue)) !== null) {
- markers.push(match[1]);
- }
- return markers;
- }
}