From a187222ed5905be1d4da894fc24fe54e4a4bf2bd Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 13 Jul 2023 15:36:48 +0200 Subject: [PATCH] Add instance name to page titles #1043 --- customize.dist/pages/index.js | 1 + customize.dist/template.js | 10 +++++++++- www/common/sframe-common-outer.js | 11 +++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/customize.dist/pages/index.js b/customize.dist/pages/index.js index 995395dc8..fc74c3916 100644 --- a/customize.dist/pages/index.js +++ b/customize.dist/pages/index.js @@ -35,6 +35,7 @@ define([ }; return function () { + document.title = Msg.homePage; var icons = [ [ 'sheet', Msg.type.sheet], [ 'doc', Msg.type.doc], diff --git a/customize.dist/template.js b/customize.dist/template.js index 15168ee5d..0903483f6 100644 --- a/customize.dist/template.js +++ b/customize.dist/template.js @@ -41,11 +41,19 @@ $(function () { }); }).nThen(function () { require([ + '/api/config', + '/common/common-util.js', + 'optional!/api/instance', 'less!/customize/src/less2/pages/page-' + pageName + '.less', 'css!/components/bootstrap/dist/css/bootstrap.min.css', 'css!/customize/fonts/cptools/style.css' - ], function () { + ], function (ApiConfig, Util, Instance) { var $main = $(infoPage()); + var titleSuffix = (Util.find(Instance, ['name','default']) || '').trim(); + if (!titleSuffix || titleSuffix === ApiConfig.httpUnsafeOrigin) { + titleSuffix = window.location.hostname; + } + document.title = document.title + ' - ' + titleSuffix; $('#placeholder').remove(); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 5d973e703..0fb43c4a9 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -150,9 +150,11 @@ define([ '/customize/application_config.js', //'/common/test.js', '/common/userObject.js', + 'optional!/api/instance' ], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel, _SecureIframe, _UnsafeIframe, _OOIframe, _Messaging, _Notifier, _Hash, _Util, _Realtime, _Notify, - _Constants, _Feedback, _LocalStore, _Cache, _AppConfig, /* _Test,*/ _UserObject) { + _Constants, _Feedback, _LocalStore, _Cache, _AppConfig, /* _Test,*/ _UserObject, + _Instance) { CpNfOuter = _CpNfOuter; Cryptpad = _Cryptpad; Crypto = Utils.Crypto = _Crypto; @@ -173,6 +175,7 @@ define([ Utils.UserObject = _UserObject; Utils.Notify = _Notify; Utils.currentPad = currentPad; + Utils.Instance = _Instance; AppConfig = _AppConfig; //Test = _Test; @@ -1228,13 +1231,17 @@ define([ var currentTitle; var currentTabTitle; + var titleSuffix = (Utils.Util.find(Utils, ['Instance','name','default']) || '').trim(); + if (!titleSuffix || titleSuffix === ApiConfig.httpUnsafeOrigin) { + titleSuffix = window.location.hostname; + } var setDocumentTitle = function () { if (!currentTabTitle) { document.title = currentTitle || 'CryptPad'; return; } var title = currentTabTitle.replace(/\{title\}/g, currentTitle || 'CryptPad'); - document.title = title; + document.title = title + ' - ' + titleSuffix; }; var setPadTitle = function (data, cb) {