Browse Source

add `{url-original}` template variable (fix #1608)

Gildas 1 year ago
parent
commit
de4a9153e3

File diff suppressed because it is too large
+ 0 - 0
lib/chrome-browser-polyfill.js


File diff suppressed because it is too large
+ 0 - 0
lib/single-file-extension-background.js


File diff suppressed because it is too large
+ 0 - 0
lib/single-file-extension-editor-helper.js


+ 23 - 1
lib/single-file-extension-editor.js

@@ -2125,7 +2125,8 @@ pre code {
 							viewport: viewport ? viewport.content : null,
 							compressContent: true,
 							foregroundSave: message.foregroundSave,
-							sharePage: message.sharePage
+							sharePage: message.sharePage,
+							documentHeight: document.documentElement.offsetHeight
 						}), "*");
 					} else {
 						if (message.foregroundSave || message.sharePage) {
@@ -3018,7 +3019,16 @@ pre code {
 				containerElement.classList.add(className);
 				classesToPreserve.push(className);
 			});
+			const optionsElement = document.querySelector("script[type=\"application/json\"][" + SCRIPT_OPTIONS + "]");
 			const article = new Readability(document, { classesToPreserve }).parse();
+			const articleMetadata = Object.assign({}, article);
+			delete articleMetadata.content;
+			delete articleMetadata.textContent;
+			for (const key in articleMetadata) {
+				if (articleMetadata[key] == null) {
+					delete articleMetadata[key];
+				}
+			}
 			removedElements = [];
 			removedElementIndex = 0;
 			document.body.innerHTML = "";
@@ -3026,6 +3036,9 @@ pre code {
 			const doc = domParser.parseFromString(article.content, "text/html");
 			const contentEditable = document.body.contentEditable;
 			document.documentElement.replaceChild(doc.body, document.body);
+			if (optionsElement) {
+				document.body.appendChild(optionsElement);
+			}
 			document.querySelectorAll(NOTE_TAGNAME).forEach(containerElement => {
 				const noteId = (Array.from(containerElement.classList).find(className => /singlefile-note-id-\d+/.test(className))).split("singlefile-note-id-")[1];
 				containerElement.classList.remove("singlefile-note-id-" + noteId);
@@ -3057,6 +3070,15 @@ pre code {
 			titleElement.classList.add("reader-title");
 			titleElement.textContent = article.title;
 			document.body.insertBefore(titleElement, document.body.firstChild);
+			const existingMetaDataElement = document.querySelector("script[id=singlefile-readability-metadata]");
+			if (existingMetaDataElement) {
+				existingMetaDataElement.remove();
+			}
+			const metaDataElement = document.createElement("script");
+			metaDataElement.type = "application/json";
+			metaDataElement.id = "singlefile-readability-metadata";
+			metaDataElement.textContent = JSON.stringify(articleMetadata, null, 2);
+			document.head.appendChild(metaDataElement);
 			document.querySelectorAll("a[href]").forEach(element => {
 				const href = element.getAttribute("href").trim();
 				if (href.startsWith(document.baseURI + "#")) {

File diff suppressed because it is too large
+ 0 - 0
lib/single-file.js


+ 18 - 18
package-lock.json

@@ -9,7 +9,7 @@
 			"version": "1.2.4",
 			"license": "AGPL-3.0-or-later",
 			"dependencies": {
-				"single-file-core": "1.5.36"
+				"single-file-core": "1.5.41"
 			},
 			"devDependencies": {
 				"@rollup/plugin-node-resolve": "15.2.3",
@@ -131,15 +131,15 @@
 			}
 		},
 		"node_modules/@rollup/pluginutils": {
-			"version": "5.1.2",
-			"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.2.tgz",
-			"integrity": "sha512-/FIdS3PyZ39bjZlwqFnWqCOVnW7o963LtKMwQOD0NhQqw22gSr2YY1afu3FxRip4ZCZNsD5jq6Aaz6QV3D/Njw==",
+			"version": "5.1.3",
+			"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.3.tgz",
+			"integrity": "sha512-Pnsb6f32CD2W3uCaLZIzDmeFyQ2b8UWMFI7xtwUezpcGBDVDW6y9XgAWIlARiGAo6eNF5FK5aQTr0LFyNyqq5A==",
 			"dev": true,
 			"license": "MIT",
 			"dependencies": {
 				"@types/estree": "^1.0.0",
 				"estree-walker": "^2.0.2",
-				"picomatch": "^2.3.1"
+				"picomatch": "^4.0.2"
 			},
 			"engines": {
 				"node": ">=14.0.0"
@@ -392,9 +392,9 @@
 			"license": "MIT"
 		},
 		"node_modules/acorn": {
-			"version": "8.12.1",
-			"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz",
-			"integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==",
+			"version": "8.14.0",
+			"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
+			"integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==",
 			"dev": true,
 			"license": "MIT",
 			"bin": {
@@ -533,13 +533,13 @@
 			"license": "MIT"
 		},
 		"node_modules/picomatch": {
-			"version": "2.3.1",
-			"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
-			"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
+			"version": "4.0.2",
+			"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz",
+			"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
 			"dev": true,
 			"license": "MIT",
 			"engines": {
-				"node": ">=8.6"
+				"node": ">=12"
 			},
 			"funding": {
 				"url": "https://github.com/sponsors/jonschlinkert"
@@ -648,9 +648,9 @@
 			}
 		},
 		"node_modules/single-file-core": {
-			"version": "1.5.36",
-			"resolved": "https://registry.npmjs.org/single-file-core/-/single-file-core-1.5.36.tgz",
-			"integrity": "sha512-OCB90XiTsSyU9+rfh3TvcVAbdEDQhFXfodM8tDbdiP0N+Rq7MRFyCoLrrFe1cxjYDQeGAHYCyY47JWuSlSjySA==",
+			"version": "1.5.41",
+			"resolved": "https://registry.npmjs.org/single-file-core/-/single-file-core-1.5.41.tgz",
+			"integrity": "sha512-ritbHntlg9YHRi6NUri1p5bPaG56sYHFXOqRdCFvrDKhvRnfQtBu4LFSyEi/ig2EEWIxhAx3T0qr4mCnmXdqrw==",
 			"license": "AGPL-3.0-or-later"
 		},
 		"node_modules/smob": {
@@ -695,9 +695,9 @@
 			}
 		},
 		"node_modules/terser": {
-			"version": "5.34.1",
-			"resolved": "https://registry.npmjs.org/terser/-/terser-5.34.1.tgz",
-			"integrity": "sha512-FsJZ7iZLd/BXkz+4xrRTGJ26o/6VTjQytUk8b8OxkwcD2I+79VPJlz7qss1+zE7h8GNIScFqXcDyJ/KqBYZFVA==",
+			"version": "5.36.0",
+			"resolved": "https://registry.npmjs.org/terser/-/terser-5.36.0.tgz",
+			"integrity": "sha512-IYV9eNMuFAV4THUspIRXkLakHnV6XO7FEdtKjf/mDyrnqUg9LnlOn6/RwRvM9SZjR4GUq8Nk8zj67FzVARr74w==",
 			"dev": true,
 			"license": "BSD-2-Clause",
 			"dependencies": {

+ 1 - 1
package.json

@@ -10,7 +10,7 @@
 	},
 	"type": "module",
 	"dependencies": {
-		"single-file-core": "1.5.40"
+		"single-file-core": "1.5.41"
 	},
 	"devDependencies": {
 		"rollup": "4.22.4",

+ 1 - 0
src/core/bg/business.js

@@ -99,6 +99,7 @@ async function saveUrls(urls, options = {}) {
 		if (tabOptions.profileName != config.DISABLED_PROFILE_NAME) {
 			Object.keys(options).forEach(key => tabOptions[key] = options[key]);
 			tabOptions.autoClose = true;
+			tabOptions.originalUrl = url;
 			tabOptions.extensionScriptFiles = extensionScriptFiles;
 			if (tabOptions.passReferrerOnError) {
 				requests.enableReferrerOnError();

+ 2 - 0
src/ui/pages/help.html

@@ -977,6 +977,8 @@
 						"http://example.com")</li>
 					<li><code>{url-referrer-flat}</code>: the URI of the page that "linked" to the page with slashed
 						replaced (e.g. "http_example.com")</li>
+					<li><code>{url-original}</code>: the original URL of the page (e.g.
+						"http://example.com/index.html")</li>
 					<li><code>{bookmark-pathname}</code>: the path name of the newly created bookmark (e.g. "My
 						Bookmarks/Last Month") when the option "Bookmarks &gt; save the page of a
 						newly created bookmark" is enabled</li>

+ 1 - 0
src/ui/pages/help_zh_CN.html

@@ -695,6 +695,7 @@
                     <li><code>{url-hash}</code>: URL 的哈希值(例如 "chapter-2")</li>
                     <li><code>{url-referrer}</code>: 链接到该页面的页面的 URI(例如 "http://example.com")</li>
                     <li><code>{url-referrer-flat}</code>: 链接到该页面的页面的 URI,斜杠被替换(例如 "http_example.com")</li>
+                    <li><code>{url-original}</code>: 页面的原始 URL(例如 "http://example.com/index.html")</li>
                     <li><code>{bookmark-pathname}</code>: 新创建的书签的路径名(例如 "我的书签/上个月"),当选项 "书签 > 保存新创建书签的页面" 被启用时</li>
                     <li><code>{bookmark-pathname-flat}</code>: 新创建的书签的路径名,斜杠被替换(例如 "我的书签_上个月"),当选项 "书签 > 保存新创建书签的页面"被启用时
                     </li>

Some files were not shown because too many files changed in this diff