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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/snippets_internals.js
diff --git a/chrome/browser/resources/snippets_internals.js b/chrome/browser/resources/snippets_internals.js
index e49205b6e4d77afbc46156290c5761cc847b54e5..8b062f02e2c0c7737cb042b98f6132f99df662e3 100644
--- a/chrome/browser/resources/snippets_internals.js
+++ b/chrome/browser/resources/snippets_internals.js
@@ -6,27 +6,25 @@ cr.define('chrome.SnippetsInternals', function() {
'use strict';
function initialize() {
- function submitDownload(event) {
+ $('submit-download').addEventListener('click', function(event) {
chrome.send('download', [$('hosts-input').value]);
event.preventDefault();
- }
-
- $('submit-download').addEventListener('click', submitDownload);
+ });
- function submitClear(event) {
+ $('submit-clear').addEventListener('click', function(event) {
chrome.send('clear');
event.preventDefault();
- }
+ });
- $('submit-clear').addEventListener('click', submitClear);
+ $('submit-dump').addEventListener('click', function(event) {
+ chrome.send('dump');
+ event.preventDefault();
+ });
- function submitClearDiscarded(event) {
+ $('discarded-snippets-clear').addEventListener('click', function(event) {
chrome.send('clearDiscarded');
event.preventDefault();
- }
-
- $('discarded-snippets-clear').addEventListener('click',
- submitClearDiscarded);
+ });
chrome.send('loaded');
}
@@ -38,7 +36,8 @@ cr.define('chrome.SnippetsInternals', function() {
function receiveHosts(hosts) {
displayList(hosts, 'hosts');
- $('hosts-input').value = hosts.list.map(host => host.url).join(' ');
+ $('hosts-input').value = hosts.list.map(
+ function(host) { return host.url;}).join(' ');
}
function receiveSnippets(snippets) {
@@ -50,6 +49,13 @@ cr.define('chrome.SnippetsInternals', function() {
'discarded-snippet-title');
}
+ function receiveJson(json) {
+ 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.
+ link.download = 'snippets.json';
+ link.href = 'data:,' + json;
+ link.click();
+ }
+
function displayList(object, domId, titleClass) {
jstProcess(new JsEvalContext(object), $(domId));
@@ -67,16 +73,13 @@ cr.define('chrome.SnippetsInternals', function() {
if ($(domId + '-empty')) $(domId + '-empty').textContent = text;
if ($(domId + '-clear')) $(domId + '-clear').style.display = display;
- function trigger(event) {
- // The id of the snippet is stored to 'snippet-id' attribute of the link.
- var id = event.currentTarget.getAttribute('snippet-id');
- $(id).classList.toggle('snippet-hidden');
- event.preventDefault();
- }
-
var links = document.getElementsByClassName(titleClass);
for (var link of links) {
- link.addEventListener('click', trigger);
+ link.addEventListener('click', function(event) {
+ var id = event.currentTarget.getAttribute('snippet-id');
+ $(id).classList.toggle('snippet-hidden');
+ event.preventDefault();
+ });
}
}
@@ -87,6 +90,7 @@ cr.define('chrome.SnippetsInternals', function() {
receiveHosts: receiveHosts,
receiveSnippets: receiveSnippets,
receiveDiscardedSnippets: receiveDiscardedSnippets,
+ receiveJson: receiveJson,
};
});

Powered by Google App Engine
This is Rietveld 408576698