-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Options update #29
Options update #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
var capture = function(){ | ||
var replace_all = function(str, find, replace) { return str.replace(new RegExp(find, 'g'), replace); }; | ||
var esc = function (text) { return replace_all(replace_all(replace_all(encodeURIComponent(text),"[(]",escape("(")),"[)]",escape(")")),"[']",escape("'")); }; | ||
var selection = window.getSelection().toString(); | ||
|
||
var uri = 'org-protocol://'; | ||
if (selection != "") | ||
{ | ||
uri += 'capture:/p/'; | ||
} | ||
else | ||
{ | ||
uri += 'capture:/L/' | ||
}; | ||
function replace_all(str, find, replace) { | ||
return str.replace(new RegExp(find, 'g'), replace); | ||
} | ||
|
||
uri += encodeURIComponent(location.href) + '/' + | ||
esc(document.title) ; | ||
function escapeIt(text) { | ||
return replace_all(replace_all(replace_all(encodeURIComponent(text), "[(]", escape("(")), | ||
"[)]", escape(")")), | ||
"[']" ,escape("'")); | ||
} | ||
|
||
if (selection != "") { uri += '/' + esc(selection); }; | ||
function createCaptureURL(template, title, url, selection, oldStyle) { | ||
if (oldStyle == true) | ||
return "org-protocol://capture:/"+template+'/'+url+'/'+title + ((selection === '') ? '' : ('/' + selection)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use consistent equality operator (see below) |
||
else | ||
return "org-protocol://capture?template="+template+'&url='+url+'&title='+title+((selection === '') ? '' : ('&body=' + selection)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are using a regular URL syntax here, the selection should be escaped using encodeURIComponent as well. |
||
} | ||
|
||
console.log("Capturing the following URI with org-protocol:", uri); | ||
function captureIt() { | ||
var selection = window.getSelection().toString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please escape the selection as well, not just the title. |
||
var url = encodeURIComponent(location.href); | ||
var title = escapeIt(document.title); | ||
|
||
location.href=uri; | ||
}; | ||
chrome.storage.sync.get({ | ||
selectedTemplate: 'p', | ||
unselectedTemplate: 'L', | ||
useOldStyleLinks: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make the default to old style links, for the benefit of those who already have the extension installed. |
||
}, function(items) { | ||
var uri = ''; | ||
if (selection != '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use consistent equality operator (see above) |
||
uri = createCaptureURL(items.selectedTemplate, title, url, selection, items.useOldStyleLinks); | ||
else | ||
uri = createCaptureURL(items.unselectedTemplate, title, url, selection, items.useOldStyleLinks); | ||
alert(uri); | ||
location.href = uri; | ||
}); | ||
} | ||
|
||
capture(); | ||
captureIt(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Org Capture Settings</title> | ||
<style> | ||
body: { padding: 10px; } | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
||
<table> | ||
<tr> | ||
<td> | ||
Selected Template | ||
</td> | ||
<td> | ||
<input id="selTemplate" /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
Unselected Template | ||
</td> | ||
<td> | ||
<input id="unselTemplate"> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
Use Old-Style Links? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add write that new-style is the recommended option for supported org-mode versions above 9.0 |
||
</td> | ||
<td> | ||
<input id="useOldstyle" type="checkbox" /> | ||
</td> | ||
</table> | ||
|
||
<div id="status"></div> | ||
<button id="save">Save</button> | ||
|
||
<script src="options.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Saves options to chrome.storage.sync. | ||
function save_options() { | ||
var selTemp = document.getElementById('selTemplate').value; | ||
var unselTemp = document.getElementById('unselTemplate').value; | ||
var oldStyleP = document.getElementById('useOldstyle').checked; | ||
chrome.storage.sync.set({ | ||
selectedTemplate: selTemp, | ||
unselectedTemplate: unselTemp, | ||
useOldStyleLinks: oldStyleP | ||
}, function() { | ||
// Update status to let user know options were saved. | ||
var status = document.getElementById('status'); | ||
status.textContent = 'Options saved.'; | ||
setTimeout(function() { | ||
status.textContent = ''; | ||
}, 750); | ||
}); | ||
} | ||
|
||
// Restores select box and checkbox state using the preferences | ||
// stored in chrome.storage. | ||
function restore_options() { | ||
// Use default value color = 'red' and likesColor = true. | ||
chrome.storage.sync.get({ | ||
selectedTemplate: 'L', | ||
unselectedTemplate: 'p', | ||
useOldStyleLinks: false | ||
}, function(items) { | ||
document.getElementById('unselTemplate').value = items.unselectedTemplate; | ||
document.getElementById('selTemplate').value = items.selectedTemplate; | ||
document.getElementById('useOldstyle').checked = items.useOldStyleLinks; | ||
}); | ||
} | ||
document.addEventListener('DOMContentLoaded', restore_options); | ||
document.getElementById('save').addEventListener('click', | ||
save_options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if oldStyle is a boolean, there is no need for
== true