-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this allows you to select a part of a page. When you fill int the form a message is sent toe the server and a snippet is created
- Loading branch information
Showing
10 changed files
with
307 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-module(addbookmark). | ||
-compile(export_all). | ||
|
||
start(Str) -> | ||
%% io:format("Str=~p~n",[Str]), | ||
T = sebg:parse_uri_args(Str), | ||
%% io:format("add bookmark:~p~n",[T]), | ||
Time = proplists:get_value("time", T), | ||
File = time_to_file(Time), | ||
file:write_file(File, term_to_binary(T)). | ||
|
||
time_to_file([$\s|T]) -> [$_|time_to_file(T)]; | ||
time_to_file([$(|T]) -> [$_|time_to_file(T)]; | ||
time_to_file([$)|T]) -> [$_|time_to_file(T)]; | ||
time_to_file([H|T]) -> [H|time_to_file(T)]; | ||
time_to_file([]) -> ".snip". | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Clipper 1.2 | ||
|
||
This is a chrome unpacked extension | ||
|
||
To install goto | ||
Chrome -> Window -> Extensions | ||
|
||
click on "Load unpacked extension" | ||
and select the directory where this extension is contained | ||
|
||
Help Needed | ||
=========== | ||
|
||
This is just a beginning. Better analysis of the selection | ||
is highly desirable | ||
|
||
Credits | ||
======= | ||
|
||
The code in this extension is a modified version of | ||
a chrome extension that I found on the net (and a blog) | ||
article. The name of the extension was | ||
|
||
"name": "Linx Bookmark 1.1", | ||
"description": "Adds the current page to the Linx bookmarking system.", | ||
"version": "1.1", | ||
|
||
Unfortunately I cannot give a more precise reference, and | ||
have not been able to find the original. Mail my if you stumble over | ||
the origonal | ||
|
||
|
||
Some the code in content_script.js | ||
came form | ||
|
||
http://dev.day.com/content/ddc/blog/2010/06.html | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script> | ||
// Array to hold callback functions | ||
var callbacks = []; | ||
|
||
// This function is called onload in the popup code | ||
function getPageInfo(callback) | ||
{ | ||
// Add the callback to the queue | ||
callbacks.push(callback); | ||
|
||
// Inject the content script into the current page | ||
// console.log('injecting'); | ||
chrome.tabs.executeScript(null, { file: "content_script.js" }); | ||
}; | ||
|
||
// Perform the callback when a request is received from the content script | ||
chrome.extension.onRequest.addListener(function(request) | ||
{ | ||
// Get the first callback in the callbacks array | ||
// and remove it from the array | ||
var callback = callbacks.shift(); | ||
|
||
// Call the callback function | ||
callback(request); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// code cut-and-paste from | ||
// http://dev.day.com/content/ddc/blog/2010/06.html | ||
|
||
// console.log('injecting code'); | ||
|
||
function getContent() { | ||
// console.log('getting selection'); | ||
var selection = window.getSelection( ); | ||
var markup = serializeSelection( selection ); | ||
// var finalMarkup = formatPage( markup ); | ||
// return finalMarkup; | ||
return markup; | ||
} | ||
|
||
function serializeSelection( selection ) { | ||
var xmlFragment = ""; | ||
try { | ||
var n = 0, ranges = selection.rangeCount; | ||
// console.log('ranges='+ranges); | ||
while ( n != ranges ) { | ||
var range = selection.getRangeAt( n++ ); | ||
// console.log('here',range); | ||
var content = range.cloneContents( ); | ||
var serializer = new XMLSerializer( ); | ||
xmlFragment += serializer.serializeToString( content ); | ||
} | ||
} | ||
catch( msg ) { } | ||
return xmlFragment; | ||
} | ||
|
||
content = getContent(); | ||
|
||
// console.log('content',content); | ||
|
||
|
||
var pageInfo = { | ||
"title": document.title, | ||
"url": window.location.href, | ||
"text": window.getSelection().toString(), | ||
"html": content | ||
}; | ||
|
||
// console.log('sending page',pageInfo) | ||
// Send the information back to the extension | ||
|
||
chrome.extension.sendRequest(pageInfo); | ||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "Clipper 1.2", | ||
"description": "Clipper release 1 - first production version", | ||
"version": "1.2", | ||
"background_page": "background.html", | ||
"permissions": [ | ||
"tabs", | ||
"http://localhost:*//*/*", | ||
"http://*/*", | ||
"https://*/*" | ||
], | ||
"browser_action": { | ||
"default_title": "Clipper", | ||
"default_icon": "icon.png", | ||
"popup": "popup.html" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<html> | ||
<head> | ||
<style> | ||
body | ||
{ | ||
min-width: 420px; | ||
overflow-x: hidden; | ||
font-family: Arial, sans-serif; | ||
font-size: 12px; | ||
} | ||
input, textarea { width: 420px; } | ||
input#save { font-weight: bold; width: auto; } | ||
</style> | ||
<script> | ||
|
||
var text,html; | ||
|
||
// This onPageInfo is called when the content script has been | ||
// injected and returned its results | ||
// it builds the form | ||
|
||
function onPageInfo(o) | ||
{ | ||
document.getElementById("title").value = o.title; | ||
document.getElementById("url").value = o.url; | ||
document.getElementById("notes").innerText = ""; | ||
text = o.text; // store in global | ||
html = o.html; // store in global | ||
} | ||
|
||
|
||
|
||
// POST the data to the server using XMLHttpRequest | ||
function addBookmark(f) | ||
{ | ||
var req = new XMLHttpRequest(); | ||
req.open("POST", "http://localhost:1234/mod/addbookmark/", true); | ||
|
||
var params = | ||
"title=" + escape(document.getElementById("title").value) + | ||
"&time=" + escape(new Date().toLocaleString()) + | ||
"&text=" + escape(text) + | ||
"&html=" + escape(html) + | ||
"&url=" + escape(document.getElementById("url").value) + | ||
"¬es=" + escape(document.getElementById("notes").value) + | ||
"&tags=" + escape(document.getElementById("tags").value); | ||
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | ||
req.setRequestHeader("Content-length", params.length); | ||
req.setRequestHeader("Connection", "close"); | ||
|
||
req.send(params); | ||
|
||
req.onreadystatechange = function() | ||
{ | ||
// If the request completed, close the extension popup | ||
if (req.readyState == 4) | ||
if (req.status == 200) window.close(); | ||
}; | ||
|
||
return false; | ||
} | ||
|
||
// Call the getPageInfo function in the background page, passing in | ||
// our onPageInfo function as the callback | ||
window.onload = function() | ||
{ | ||
var bg = chrome.extension.getBackgroundPage(); | ||
bg.getPageInfo(onPageInfo); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<form id="addbookmark" onsubmit="addBookmark(this); return false;"> | ||
<p><label for="title">Title</label><br /> | ||
<input type="text" id="title" name="title" size="50" value="" /></p> | ||
<p><label for="url">Url</label><br /> | ||
<input type="text" id="url" name="url" size="50" value="" /></p> | ||
<p><label for="notes">Notes</label><br /> | ||
<textarea id="notes" name="notes" rows="6" cols="35"></textarea></p> | ||
<p><label for="tags">Tags</label><br /> | ||
<input type="text" id="tags" name="tags" size="50" value="" /></p> | ||
<p><input id="save" type="submit" value="Save Bookmark" /></p> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.