gao shuai avatar gao shuai committed 30e7fc3

chromeExtention

Comments (0)

Files changed (4)

chromExtention/README

+Demo Chrome Extension that uses the Tab Pinning API. Enables a new keyboard
+shortcut (Ctrl + Shift + P) to toggle pinning and unpinning of the current tab.

chromExtention/background.html

+<!DOCTYPE html>
+<!--
+ * Copyright (c) 2011 The Chromium Authors. All rights reserved.  Use of this
+ * source code is governed by a BSD-style license that can be found in the
+ * LICENSE file.
+-->
+<head>
+<title>Keyboard Pin</title>
+<script>
+chrome.extension.onRequest.addListener(
+  function(request, sender, sendResponse) {
+    if (request.toggle_pin) {
+      // Get the currently selected tab
+      chrome.tabs.getSelected(null, function(tab) { 
+        // Toggle the pinned status
+        chrome.tabs.update(tab.id, {'pinned': !tab.pinned});
+      });
+    }
+  }
+);
+</script>
+</head>

chromExtention/inject.js

+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+function httpGet(theUrl){
+    var xmlHttp = null;
+
+    xmlHttp = new XMLHttpRequest();
+    xmlHttp.open( "GET", theUrl, false );
+    xmlHttp.send( null );
+    return xmlHttp.responseText;
+}
+function post_to_url(path, params, method) {
+    method = method || "post"; // Set method to post by default, if not specified.
+
+    // The rest of this code assumes you are not using a library.
+    // It can be made less wordy if you use one.
+    var form = document.createElement("form");
+    form.setAttribute("method", method);
+    form.setAttribute("action", path);
+
+    for(var key in params) {
+        var hiddenField = document.createElement("input");
+        hiddenField.setAttribute("type", "hidden");
+        hiddenField.setAttribute("name", key);
+        hiddenField.setAttribute("value", params[key]);
+
+        form.appendChild(hiddenField);
+    }
+
+    document.body.appendChild(form);
+    form.submit();
+}
+window.addEventListener("keydown", function(event) {
+  // Bind to both command (for Mac) and control (for Win/Linux)
+  var modifier = event.ctrlKey || event.metaKey;
+  if (modifier && event.shiftKey && event.keyCode == 80) {
+		var sel = window.getSelection().toString();
+		alert(httpGet("http://fy.gongda.tk/translate/"+sel));
+  }
+  else if (modifier && event.shiftKey && event.keyCode == 83) {
+		var sel = window.getSelection().toString();
+		post_to_url("http://fy.gongda.tk/swap/new",{"content" : sel});
+  }
+  else if (modifier && event.shiftKey && event.keyCode == 76) {
+		var sel = window.getSelection().toString();
+		post_to_url("http://fy.gongda.tk/li/new",{"content" : sel});
+  }
+}, false);

chromExtention/manifest.json

+{
+  "name": "Keyboard Pin",
+  "version": "0.1",
+  "description": "Creates a keyboard shortcut (C + Shift + P) to toggle the pinned state of the currently selected tab",
+  "permissions": [
+    "tabs"
+  ],
+  "background_page": "background.html",
+  "content_scripts": [
+    {
+      "matches": ["<all_urls>"],
+      "js": ["inject.js"]
+    }
+  ]
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.