Commits

Alexey Kozlov committed e374289

version 1.0

  • Participants

Comments (0)

Files changed (7)

File 128.png

Added
New image

File 16.png

Added
New image

File 48.png

Added
New image

File background.html

+<html>
+<head>
+ <script>
+
+  function checkForValidUrl(tabId, changeInfo, tab) {
+
+    up = tab.url.split('://', 2);
+    up_s = up[1].split('/');
+
+    if (up[0].indexOf('http') > -1 && (up_s.length > 2 || up_s[1].length > 0)) {
+
+      chrome.pageAction.show(tabId);
+
+    }
+  }
+
+  chrome.tabs.onUpdated.addListener(checkForValidUrl);
+
+ </script>
+</head>
+</html>

File manifest.json

+{
+   "name": "L-Cube",
+   "description": "Making breadcrumbs from URL",
+   "version": "1.0",
+   "background_page": "background.html",
+   "options_page": "options.html",
+   "page_action": {
+      "default_icon": "48.png",
+      "default_title": "Making breadcrumbs from URL",
+      "default_popup": "popup.html"
+   },
+   "icons": {
+      "128": "128.png",
+      "48": "48.png",
+      "16": "16.png"
+   },
+   "permissions": [ "tabs", "http://*/*", "https://*/*" ]
+}

File options.html

+<html>
+<head><title>L-Cube options:</title></head>
+<script type="text/javascript">
+
+// Saves options to localStorage.
+function save_options() {
+
+  if (document.getElementById("newtab").checked) {
+
+    localStorage["l3_newtab"] = 1;
+
+  } else {
+
+    localStorage["l3_newtab"] = 0;
+
+  }
+}
+
+// Restores options from localStorage.
+function restore_options() {
+
+  document.getElementById("newtab").checked = [ false, true ][localStorage["l3_newtab"]];
+
+}
+
+</script>
+
+<body onload="restore_options()">
+
+Open links in new tab: <input type="checkbox" id="newtab" onclick="save_options()" >
+
+</body>
+</html>
+<html>
+<head>
+ <style>
+  body {
+    min-width:500px;
+    /*overflow-x:hidden;*/
+  }
+  div {
+    padding:0 10px 10px 10px;
+  }
+  p {
+    padding:5px 0;
+    margin:0;
+  }
+ </style>
+ <script type="text/javascript">
+
+  chrome.tabs.executeScript(null, {code: "chrome.extension.sendRequest(document.URL);"});
+  chrome.extension.onRequest.addListener(function(request) { parse_url(request) });
+
+  function parse_url(request) {
+
+    url_parts = request.split('://' ,2)[1].split('/');
+    last_dir = url_parts.pop();
+    if (last_dir == '') {
+
+      url_parts.pop();
+
+    }
+    url_base = request.split('://' ,2)[0] + '://';
+    text_nodes = [];
+
+    for (i in url_parts) {
+
+      url_base = url_base + url_parts[i] + '/';
+      text_nodes.push(url_base);
+
+    }
+
+    output_div = document.getElementById("output");
+    output_div.innerHTML = '';
+    //while (output_div.firstChild)
+    //  output_div.removeChild(output_div.firstChild);
+
+    for (i in text_nodes) {
+
+      tmp_para = document.createElement("p");
+      tmp_a = document.createElement("a");
+      tmptext = document.createTextNode('[' + text_nodes[i] + ']');
+      tmp_a.appendChild(tmptext);
+      tmp_para.appendChild(tmp_a);
+      tmp_a.setAttribute("href", text_nodes[i]);
+      tmp_a.setAttribute("onClick", "javascript:run_link('" + text_nodes[i] + "');return false");
+      output_div.appendChild(tmp_para);
+
+    }
+  }
+
+  function run_link(target_url) {
+
+    if (localStorage["l3_newtab"] == 1) {
+
+      chrome.tabs.create({'url': target_url});
+
+    } else {
+
+      chrome.tabs.executeScript(null, {code: "location.href = '" + target_url + "'"});
+
+    }
+    window.close();
+
+  }
+
+ </script>
+</head>
+<body>
+<div>
+ <div style="float: left"><img src="48.png"></div>
+ <div id="output" style="float: left"></div>
+</div>
+</body>
+</html>