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

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

Issue 2720793005: Add Open my editor (Closed)
Patch Set: change python2 to python 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..10860edab94d59646d9c2150757069a791c0282d
--- /dev/null
+++ b/tools/chrome_extensions/open_my_editor/ext/cr-content.js
@@ -0,0 +1,41 @@
+// 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
+
+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