Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added 2 files that were accidentally left untracked.

  • Loading branch information...
commit ed02163e1b1a2f6c10123a2876e965572123af88 1 parent d5f6238
@victorquinn authored
Showing with 67 additions and 0 deletions.
  1. +8 −0 duckduckgo.js
  2. +59 −0 global.html
View
8 duckduckgo.js
@@ -0,0 +1,8 @@
+document.addEventListener("contextmenu", ddgHandler, false);
+
+function ddgHandler(ddgEvent) {
+ var sel = '';
+ sel = window.parent.getSelection()+'';
+ sel = sel.replace(/^\s+|\s+$/g,"");
+ safari.self.tab.setContextMenuEventUserInfo(ddgEvent, sel);
+}
View
59 global.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset='utf-8' />
+ <title>DuckDuckGo</title>
+ <script type="text/javascript">
+ function ddgRightClickCommand(event) {
+ var searchTerms = event.userInfo;
+ var secure = safari.extension.settings.getItem("ddg_secure");
+ if (secure) {
+ searchURL = "https://duckduckgo.com/?q=" + searchTerms;
+ }
+ else {
+ searchURL = "http://duckduckgo.com/?q=" + searchTerms;
+ }
+
+ ddgRightClickStyle = safari.extension.settings.getItem("ddgRightClickStyle");
+ switch(ddgRightClickStyle) {
+ case 'newTab':
+ var tab = safari.application.activeBrowserWindow.openTab("foreground");
+ tab.url = searchURL;
+ break;
+ case 'bgTab':
+ var tab = safari.application.activeBrowserWindow.openTab("background");
+ tab.url = searchURL;
+ break;
+ case 'newWindow':
+ safari.application.openBrowserWindow();
+ case 'curTab':
+ safari.application.activeBrowserWindow.activeTab.url = searchURL;
+ break;
+ }
+ var searchField = document.getElementById("searchField");
+ searchField.value = safari.application.activeBrowserWindow.getSelection;
+ // safari.self.browserWindow.openTab();
+
+ // safari.application.activeBrowserWindow.activeTab.url = "https://duckduckgo.com/?q=" + searchField.value;
+ }
+ function ddgRightClickValidate(event) {
+ var selectedText = event.userInfo;
+ if (event.command !== 'ddgRightClickHandler' || selectedText === undefined) {
+ return;
+ }
+ if (selectedText.length == 0 || !selectedText) {
+ event.target.disabled = true;
+ }
+ if (selectedText.length > 30) {
+ selectedText = selectedText.substr(0,30);
+ selectedText = selectedText.replace(/^\s+|\s+$/g,"");
+ selectedText = selectedText + "...";
+ }
+
+ event.target.title = 'Search for "' + selectedText + '" on DuckDuckGo';
+ }
+ safari.application.addEventListener("validate", ddgRightClickValidate, false);
+ safari.application.addEventListener("command", ddgRightClickCommand, false);
+ </script>
+ </head>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.