Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: options.js

Issue 29333544: Issue 3515 - Use fetch() API instead XMLHttpRequest (UI) (Closed)
Patch Set: Created Jan. 14, 2016, 5:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 collections.whitelist.addItems(filter); 305 collections.whitelist.addItems(filter);
306 } 306 }
307 else 307 else
308 collections.customFilters.addItems(filter); 308 collections.customFilters.addItems(filter);
309 309
310 filtersMap[filter.text] = filter; 310 filtersMap[filter.text] = filter;
311 } 311 }
312 312
313 function loadRecommendations() 313 function loadRecommendations()
314 { 314 {
315 var request = new XMLHttpRequest(); 315 fetch("subscriptions.xml")
316 request.open("GET", "subscriptions.xml", false); 316 .then(function(response)
317 request.addEventListener("load", function()
318 {
319 var list = document.getElementById("subscriptionSelector");
320 var docElem = request.responseXML.documentElement;
321 var elements = docElem.getElementsByTagName("subscription");
322 for (var i = 0; i < elements.length; i++)
323 { 317 {
324 var element = elements[i]; 318 return response.text();
325 var subscription = Object.create(null); 319 })
326 subscription.title = element.getAttribute("title"); 320 .then(function(text)
327 subscription.url = element.getAttribute("url"); 321 {
328 subscription.disabled = null; 322 var list = document.getElementById("subscriptionSelector");
329 subscription.downloadStatus = null; 323 var doc = new DOMParser().parseFromString(text, "application/xml");
330 subscription.homepage = null; 324 var elements = doc.documentElement.getElementsByTagName("subscription");
331 subscription.lastSuccess = null; 325 for (var i = 0; i < elements.length; i++)
332 var recommendation = Object.create(null);
333 recommendation.type = element.getAttribute("type");
334 var prefix = element.getAttribute("prefixes");
335 if (prefix)
336 { 326 {
337 prefix = prefix.replace(/\W/g, "_"); 327 var element = elements[i];
338 subscription.title = ext.i18n.getMessage("options_language_" + prefix) ; 328 var subscription = Object.create(null);
329 subscription.title = element.getAttribute("title");
330 subscription.url = element.getAttribute("url");
331 subscription.disabled = null;
332 subscription.downloadStatus = null;
333 subscription.homepage = null;
334 subscription.lastSuccess = null;
335 var recommendation = Object.create(null);
336 recommendation.type = element.getAttribute("type");
337 var prefix = element.getAttribute("prefixes");
338 if (prefix)
339 {
340 prefix = prefix.replace(/\W/g, "_");
341 subscription.title = ext.i18n.getMessage("options_language_" + prefi x);
342 }
343 else
344 {
345 var type = recommendation.type.replace(/\W/g, "_");
346 subscription.title = ext.i18n.getMessage("common_feature_" + type + "_title");
347 }
348
349 recommendationsMap[subscription.url] = recommendation;
350 updateSubscription(subscription);
339 } 351 }
340 else 352 });
341 {
342 var type = recommendation.type.replace(/\W/g, "_");
343 subscription.title = ext.i18n.getMessage("common_feature_" + type + "_ title");
344 }
345
346 recommendationsMap[subscription.url] = recommendation;
347 updateSubscription(subscription);
348 }
349 }, false);
350 request.send(null);
351 } 353 }
352 354
353 function onClick(e) 355 function onClick(e)
354 { 356 {
355 var element = e.target; 357 var element = e.target;
356 while (true) 358 while (true)
357 { 359 {
358 if (!element) 360 if (!element)
359 return; 361 return;
360 362
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 filter: ["added", "loaded", "removed"] 819 filter: ["added", "loaded", "removed"]
818 }); 820 });
819 ext.backgroundPage.sendMessage( 821 ext.backgroundPage.sendMessage(
820 { 822 {
821 type: "subscriptions.listen", 823 type: "subscriptions.listen",
822 filter: ["added", "disabled", "homepage", "removed", "title"] 824 filter: ["added", "disabled", "homepage", "removed", "title"]
823 }); 825 });
824 826
825 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 827 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
826 })(); 828 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld