<ul class="contact">
<li class="first">Carnegie Mellon University</li>
<li>5000 Forbes Avenue, Pittsburgh, PA 15213</li>
</ul>
=>
<ul class="contact">
<li class="first">[univ]Carnegie Mellon University[/univ]</li>
<li>[address]5000 Forbes Avenue, Pittsburgh, PA 15213[/address]</li>
</ul>
shows the semantic annotation process I'd like to go through for thousands of web pages. To make my intention clear, I'd like to download all these web pages and have them annotated with user-defined tags (e.g., univ
, address
). The annotated pages will be used later for processing.
The most naive method I've been using is download the page, open the page file, edit the file with a text editor and save it. It's just too cumbersome.
A better approach I've been using is select the target text to be annotated from browser, inspect the target with tools like Firebug, edit the target text within the inspected view and save the edited page. This helps alleviate some burden, but still there's much room for improvement.
The ideal tool I'd like to have is one with which I can select the target text from the page within a browser, pick the corresponding annotation tag(preferably choosing from a tool bar which displays all tags available), and save the edited page with a single button.
If anyone knows such kind of tools, it would be great. But I doubt such a tool exists at all. Chances are I have to write such a tool myself. The question is, how should I get started? I have little web application developing experience.
Should I write a browser extension? Should I write a standalone application? In what language?
EDIT: A simpler version of the question can be found here. A complete working solution is preferred. I assume this problem is no big deal for experienced web developers but it might really take a while for me and I need to implement the function as soon as possible.
EDIT: Also, I prefer a tool bar right after selection to a drop-down list after right click. I think the tool bar for chrome extension Diigo Web Collector
is quite cool.
What's more, a save
button is needed on the tool bar to save the edited page to default or user specified place on computer. The buttons on the tool bar should be in this order: univ
address
tag3
tag4
... tagn
save
. The save button comes last.
EDIT: It seems impossible to download the edited page to local file system using Javascript. In either Chrome or Firefox, after we edit the source code of the page in the inspected view, there's a save button for us to save the edited page to local file system. How was that implemented? What I don't want about that save button is it always prompts for the directory to download the page. I'd like to make it a default directory with my own save button.
A chrome extension can automate this functionality, you can further extend this skeleton functionality for all possibilities.
The following skeleton adds a context menu for right click event of mouse for selection event1
A Menu is added to chrome browser and is activated when a selection is made as shown in this screen shot
Context Menu Appearance after selection of text
1- Selection context event fires when a selection of text is done by mouse click
Demonstration
Look at jsfiddle, after installation of chrome extension it annotates with user-defined tags
HTML Code Before
HTML Code After Selection
Select a
<li>
text from output console of jsfiddle through context menu added to chrome browser,you can see DOM is also changed!Code Reference
manifest.json
manifest file binds
content script(s)
andbackground page(s)
to extension.background.js
Create(s) Context menu and binds it to browser and activates context menu execution through message passing.
myscript.js
Further Extension
If you want to further add few more context menu(s)
1) create a variable for context menu as shown here in
background.js
2) add a case for switch in background page as shown here
3) handle your custom tag in content scripts by adding code as shown here
Testing and Loading Extension
Check How to Load an Extension for testing and extending this script.
References
EDIT 1
You can use following code of chrome extension for
To use this code use any of your fav icon(s) and put them in chrome directory for every tag
[univ]
and use corresponding names incss file
heremanifest.json
Registering
css and java script
forannotation tool
.myscript.css
Binding Icons here.
myscript.js
Code for updating selected text with custom tags.
Output1
Now You can replace any part of text
Output 2
Replace any web page
Saving file to chosen Location
It is possible to download the page using chrome.pageCapture API, but to a
sand boxed
location.Sample Implementation on using pageCapture API
manifest.json
popup.html
popup.js
Test this code using steps above by picking your icons of choice, hope this helps :)
Edit 2
images
,js
andcss
files is possible from chrome extensionA browser extension should be fine. A standalone application would need to utilize a full-fledged browser, which is cumbersome.
Only with a browser extension (in contrast to a bookmarklet) you would have the permission to save the results directly to the filesystem. You can add the "Annotate" button to the browser (G)UI as well.
However, storing thousands of HTML files on your harddisk might not be your aim. Instead, you could set up a simple database server to which you post the annotation results. A small bookmarklet with some ajax code would be enough on the clientside then.