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

Delta Between Two Patch Sets: options.js

Issue 29458601: Issue 5315 - Add support for Microsoft Edge (Closed)
Left Patch Set: Workaround CSS.excape, i18n issue and use typeof for 'undefined' detection Created July 17, 2017, 12:51 p.m.
Right Patch Set: Cosmetic changes Created July 28, 2017, 11:02 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « metadata.edge ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 "downloadable", "special"); 62 "downloadable", "special");
63 const removeSubscription = wrapper({type: "subscriptions.remove"}, "url"); 63 const removeSubscription = wrapper({type: "subscriptions.remove"}, "url");
64 const addSubscription = wrapper({type: "subscriptions.add"}, 64 const addSubscription = wrapper({type: "subscriptions.add"},
65 "url", "title", "homepage"); 65 "url", "title", "homepage");
66 const toggleSubscription = wrapper({type: "subscriptions.toggle"}, 66 const toggleSubscription = wrapper({type: "subscriptions.toggle"},
67 "url", "keepInstalled"); 67 "url", "keepInstalled");
68 const updateSubscription = wrapper({type: "subscriptions.update"}, "url"); 68 const updateSubscription = wrapper({type: "subscriptions.update"}, "url");
69 const importRawFilters = wrapper({type: "filters.importRaw"}, 69 const importRawFilters = wrapper({type: "filters.importRaw"},
70 "text", "removeExisting"); 70 "text", "removeExisting");
71 const addFilter = wrapper({type: "filters.add"}, "text"); 71 const addFilter = wrapper({type: "filters.add"}, "text");
72 const getFilters = wrapper({type: "filters.get"}, "subscriptionUrl");
73 const removeFilter = wrapper({type: "filters.remove"}, "text"); 72 const removeFilter = wrapper({type: "filters.remove"}, "text");
73 const quoteCSS = wrapper({type: "composer.quoteCSS"}, "CSS");
74 74
75 const whitelistedDomainRegexp = /^@@\|\|([^/:]+)\^\$document$/; 75 const whitelistedDomainRegexp = /^@@\|\|([^/:]+)\^\$document$/;
76 const statusMessages = new Map([ 76 const statusMessages = new Map([
77 ["synchronize_invalid_url", 77 ["synchronize_invalid_url",
78 "filters_subscription_lastDownload_invalidURL"], 78 "filters_subscription_lastDownload_invalidURL"],
79 ["synchronize_connection_error", 79 ["synchronize_connection_error",
80 "filters_subscription_lastDownload_connectionError"], 80 "filters_subscription_lastDownload_connectionError"],
81 ["synchronize_invalid_data", 81 ["synchronize_invalid_data",
82 "filters_subscription_lastDownload_invalidData"], 82 "filters_subscription_lastDownload_invalidData"],
83 ["synchronize_checksum_mismatch", 83 ["synchronize_checksum_mismatch",
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // Load recommended subscriptions 180 // Load recommended subscriptions
181 loadRecommendations(); 181 loadRecommendations();
182 182
183 // Show user's filters 183 // Show user's filters
184 reloadFilters(); 184 reloadFilters();
185 } 185 }
186 $(loadOptions); 186 $(loadOptions);
187 187
188 function convertSpecialSubscription(subscription) 188 function convertSpecialSubscription(subscription)
189 { 189 {
190 getFilters(subscription.url, filters => 190 for (let filter of subscription.filters)
191 { 191 {
192 for (let filter of filters) 192 if (whitelistedDomainRegexp.test(filter.text))
193 { 193 appendToListBox("excludedDomainsBox", RegExp.$1);
194 if (whitelistedDomainRegexp.test(filter.text)) 194 else
195 appendToListBox("excludedDomainsBox", RegExp.$1); 195 appendToListBox("userFiltersBox", filter.text);
196 else 196 }
197 appendToListBox("userFiltersBox", filter.text);
198 }
199 });
200 } 197 }
201 198
202 // Reloads the displayed subscriptions and filters 199 // Reloads the displayed subscriptions and filters
203 function reloadFilters() 200 function reloadFilters()
204 { 201 {
205 // Load user filter URLs 202 // Load user filter URLs
206 let container = document.getElementById("filterLists"); 203 let container = document.getElementById("filterLists");
207 while (container.lastChild) 204 while (container.lastChild)
208 container.removeChild(container.lastChild); 205 container.removeChild(container.lastChild);
209 206
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 elt.value = text; 525 elt.value = text;
529 document.getElementById(boxId).appendChild(elt); 526 document.getElementById(boxId).appendChild(elt);
530 } 527 }
531 528
532 // Remove a filter string from a list box. 529 // Remove a filter string from a list box.
533 function removeFromListBox(boxId, text) 530 function removeFromListBox(boxId, text)
534 { 531 {
535 let list = document.getElementById(boxId); 532 let list = document.getElementById(boxId);
536 // Edge does not support CSS.escape yet: 533 // Edge does not support CSS.escape yet:
537 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/101410 / 534 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/101410 /
538 if (typeof CSS.escape == "undefined") 535 quoteCSS(text, escapedCSS =>
539 { 536 {
540 for (let i = 0; i < list.length; i++) 537 let selector = "option[value=" + escapedCSS + "]";
kzar 2017/07/17 14:08:19 This will be kinda slow when there are lots of fil
Sebastian Noack 2017/07/17 14:17:21 Couldn't we just do this instead of CSS.escape():
kzar 2017/07/17 14:27:02 I'm not sure that would always work, for example w
Sebastian Noack 2017/07/17 14:31:25 It seems that we have already implemented the same
kzar 2017/07/17 14:41:37 Sounds good to me. Though to avoid duplicating th
Sebastian Noack 2017/07/17 15:49:56 How about using messaging?
Oleksandr 2017/07/17 23:52:09 Done.
541 if (list.options[i].value == text)
542 list.remove(i--);
543 }
544 else
545 {
546 let selector = "option[value=" + CSS.escape(text) + "]";
547 for (let option of list.querySelectorAll(selector)) 538 for (let option of list.querySelectorAll(selector))
548 list.removeChild(option); 539 list.removeChild(option);
549 } 540 });
550 } 541 }
551 542
552 function addWhitelistDomain(event) 543 function addWhitelistDomain(event)
553 { 544 {
554 event.preventDefault(); 545 event.preventDefault();
555 546
556 let domain = document.getElementById( 547 let domain = document.getElementById(
557 "newWhitelistDomain" 548 "newWhitelistDomain"
558 ).value.replace(/\s/g, ""); 549 ).value.replace(/\s/g, "");
559 document.getElementById("newWhitelistDomain").value = ""; 550 document.getElementById("newWhitelistDomain").value = "";
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 onFilterMessage(message.action, message.args[0]); 735 onFilterMessage(message.action, message.args[0]);
745 break; 736 break;
746 case "prefs.respond": 737 case "prefs.respond":
747 onPrefMessage(message.action, message.args[0]); 738 onPrefMessage(message.action, message.args[0]);
748 break; 739 break;
749 case "subscriptions.respond": 740 case "subscriptions.respond":
750 onSubscriptionMessage(message.action, message.args[0]); 741 onSubscriptionMessage(message.action, message.args[0]);
751 break; 742 break;
752 } 743 }
753 }); 744 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld