Просмотр исходного кода

feat: show `@grant none` hint in editor

tophf 2 недель назад
Родитель
Сommit
00a1be5d1c
2 измененных файлов с 6 добавлено и 0 удалено
  1. 3 0
      src/_locales/en/messages.yml
  2. 3 0
      src/background/utils/db.js

+ 3 - 0
src/_locales/en/messages.yml

@@ -331,6 +331,9 @@ hintGrantless:
     A sandboxed script cannot change these global properties: $1.
     To fix the script either add `@grant none` to disable the sandbox,
     or use `unsafeWindow` instead of `window`.
+hintGrantNone:
+  description: Don't translate back-quoted terms.
+  message: '`@grant none` disables all other `@grant` keys.'
 hintInputURL:
   description: Hint for a prompt box to input URL of a user script.
   message: 'Input URL:'

+ 3 - 0
src/background/utils/db.js

@@ -590,6 +590,9 @@ function parseMetaWithErrors(src) {
   const errors = [];
   const meta = parseMeta(isObj ? src.code : src, { errors });
   if (meta) {
+    if (meta.grant.includes('none') && new Set(meta.grant).size > 1) {
+      errors.push(i18n('hintGrantNone'));
+    }
     testerBatch(errors);
     testScript('', { meta, custom });
     testerBatch();