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

Delta Between Two Patch Sets: html/static/js/firstRun.js

Issue 4812049892769792: Add acceptable ads message in FRP (Closed)
Left Patch Set: Created July 24, 2014, 7:47 a.m.
Right Patch Set: Cosmetic fixes Created July 24, 2014, 9:12 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 | « no previous file | html/templates/firstRun.html » ('j') | 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 { 96 {
97 return Prefs.documentation_link 97 return Prefs.documentation_link
98 .replace(/%LINK%/g, page) 98 .replace(/%LINK%/g, page)
99 .replace(/%LANG%/g, Utils.appLocale); 99 .replace(/%LANG%/g, Utils.appLocale);
100 } 100 }
101 101
102 function initTranslations() 102 function initTranslations()
103 { 103 {
104 // Map message ID to HTML element ID 104 // Map message ID to HTML element ID
105 var mapping = { 105 var mapping = {
106 "aa-title": "first-run-aa-title",
107 "aa-text": "first-run-aa-text",
106 "title-main": "first-run-title-install", 108 "title-main": "first-run-title-install",
107 "share-text1": "first-run-share1", 109 "share-text1": "first-run-share1",
108 "share-text2": "first-run-share2", 110 "share-text2": "first-run-share2",
109 "share-donate": "first-run-share2-donate", 111 "share-donate": "first-run-share2-donate",
110 "share2-connection": "first-run-share2-or", 112 "share2-connection": "first-run-share2-or"
111 "aa-title": "first-run-aa-title",
112 "aa-text": "first-run-aa-text"
113 }; 113 };
114 114
115 document.title = AdblockPlus.getMessage("first-run", "first-run-title-install" ); 115 document.title = AdblockPlus.getMessage("first-run", "first-run-title-install" );
116 for (var i in mapping) 116 for (var i in mapping)
117 { 117 {
118 var element = document.getElementById(i); 118 var element = document.getElementById(i);
119 element.innerHTML = AdblockPlus.getMessage("first-run", mapping[i]); 119 setElementText(element, AdblockPlus.getMessage("first-run", mapping[i]));
Felix Dahlke 2014/07/24 08:04:22 This would introduce an XSS vulnerability, I'm afr
120 } 120 }
121 } 121 }
122 122
123 function init() 123 function init()
124 { 124 {
125 // Choose a share text variant randomly 125 // Choose a share text variant randomly
126 var variant = Math.floor(Math.random() * 2) + 1; 126 var variant = Math.floor(Math.random() * 2) + 1;
127 var classList = document.documentElement.className.split(" "); 127 var classList = document.documentElement.className.split(" ");
128 classList.push("share-variant-" + variant); 128 classList.push("share-variant-" + variant);
129 document.documentElement.className = classList.join(" "); 129 document.documentElement.className = classList.join(" ");
130 130
131 initTranslations(); 131 initTranslations();
132 initSocialLinks(variant); 132 initSocialLinks(variant);
133 setLinks("aa-text", getDocLink("acceptable_ads_criteria"), "index.html"); 133 setLinks("aa-text", getDocLink("acceptable_ads_criteria"), "index.html");
134 134
135 var donateLink = document.getElementById("share-donate"); 135 var donateLink = document.getElementById("share-donate");
136 donateLink.href = getDocLink("donate") + "&variant=" + variant; 136 donateLink.href = getDocLink("donate") + "&variant=" + variant;
137 } 137 }
138 138
139 // Inserts i18n strings into matching elements. Any inner HTML already in the
140 // element is parsed as JSON and used as parameters to substitute into
141 // placeholders in the i18n message.
142 setElementText = function(element, elementHtml)
143 {
144 function processString(str, element)
145 {
146 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str);
147 if (match)
148 {
149 processString(match[1], element);
150
151 var e = document.createElement(match[2]);
152 processString(match[3], e);
153 element.appendChild(e);
154
155 processString(match[4], element);
156 }
157 else
158 element.appendChild(document.createTextNode(str));
159 }
160
161 while (element.lastChild)
162 element.removeChild(element.lastChild);
163 processString(elementHtml, element);
164 }
165
166
139 function setLinks(id) 167 function setLinks(id)
140 { 168 {
141 var element = document.getElementById(id); 169 var element = document.getElementById(id);
142 if (!element) 170 if (!element)
143 { 171 {
144 return; 172 return;
145 } 173 }
146 174
147 var links = element.getElementsByTagName("a"); 175 var links = element.getElementsByTagName("a");
148 176
149 for (var i = 0; i < links.length; i++) 177 for (var i = 0; i < links.length && i < arguments.length - 1; i++)
Felix Dahlke 2014/07/24 08:04:22 Please also check that |i < arguments.length - 1|
150 { 178 {
151 if (typeof arguments[i + 1] == "string") 179 var curArg = arguments[i + 1];
Felix Dahlke 2014/07/24 08:04:22 It'd be cleaner to put arguments[i + 1] in a tempo
180 if (typeof curArg == "string")
152 { 181 {
153 links[i].href = arguments[i + 1]; 182 links[i].href = curArg;
154 links[i].setAttribute("target", "_blank"); 183 links[i].setAttribute("target", "_blank");
155 } 184 }
156 else if (typeof arguments[i + 1] == "function") 185 else if (typeof curArg == "function")
157 { 186 {
158 links[i].href = "javascript:void(0);"; 187 links[i].href = "javascript:void(0);";
159 links[i].addEventListener("click", arguments[i + 1], false); 188 links[i].addEventListener("click", curArg, false);
160 } 189 }
161 } 190 }
162 } 191 }
163 192
164 window.addEventListener("load", init); 193 window.addEventListener("load", init);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld