fix file name not trimmed - ff doesnt allow leading/trailing space?

master
Ondřej Hruška 6 years ago
parent e7d07a5729
commit c1891e4f00
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 18
      background.js
  2. 2
      manifest.json

@ -17,8 +17,11 @@ function sanitizeUrl(unsafe) {
/** Remove the most risky characters from a filename string */ /** Remove the most risky characters from a filename string */
function cleanFilename(unsafe) { function cleanFilename(unsafe) {
return unsafe return unsafe
.replace(/::/g, " - ")
.replace(/[/\\?*|"'<>:]+/g, " ") .replace(/[/\\?*|"'<>:]+/g, " ")
.replace(/\s+/g, " "); .replace(/\s+/g, " ")
.replace(/[\._-]$/g, "")
.trim();
} }
browser.browserAction.onClicked.addListener((tab) => { browser.browserAction.onClicked.addListener((tab) => {
@ -26,8 +29,11 @@ browser.browserAction.onClicked.addListener((tab) => {
const escapedTitle = escapeHtml(tab.title); const escapedTitle = escapeHtml(tab.title);
const filename = cleanFilename(tab.title); const filename = cleanFilename(tab.title);
const content = new Blob([ console.log(`Escaped URL: "${escapedUrl}"`);
`<!DOCTYPE html> console.log(`Escaped title: "${escapedTitle}"`);
console.log(`Saving as: "${filename}"`);
const html = `<!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
@ -49,7 +55,11 @@ browser.browserAction.onClicked.addListener((tab) => {
Redirecting to: <a href="${escapedUrl}">${escapedUrl}</a> Redirecting to: <a href="${escapedUrl}">${escapedUrl}</a>
</body> </body>
</html> </html>
`]); `;
const content = new Blob([html]);
//console.log(`Generated HTML:\n${html}`);
browser.downloads.download({ browser.downloads.download({
filename: `${filename}.link.html`, filename: `${filename}.link.html`,

@ -2,7 +2,7 @@
"manifest_version":2, "manifest_version":2,
"author": "Ondřej Hruška", "author": "Ondřej Hruška",
"name":"Save Link to File", "name":"Save Link to File",
"version":"0.3", "version":"0.4",
"description":"Saves the current page as a HTML file with auto-redirect. It's like a bookmark you can store anywhere on your disk.", "description":"Saves the current page as a HTML file with auto-redirect. It's like a bookmark you can store anywhere on your disk.",
"icons":{ "icons":{
"48":"icon-dark.svg", "48":"icon-dark.svg",

Loading…
Cancel
Save