Переглянути джерело

feat: include script name in title

close #515
Gerald 6 роки тому
батько
коміт
e955ffa60a
3 змінених файлів з 15 додано та 3 видалено
  1. 1 1
      src/options/index.js
  2. 7 0
      src/options/views/app.vue
  3. 7 2
      src/options/views/edit/index.vue

+ 1 - 1
src/options/index.js

@@ -16,12 +16,12 @@ Object.assign(store, {
   scripts: [],
   sync: [],
   filteredScripts: [],
+  title: null,
 });
 zip.workerScriptsPath = '/public/lib/zip.js/';
 initialize();
 
 function initialize() {
-  document.title = i18n('extName');
   initMain();
   options.ready(() => {
     const el = document.createElement('div');

+ 7 - 0
src/options/views/app.vue

@@ -31,6 +31,7 @@
 </template>
 
 <script>
+import { i18n } from '#/common';
 import Icon from '#/common/ui/icon';
 import { store } from '../utils';
 import Installed from './tab-installed';
@@ -42,6 +43,7 @@ const tabs = {
   settings: Settings,
   about: About,
 };
+const extName = i18n('extName');
 
 export default {
   components: {
@@ -63,6 +65,11 @@ export default {
       return tabs[this.tab];
     },
   },
+  watch: {
+    'store.title'(title) {
+      document.title = title ? `${title} - ${extName}` : extName;
+    },
+  },
 };
 </script>
 

+ 7 - 2
src/options/views/edit/index.vue

@@ -58,7 +58,7 @@ import { i18n, sendMessage, noop } from '#/common';
 import { objectGet } from '#/common/object';
 import VmCode from '#/common/ui/code';
 import { route } from '#/common/router';
-import { showMessage } from '../../utils';
+import { store, showMessage } from '../../utils';
 import VmSettings from './settings';
 import VmValues from './values';
 
@@ -95,7 +95,9 @@ export default {
   computed: {
     scriptName() {
       const { custom, meta } = this.script || {};
-      return custom && custom.name || meta && meta.name;
+      const scriptName = custom && custom.name || meta && meta.name;
+      store.title = scriptName;
+      return scriptName;
     },
   },
   watch: {
@@ -232,6 +234,9 @@ export default {
       this.tooLarge = tooLarge;
     },
   },
+  beforeDestroy() {
+    store.title = null;
+  },
 };
 </script>