Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: tools/chrome_extensions/open_my_editor/ext/cr-content.js

Issue 2720793005: Add Open my editor (Closed)
Patch Set: add owners and change to py2 Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/chrome_extensions/open_my_editor/ext/cr-content.js
diff --git a/tools/chrome_extensions/open_my_editor/ext/cr-content.js b/tools/chrome_extensions/open_my_editor/ext/cr-content.js
new file mode 100644
index 0000000000000000000000000000000000000000..a5f8a959a1abcc39e0ea0abdd9e0b2f372ea1404
--- /dev/null
+++ b/tools/chrome_extensions/open_my_editor/ext/cr-content.js
@@ -0,0 +1,42 @@
+// Copyright 2017 Google Inc.
+//
+// Copyright 2017 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.
+
+// For codereview.chromium.org
watk 2017/03/02 23:13:49 Newline after. It looks like it's attached to the
+let clicked_element = null;
+
+document.addEventListener("mousedown", (event) => {
+ //right click
+ if (event.button == 2)
+ clicked_element = event.target;
+});
+
+chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
+ if (request == "getFiles") {
+ let element = clicked_element;
+ while (element != null && element.tagName != "TABLE")
+ element = element.parentElement;
+
+ let trs = element.getElementsByTagName("TR");
+ if (trs.length == 0)
+ alert("Please toggle one patchset.");
+
+ let files = [];
+ for (let i = 1; i < trs.length; ++i) {
+ let tr = trs[i];
+ if (tr.getAttribute("name") != "patch")
+ continue;
+ // Skip deleted file.
+ if (tr.children[1].firstChild.data == "D")
+ continue;
+
+ files.push(tr.children[2].children[0].text.replace(/\s*/g, ""));
+ }
+
+ sendResponse({ files: files });
+ } else if (request == "getFile" && clicked_element.tagName == "A") {
+ sendResponse({ file: clicked_element.text });
+ }
+});

Powered by Google App Engine
This is Rietveld 408576698