Browse Source

set default title to "Unsaved page" is no title was found

Gildas 7 năm trước cách đây
mục cha
commit
626c1271a4
2 tập tin đã thay đổi với 3 bổ sung2 xóa
  1. 1 1
      extension/core/content/content.js
  2. 2 1
      lib/single-file/single-file-core.js

+ 1 - 1
extension/core/content/content.js

@@ -59,7 +59,7 @@ this.singlefile.top = this.singlefile.top || (() => {
 		if (options.selected) {
 			markSelectedContent(processor.SELECTED_CONTENT_ATTRIBUTE_NAME, processor.SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME);
 		}
-		await processor.initialize();		
+		await processor.initialize();
 		await processor.preparePageData();
 		const page = processor.getPageData();
 		if (options.selected) {

+ 2 - 1
lib/single-file/single-file-core.js

@@ -300,6 +300,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				title = titleElement.textContent.trim();
 			}
 			const matchTitle = this.baseURI.match(/([^/]*)\/?(\.html?.*)$/) || this.baseURI.match(/\/\/([^/]*)\/?$/);
+			const url = new URL(this.baseURI);
 			let size;
 			if (this.options.displayStats) {
 				size = new Blob([this.doc.documentElement.outerHTML]).size;
@@ -311,7 +312,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			}
 			return {
 				stats: this.stats,
-				title: title || (this.baseURI && matchTitle ? matchTitle[1] : ""),
+				title: title || (this.baseURI && matchTitle ? matchTitle[1] : (url.hostname ? url.hostname : "Untitled page")),
 				content
 			};
 		}