Skip to content

TagSpaces is an offline, open source, document manager with tagging support

enhancing the browser extension to save the source url and saved data

uggrock93d75719a91b
diff --git a/data/chromium/popup.html b/data/chromium/popup.html
index ca8dcee08..1aedf1386 100644
--- a/data/chromium/popup.html
+++ b/data/chromium/popup.html
@@ -10,7 +10,7 @@ can be found in the LICENSE file.
<title></title>
<link rel="stylesheet" type="text/css" href="../assets/tagspaces.css">
</head>
-<body style="width: 520px; height: 400px; padding:0; font-size: 14px; background-color: #f9f9f9;">
+<body style="width: 520px; height: 420px; padding:0; font-size: 14px; background-color: #f9f9f9;">
<div class="well" style="margin: 0; border: 0px; background-color: transparent;">
<div style="white-space: nowrap;" class="text-center">
<img src="../assets/icon128.png" class="pull-left" style="margin-left: 20px; max-height: 32px; max-width: 32px;"/>&nbsp;&nbsp;
diff --git a/data/chromium/popup.js b/data/chromium/popup.js
index b078f67f9..ee5e20e77 100644
--- a/data/chromium/popup.js
+++ b/data/chromium/popup.js
@@ -13,6 +13,8 @@
var htmlTemplate;
var tagLibrary;
var fileExt;
+ var currentTabURL;
+ var currentTabID;
function init() {
$("#startTagSpaces").on("click", function(e) {
@@ -25,7 +27,9 @@
var tagList = extractAllTags(tagLibrary);
chrome.tabs.getSelected(null, function(tab) {
- fileExt = getFileExt(tab.url);
+ currentTabURL = tab.url;
+ currentTabID = tab.id;
+ fileExt = getFileExt(currentTabURL);
$('#title').val(tab.title.substring(tab.title.lastIndexOf("/") + 1, tab.title.length));
$("#saveSelectionAsHtml").attr("disabled", (fileExt !== 'mhtml'));
});
@@ -91,18 +95,16 @@
}
function saveAsBookmark() {
- chrome.tabs.getSelected(null, function(tab) {
- var filename;
- tags = document.getElementById("tags").value;
- if (tags) {
- tags = tags.split(",").join(" ");
- filename = $('#title').val() + ' [' + tags + '].url';
- } else {
- filename = $('#title').val() + '.url';
- }
- var content = '[InternetShortcut]\r\nURL=' + tab.url;
- saveAs(content, filename);
- });
+ var filename;
+ tags = document.getElementById("tags").value;
+ if (tags) {
+ tags = tags.split(",").join(" ");
+ filename = $('#title').val() + ' [' + tags + '].url';
+ } else {
+ filename = $('#title').val() + '.url';
+ }
+ var content = '[InternetShortcut]\r\nURL=' + currentTabURL + '';
+ saveAs(content, filename);
}
function saveAsMHTML() {
@@ -115,22 +117,19 @@
filename = $('#title').val() + '.' + fileExt;
}
- chrome.tabs.getSelected(null, function(tab) {
-
- if (fileExt === 'mhtml') {
- chrome.pageCapture.saveAsMHTML({
- tabId: tab.id
- }, function(mhtml) {
- saveAs(mhtml, filename);
- });
- } else {
- chrome.downloads.download({
- url: tab.url,
- filename: filename,
- saveAs: true
- });
- }
- });
+ if (fileExt === 'mhtml') {
+ chrome.pageCapture.saveAsMHTML({
+ tabId: currentTabID
+ }, function(mhtml) {
+ saveAs(mhtml, filename);
+ });
+ } else {
+ chrome.downloads.download({
+ url: currentTabURL,
+ filename: filename,
+ saveAs: true
+ });
+ }
}
function saveScreenshot() {
@@ -205,7 +204,7 @@
});
// end saving all images*/
- cleanedHTML = "<body>" + cleanedHTML + "</body>";
+ cleanedHTML = "<body data-sourceUrl='" + currentTabURL + "' data-scrapedOn='" + (new Date()) + "' >" + cleanedHTML + "</body>";
if (htmlTemplate) {
cleanedHTML = htmlTemplate.replace(/\<body[^>]*\>([^]*)\<\/body>/m, cleanedHTML); // jshint ignore:line
}
diff --git a/data/mozilla/main.js b/data/mozilla/main.js
index 507518c0c..4a9c94dd9 100644
--- a/data/mozilla/main.js
+++ b/data/mozilla/main.js
@@ -107,9 +107,10 @@ function initToobarButton() {
data.url('mozilla/popup.js')
],
onShow: function() {
- var contextExt = capture.getFileExt(tabs.activeTab.url.toString());
- tagspacesPanel.port.emit("show", selection.html,
- tabs.activeTab.title.toString(), contextExt);
+ var currentURL = tabs.activeTab.url.toString();
+ var contextExt = capture.getFileExt(currentURL);
+ tagspacesPanel.port.emit("show", selection.html,
+ tabs.activeTab.title.toString(), contextExt, currentURL);
},
onHide: function() {
tagspacesPanel.port.emit("hide");
diff --git a/data/mozilla/popup.js b/data/mozilla/popup.js
index 4cd97b3aa..0df7413aa 100644
--- a/data/mozilla/popup.js
+++ b/data/mozilla/popup.js
@@ -9,6 +9,7 @@
var htmlTemplate;
var tagLibrary;
var currentSelection;
+ var currentURL;
var currentExt;
function init() {
@@ -61,8 +62,7 @@
function prepareContent(uncleanedHTML) {
//console.log("uncleaned "+uncleanedHTML);
var cleanedHTML = DOMPurify.sanitize(uncleanedHTML);
-
- cleanedHTML = "<body>" + cleanedHTML + "</body>";
+ cleanedHTML = "<body data-sourceUrl='" + currentURL + "' data-scrapedOn='" + (new Date()) + ">" + cleanedHTML + "</body>";
cleanedHTML = htmlTemplate.replace(/\<body[^>]*\>([^]*)\<\/body>/m, cleanedHTML); // jshint ignore:line
return cleanedHTML;
}
@@ -99,11 +99,12 @@
//$(document).ready(init);
init();
- self.port.on("show", function(selection, title, ext) {
+ self.port.on("show", function(selection, title, ext, cURL) {
//self.postMessage('show', "ddd1");
loadSettingsLocalStorage();
currentSelection = selection;
+ currentURL = cURL;
currentExt = ext;
var tagList = extractAllTags(tagLibrary);