initial version

master
Ondřej Hruška 4 years ago
commit 03128e7515
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      .gitignore
  2. 3
      .web-extension-id
  3. 58
      background.js
  4. 79
      icon.svg
  5. 29
      manifest.json

1
.gitignore vendored

@ -0,0 +1 @@
web-ext-artifacts

@ -0,0 +1,3 @@
# This file was created by https://github.com/mozilla/web-ext
# Your auto-generated extension ID for addons.mozilla.org is:
@save_link_to_file

@ -0,0 +1,58 @@
/** HTML escape */
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
/** Escape URL chars that could throw off the meta redirect tag */
function sanitizeUrl(unsafe) {
return unsafe
.replace(/;/g, "%3B");
}
/** Remove the most risky characters from a filename string */
function cleanFilename(unsafe) {
return unsafe
.replace(/[/\\?*|"'<>:]+/g, " ")
.replace(/\s+/g, " ");
}
browser.browserAction.onClicked.addListener((tab) => {
const escapedUrl = escapeHtml(sanitizeUrl(tab.url));
const escapedTitle = escapeHtml(tab.title);
const filename = cleanFilename(tab.title);
const content = new Blob([
`<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>${escapedTitle}</title>
<meta http-equiv="refresh" content="0; url=${escapedUrl}">
<style>
body {
padding: 1em;
text-align: center;
font-family: sans-serif;
color:#aaa;
}
a, a:visited, a:hover, a:link {
color:#888;
}
</style>
</head>
<body>
Redirecting to: <a href="${escapedUrl}">${escapedUrl}</a>
</body>
</html>
`]);
browser.downloads.download({
filename: `${filename}.link.html`,
url: URL.createObjectURL(content)
});
});

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="42"
height="42"
viewBox="0 0 112 112"
version="1.1"
id="svg4"
sodipodi:docname="icon.svg"
inkscape:version="0.92.4 5da689c313, 2019-01-14">
<metadata
id="metadata10">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs8" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1139"
id="namedview6"
showgrid="true"
inkscape:zoom="6.9532167"
inkscape:cx="-11.076832"
inkscape:cy="2.0520977"
inkscape:window-x="0"
inkscape:window-y="30"
inkscape:window-maximized="1"
inkscape:current-layer="svg4"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0">
<inkscape:grid
type="xygrid"
id="grid4522"
originx="-4.4089761"
originy="-21.842435" />
</sodipodi:namedview>
<path
style="fill:#0071ff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2.66666675px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 22.752019,6.9806825 H 41.343764 V 37.093346 H 59.935507 L 32.047892,69.356911 2.3010931,37.093346 H 22.752019 Z"
id="path4520"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccccc" />
<path
style="fill:none;fill-rule:evenodd;stroke:#0071ff;stroke-width:8.53333378;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 78.237951,59.234645 C 61.985372,50.183904 37.606511,86.386874 49.795957,99.962984 66.04852,109.01371 90.427368,77.336122 82.301101,63.760013"
id="path4524"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc" />
<path
style="fill:none;fill-rule:evenodd;stroke:#0071ff;stroke-width:8.53333378;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 74.322044,89.148066 C 90.574618,98.198804 114.95354,61.995844 102.76408,48.419735 86.511469,39.368997 62.132613,71.046584 70.2589,84.622694"
id="path4524-3"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc" />
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

@ -0,0 +1,29 @@
{
"applications":{
"gecko":{
"id":"@save_link_to_file",
"strict_min_version":"64.0"
}
},
"manifest_version":2,
"author": "Ondřej Hruška",
"name":"Save Link to File",
"version":"0.2",
"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":{
"48":"icon.svg",
"128":"icon.svg"
},
"background":{
"scripts":["background.js"]
},
"permissions":[
"activeTab",
"downloads"
],
"browser_action": {
"browser_style": true,
"default_icon": "icon.svg",
"default_title": "Save Link"
}
}
Loading…
Cancel
Save