Bookmarking Project Progress
.I started working on my bookmarking project, and have the JavaScript side more or less worked out.
The bookmarklet expects to be invoked as a keyword, with arguments. The arguments are separated by comma-space, as in “
The bookmarklet will then pop up a prompt asking for any comments on the page. Once that’s done, it adds a form to the page and submits it. The server is supposed to deal with the rest, but I haven’t built the database structure yet.
I haven’t decided whether or not I want to store page metadata (such as doctype and charset) outside of the page, as metadata in the database. At the moment I’m not doing so, but I should probably consider it. It would be a fairly easy change to make.
The only major feature I might attempt to add to the current JavaScript would be the ability to save linked assets, like images, as well, and that’s something I probably won’t tackle for a while. Here’s the bookmarklet in its current form:
(function () {
var bookmarkSubmitter = {
init: function() {
var bookmarkletArguments = "%s";
var argumentTest = "%" + "s";
if (bookmarkletArguments == argumentTest) {
bookmarkletArguments = "";
} else {
var doctype = document.doctype;
var doctypeString = "";
if (doctype != null) {
doctypeString = "\n";
}
var pageSource = doctypeString + "" + document.documentElement.innerHTML + "";
var pageURL = document.location;
if (bookmarkletArguments.indexOf("|") != -1) {
var tagList = bookmarkletArguments.split("|")[0];
var pageTitle = bookmarkletArguments.split("|")[1];
} else {
var tagList = bookmarkletArguments;
var pageTitle = document.title;
}
bookmarkSubmitter.makeForm(tagList, pageSource, pageURL, pageTitle);
}
},
makeForm: function(tagList, pageSource, pageURL, pageTitle) {
submissionForm = document.createElement("form");
submissionForm.action = "http://domain.tld/formpage";
submissionForm.method = "POST";
submissionForm.id = "bookmarkletSubmitterForm";
document.body.appendChild(submissionForm);
tagListInput = document.createElement("input");
tagListInput.name = "tagList";
tagListInput.id = "tagList";
tagListInput.value = tagList;
document.getElementById( "bookmarkletSubmitterForm" ).appendChild(tagListInput);
pageURLInput = document.createElement("input");
pageURLInput.name = "pageURL";
pageURLInput.id = "pageURL";
pageURLInput.value = pageURL;
document.getElementById( "bookmarkletSubmitterForm" ).appendChild(pageURLInput);
pageTitleInput = document.createElement("input");
pageTitleInput.name = "pageTitle";
pageTitleInput.id = "pageTitle";
pageTitleInput.value = pageTitle;
document.getElementById( "bookmarkletSubmitterForm" ).appendChild(pageTitleInput);
pageSourceInput = document.createElement("textarea");
pageSourceInput.name = "pageSource";
pageSourceInput.id = "pageSource";
pageSourceInput.value = pageSource;
document.getElementById( "bookmarkletSubmitterForm" ).appendChild(pageSourceInput);
pageCommentsInput = document.createElement("textarea");
pageCommentsInput.name = "pageComments";
pageCommentsInput.id = "pageComments";
var pageComments = prompt("Page Comments: ");
pageCommentsInput.value = pageComments;
document.getElementById( "bookmarkletSubmitterForm" ).appendChild(pageCommentsInput);
submissionForm.submit();
}
};
bookmarkSubmitter.init();
})();