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

Side by Side Diff: chrome/browser/resources/snippets_internals.js

Issue 1907233002: Allows to dump current snippets to a json in the Downloads folder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor cleanup Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('chrome.SnippetsInternals', function() { 5 cr.define('chrome.SnippetsInternals', function() {
6 'use strict'; 6 'use strict';
7 7
8 function initialize() { 8 function initialize() {
9 function submitDownload(event) { 9 $('submit-download').addEventListener('click', function(event) {
10 chrome.send('download', [$('hosts-input').value]); 10 chrome.send('download', [$('hosts-input').value]);
11 event.preventDefault(); 11 event.preventDefault();
12 } 12 });
13 13
14 $('submit-download').addEventListener('click', submitDownload); 14 $('submit-clear').addEventListener('click', function(event) {
15
16 function submitClear(event) {
17 chrome.send('clear'); 15 chrome.send('clear');
18 event.preventDefault(); 16 event.preventDefault();
19 } 17 });
20 18
21 $('submit-clear').addEventListener('click', submitClear); 19 $('submit-dump').addEventListener('click', function(event) {
20 chrome.send('dump');
21 event.preventDefault();
22 });
22 23
23 function submitClearDiscarded(event) { 24 $('discarded-snippets-clear').addEventListener('click', function(event) {
24 chrome.send('clearDiscarded'); 25 chrome.send('clearDiscarded');
25 event.preventDefault(); 26 event.preventDefault();
26 } 27 });
27
28 $('discarded-snippets-clear').addEventListener('click',
29 submitClearDiscarded);
30 28
31 chrome.send('loaded'); 29 chrome.send('loaded');
32 } 30 }
33 31
34 function receiveProperty(propertyId, value) { 32 function receiveProperty(propertyId, value) {
35 $(propertyId).textContent = value; 33 $(propertyId).textContent = value;
36 } 34 }
37 35
38 function receiveHosts(hosts) { 36 function receiveHosts(hosts) {
39 displayList(hosts, 'hosts'); 37 displayList(hosts, 'hosts');
40 38
41 $('hosts-input').value = hosts.list.map(host => host.url).join(' '); 39 $('hosts-input').value = hosts.list.map(
40 function(host) { return host.url;}).join(' ');
42 } 41 }
43 42
44 function receiveSnippets(snippets) { 43 function receiveSnippets(snippets) {
45 displayList(snippets, 'snippets', 'snippet-title'); 44 displayList(snippets, 'snippets', 'snippet-title');
46 } 45 }
47 46
48 function receiveDiscardedSnippets(discardedSnippets) { 47 function receiveDiscardedSnippets(discardedSnippets) {
49 displayList(discardedSnippets, 'discarded-snippets', 48 displayList(discardedSnippets, 'discarded-snippets',
50 'discarded-snippet-title'); 49 'discarded-snippet-title');
51 } 50 }
52 51
52 function receiveJson(json) {
53 var link = document.createElement('a');
Bernhard Bauer 2016/04/25 10:32:22 Add a comment here that explains what you're doing
jkrcal 2016/04/25 12:04:15 Done.
54 link.download = 'snippets.json';
55 link.href = 'data:,' + json;
56 link.click();
57 }
58
53 function displayList(object, domId, titleClass) { 59 function displayList(object, domId, titleClass) {
54 jstProcess(new JsEvalContext(object), $(domId)); 60 jstProcess(new JsEvalContext(object), $(domId));
55 61
56 var text; 62 var text;
57 var display; 63 var display;
58 64
59 if (object.list.length > 0) { 65 if (object.list.length > 0) {
60 text = ''; 66 text = '';
61 display = 'inline'; 67 display = 'inline';
62 } else { 68 } else {
63 text = 'The list is empty.'; 69 text = 'The list is empty.';
64 display = 'none'; 70 display = 'none';
65 } 71 }
66 72
67 if ($(domId + '-empty')) $(domId + '-empty').textContent = text; 73 if ($(domId + '-empty')) $(domId + '-empty').textContent = text;
68 if ($(domId + '-clear')) $(domId + '-clear').style.display = display; 74 if ($(domId + '-clear')) $(domId + '-clear').style.display = display;
69 75
70 function trigger(event) {
71 // The id of the snippet is stored to 'snippet-id' attribute of the link.
72 var id = event.currentTarget.getAttribute('snippet-id');
73 $(id).classList.toggle('snippet-hidden');
74 event.preventDefault();
75 }
76
77 var links = document.getElementsByClassName(titleClass); 76 var links = document.getElementsByClassName(titleClass);
78 for (var link of links) { 77 for (var link of links) {
79 link.addEventListener('click', trigger); 78 link.addEventListener('click', function(event) {
79 var id = event.currentTarget.getAttribute('snippet-id');
80 $(id).classList.toggle('snippet-hidden');
81 event.preventDefault();
82 });
80 } 83 }
81 } 84 }
82 85
83 // Return an object with all of the exports. 86 // Return an object with all of the exports.
84 return { 87 return {
85 initialize: initialize, 88 initialize: initialize,
86 receiveProperty: receiveProperty, 89 receiveProperty: receiveProperty,
87 receiveHosts: receiveHosts, 90 receiveHosts: receiveHosts,
88 receiveSnippets: receiveSnippets, 91 receiveSnippets: receiveSnippets,
89 receiveDiscardedSnippets: receiveDiscardedSnippets, 92 receiveDiscardedSnippets: receiveDiscardedSnippets,
93 receiveJson: receiveJson,
90 }; 94 };
91 }); 95 });
92 96
93 document.addEventListener('DOMContentLoaded', 97 document.addEventListener('DOMContentLoaded',
94 chrome.SnippetsInternals.initialize); 98 chrome.SnippetsInternals.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698