Permalink
Browse files

Removing inline script that are not allowed anymore.

  • Loading branch information...
1 parent 04424a4 commit 01b8aae1215c2789c68893164f4b69bc6cc8fdd9 @cezarsa committed Jun 22, 2012
Showing with 554 additions and 518 deletions.
  1. +182 −0 lib/locales/page.js
  2. +32 −0 lib/notifier/init.js
  3. +317 −0 lib/options/page.js
  4. +11 −1 lib/tweet_manager.js
  5. +1 −185 locales.html
  6. +8 −296 options.html
  7. +3 −36 tweets_notifier.html
View
@@ -0,0 +1,182 @@
+var LocaleTable = function() {
+ this.locales = {};
+ this.tableEl = Util.makeElem('table', {id: "localeTable"});
+ document.body.appendChild(this.tableEl);
+ this.loadData();
+};
+LocaleTable.prototype = {
+ _caseInsensitiveCompare: function(a, b) {
+ return a.toUpperCase().localeCompare(b.toUpperCase());
+ },
+
+ prepareLocaleData: function() {
+ this.orderedLocaleCodes = [];
+ for(var localeCode in this.locales) {
+ this.orderedLocaleCodes.push(localeCode);
+ }
+ this.orderedLocaleCodes.sort(this._caseInsensitiveCompare);
+
+ this.orderedKeywords = [];
+ for(var i = 0, len = this.orderedLocaleCodes.length; i < len; ++i) {
+ var localeData = this.locales[this.orderedLocaleCodes[i]];
+ for(var keyword in localeData) {
+ if(Util.inArray(keyword, this.orderedKeywords) == -1) {
+ this.orderedKeywords.push(keyword);
+ }
+ }
+ }
+ this.orderedKeywords.sort(this._caseInsensitiveCompare);
+ },
+
+ drawTable: function() {
+ this.prepareLocaleData();
+ while(this.tableEl.firstChild) {
+ this.tableEl.removeChild(this.tableEl.firstChild);
+ }
+
+ var emptyCount = {};
+ for(var i = 0, len = this.orderedKeywords.length; i < len; ++i) {
+ var keyword = this.orderedKeywords[i];
+ var rowEl = Util.makeElem('tr');
+ var titleCellEl = Util.makeElem('th', null, keyword);
+ rowEl.appendChild(titleCellEl);
+ var isKeywordComplete = true;
+ for(var j = 0, len2 = this.orderedLocaleCodes.length; j < len2; ++j) {
+ var localeCode = this.orderedLocaleCodes[j];
+ var localeData = this.locales[localeCode];
+ var message = localeData.hasOwnProperty(keyword) ? localeData[keyword].message : '-';
+ var className = '';
+ if(message == '-') {
+ className = 'empty';
+ emptyCount[localeCode] = emptyCount[localeCode] ? emptyCount[localeCode] + 1 : 1;
+ isKeywordComplete = false;
+ }
+ var cellEl = Util.makeElem('td', {'class': className}, message);
+ rowEl.appendChild(cellEl);
+ }
+ var isPropertyInDefault = this.locales[this.defaultLocale] && this.locales[this.defaultLocale].hasOwnProperty(keyword);
+ if(!isPropertyInDefault) {
+ rowEl.className = 'invalid';
+ } else if(!isKeywordComplete) {
+ rowEl.className = 'incomplete';
+ }
+ this.tableEl.appendChild(rowEl);
+ }
+
+ var titleRowEl = Util.makeElem('tr');
+ titleRowEl.appendChild(Util.makeElem('th'));
+ for(var k = 0, len3 = this.orderedLocaleCodes.length; k < len3; ++k) {
+ var code = this.orderedLocaleCodes[k];
+ var localeCellEl = Util.makeElem('th', null, code);
+ if(emptyCount[code]) {
+ localeCellEl.appendChild(Util.makeElem('span', {'class': 'empty_count'}, ' (' + emptyCount[code] + ')'));
+ }
+ titleRowEl.appendChild(localeCellEl);
+ }
+ this.tableEl.insertBefore(titleRowEl, this.tableEl.childNodes[0]);
+ },
+
+ loadData: function() {
+ var _this = this;
+ this.loadDefaultLocale(function(defaultLocale) {
+ _this.defaultLocale = defaultLocale;
+ _this.loadLocaleMessages(function(locales) {
+ _this.locales = locales;
+ _this.drawTable();
+ });
+ });
+ },
+
+ loadDefaultLocale: function(callback) {
+ Util.ajax(function(status, data) {
+ if(data) {
+ data = JSON.parse(data);
+ callback(data.default_locale);
+ }
+ }, 'manifest.json');
+ },
+
+ showError: function(message) {
+ document.body.appendChild(Util.makeElem('h2', {}, message));
+ },
+
+ loadLocaleMessages: function(callback) {
+ var remainingLocalesMap = {};
+ for(var k = 0, codesLen = LocaleTable.availableLocaleCodes.length; k < codesLen; ++k) {
+ remainingLocalesMap[LocaleTable.availableLocaleCodes[k]] = true;
+ }
+ var locales = {};
+ var updateLocaleCallback = function(localeCode, data) {
+ delete remainingLocalesMap[localeCode];
+ if(data) {
+ locales[localeCode] = data;
+ }
+ if(Util.isEmptyObject(remainingLocalesMap)) {
+ callback(locales);
+ }
+ };
+ var _this = this;
+ for(var i = 0, len = LocaleTable.availableLocaleCodes.length; i < len; ++i) {
+ var localeCode = LocaleTable.availableLocaleCodes[i];
+ (function(localeCode) {
+ Util.ajax(function(status, data) {
+ if(data) {
+ try {
+ data = JSON.parse(data);
+ } catch(e) {
+ _this.showError('Invalid JSON file for "' + localeCode + '", check console.');
+ console.log('Invalid JSON', data, e);
+ throw e;
+ }
+ }
+ updateLocaleCallback(localeCode, data);
+ }, '_locales/' + localeCode + '/messages.json');
+ })(localeCode);
+ }
+ }
+};
+LocaleTable.availableLocaleCodes = ["az", "am", "ar", "bg", "bn", "ca", "cs", "da", "de", "el", "en", "en_GB", "en_US", "es",
+ "es_419", "et", "fi", "fil", "fr", "gu", "he", "hi", "hr", "hu", "id", "it", "ja", "kn", "ko", "lt", "lv",
+ "ml", "mr", "nb", "nl", "or", "pl", "pt", "pt_BR", "pt_PT", "ro", "ru", "sk", "sl", "sr", "sv", "sw",
+ "ta", "te", "th", "tr", "uk", "vi", "zh", "zh_CN", "zh_TW"];
+
+var Util = {
+ ajax: function(callback, url) {
+ var req = new XMLHttpRequest();
+ req.open('GET', url, true);
+ req.onreadystatechange = function() {
+ if(req.readyState == 4) {
+ callback(req.status, req.responseText, req);
+ }
+ };
+ req.send();
+ },
+ makeElem: function(elem, attrs, content) {
+ var el = document.createElement(elem);
+ if(attrs) {
+ for (var attrName in attrs) {
+ el.setAttribute(attrName, attrs[attrName]);
+ }
+ }
+ if(content) {
+ el.innerText = content;
+ }
+ return el;
+ },
+ inArray: function(elem, array) {
+ for(var i = 0, len = array.length; i < len; ++i) {
+ if(elem == array[i]) {
+ return i;
+ }
+ }
+ return -1;
+ },
+ isEmptyObject: function(obj) {
+ for(var p in obj) {
+ return false;
+ }
+ return true;
+ }
+};
+
+new LocaleTable();
View
@@ -0,0 +1,32 @@
+var OptionsBackend = chrome.extension.getBackgroundPage().OptionsBackend;
+var urlExpander = chrome.extension.getBackgroundPage().urlExpander;
+var tweetManager = chrome.extension.getBackgroundPage().TweetManager.instance;
+var ImageService = chrome.extension.getBackgroundPage().ImageService;
+
+chrome.i18n.getMessage = chrome.extension.getBackgroundPage().chrome.i18n.getMessage;
+
+var fadeTimeout = OptionsBackend.get('notification_fade_timeout');
+
+try {
+ var tweet = tweetManager.injectTweets.shift();
+ Renderer.setContext('desktop');
+ $(document.body).prepend(Renderer.renderTweet(tweet, false, OptionsBackend.get('name_attribute')));
+} catch(e) {
+ console.log(e);
+ window.close();
+}
+
+setTimeout(function() {
+ $("#progress").text(chrome.i18n.getMessage("preventClosing"));
+ $('#progress').show().css('bottom', '0px').css('width', '100%').
+ animate({width: '0px'}, fadeTimeout, 'linear', function() {
+ // Tell manager that this tweet shouldn't be marked as read
+ tweetManager.shouldNotReadMap[tweet.id] = true;
+ window.close();
+ });
+
+ $(document.body).click(function() {
+ $('#progress').stop().hide();
+ });
+}, 100);
+
Oops, something went wrong.

0 comments on commit 01b8aae

Please sign in to comment.