Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removing inline script that are not allowed anymore.

  • Loading branch information...
commit 01b8aae1215c2789c68893164f4b69bc6cc8fdd9 1 parent 04424a4
@cezarsa authored
View
182 lib/locales/page.js
@@ -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
32 lib/notifier/init.js
@@ -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);
+
View
317 lib/options/page.js
@@ -0,0 +1,317 @@
+var LocaleTable = chrome.extension.getBackgroundPage().LocaleTable;
+var ImageService = chrome.extension.getBackgroundPage().ImageService;
+var IconCreator = chrome.extension.getBackgroundPage().IconCreator;
+var tweetManager = chrome.extension.getBackgroundPage().TweetManager.instance;
+
+chrome.i18n.getMessage = chrome.extension.getBackgroundPage().chrome.i18n.getMessage;
+
+var twitterBackend = tweetManager.twitterBackend;
+var options = new Options();
+var imgEl = null;
+
+function paintIcon(canvas, color) {
+ if(!imgEl) {
+ var img = $('<img>').attr('src', 'img/icon19.png');
+ img.load(function() {
+ imgEl = img[0];
+ var imgData = IconCreator.paintIcon(imgEl, color);
+ canvas.getContext("2d").putImageData(imgData, 0, 0);
+ });
+ } else {
+ var imgData = IconCreator.paintIcon(imgEl, color);
+ canvas.getContext("2d").putImageData(imgData, 0, 0);
+ }
+}
+
+
+function bindEvents() {
+ $("#Yes").bind('click', function() {
+ options.confirmRestart();
+ });
+
+ $("#No").bind('click', function() {
+ options.denyRestart();
+ });
+
+ $("#btn_reset_popup_size").bind('click', function() {
+ Persistence.popupSize().remove();
+ });
+
+ $("#btn_save").bind('click', function() {
+ options.save();
+ });
+
+ $("#btn_reset").bind('click', function() {
+ options.load();
+ });
+
+ $("#btn_default").bind('click', function() {
+ options.loadDefaults();
+ });
+}
+
+
+var hourlyLimit = 150;
+$(function() {
+ bindEvents();
+
+ $("input.i18n").each(function() {
+ $(this).val(chrome.i18n.getMessage(this.id));
+ });
+
+ $(".i18n").not("input .htmlSafe").each(function() {
+ $(this).text(chrome.i18n.getMessage(this.id));
+ });
+
+ $(".i18n.htmlSafe").each(function() {
+ $(this).html(chrome.i18n.getMessage(this.id));
+ });
+
+ var resetDateObj = new Date();
+ if(twitterBackend) {
+ var hitsInfo = twitterBackend.remainingHitsInfo();
+ $(".twitter_hits_left").text(hitsInfo[0]);
+
+ resetDateObj.setTime(parseInt(hitsInfo[1], 10) * 1000);
+ $(".twitter_hits_reset").text(resetDateObj.toLocaleDateString() + " " + resetDateObj.toLocaleTimeString());
+
+ if(hitsInfo[2]) {
+ hourlyLimit = parseInt(hitsInfo[2], 10);
+ }
+ }
+ $(".__hourly_limit").text(hourlyLimit);
+
+ $("select[name='default_locale']").append($("<option>").attr('value', 'auto').text(chrome.i18n.getMessage('automatic')));
+ for(var localeCode in LocaleTable.instance.locales) {
+ $("select[name='default_locale']").append($("<option>").attr('value', localeCode).text(localeCode));
+ }
+
+ for(var key in SHORTENERS_BACKEND) {
+ var desc = SHORTENERS_BACKEND[key].desc;
+ $("select[name='url_shortener']").append($("<option>").attr('value', key).text(desc));
+ }
+
+ for(var i = 0, len = ImageService.services.length; i < len; ++i) {
+ var service = ImageService.services[i];
+ if(service.hasUpload()) {
+ $("select[name='image_upload_service']").append($("<option>").attr('value', service.domain).text(service.domain));
+ }
+ }
+
+ var onShortenerChange = function() {
+ $("#shortener_opts").hide();
+ $("#yourls_opts").hide();
+ $("#googl_opts").hide();
+ var shortenerSelect = $("select[name='url_shortener']")[0];
+ if(shortenerSelect.value == 'bitly' || shortenerSelect.value == 'jmp' || shortenerSelect.value == 'karmacracy') {
+ $("#shortener_opts").show();
+ } else if(shortenerSelect.value == 'yourls') {
+ $("#yourls_opts").show();
+ } else if(shortenerSelect.value == 'googl') {
+ $("#googl_opts").show();
+ }
+ };
+
+ var onShortenerAcctClick = function() {
+ if($("input[name='shortener_acct']").is(':checked')) {
+ $("input[name='shortener_login']").removeAttr('disabled');
+ $("input[name='shortener_key']").removeAttr('disabled');
+ } else {
+ $("input[name='shortener_login']").val('').attr('disabled', 'disabled');
+ $("input[name='shortener_key']").val('').attr('disabled', 'disabled');
+ }
+ };
+ $("select[name='url_shortener']").change(onShortenerChange);
+ $("input[name='shortener_acct']").click(onShortenerAcctClick);
+
+ var onSigningUrlCheck = function() {
+ var $check = $("input[name='same_signing_urls']");
+ if($check.is(':checked')) {
+ $("input[name='base_signing_url'], input[name='base_oauth_signing_url']").attr('disabled', 'disabled');
+ $("input[name='base_signing_url']").val($("input[name='base_url']").val());
+ $("input[name='base_oauth_signing_url']").val($("input[name='base_oauth_url']").val());
+
+ $("input[name='base_url']").bind('keyup blur', function() {
+ $("input[name='base_signing_url']").val($(this).val());
+ });
+ $("input[name='base_oauth_url']").bind('keyup blur', function() {
+ $("input[name='base_oauth_signing_url']").val($(this).val());
+ });
+ } else {
+ $("input[name='base_signing_url'], input[name='base_oauth_signing_url']").removeAttr('disabled');
+
+ $("input[name='base_url']").unbind('keyup blur');
+ $("input[name='base_oauth_url']").unbind('keyup blur');
+ }
+ };
+ $("input[name='same_signing_urls']").click(onSigningUrlCheck);
+
+ $('canvas.color_selector').ColorPicker({
+ onChange: function (hsb, hex, rgb, rgbaStr) {
+ var canvas = this.data('colorpicker').el;
+ $(canvas).attr('strColor', rgbaStr);
+ paintIcon(canvas, rgb);
+ }
+ });
+ $('div.color_selector').ColorPicker({
+ onChange: function (hsb, hex, rgb, rgbaStr) {
+ var div = this.data('colorpicker').el;
+ $(div).attr('strColor', rgbaStr);
+ $(div).css('backgroundColor', rgbaStr);
+ }
+ });
+ options.onload(function() {
+ onShortenerChange();
+ onShortenerAcctClick();
+ onSigningUrlCheck();
+ });
+ options.onsaveChangedOption(function(optionName, oldValue, newValue) {
+ var idx, templateId;
+ if((idx = optionName.indexOf('_visible')) != -1) {
+ templateId = optionName.substring(0, idx);
+ if(newValue) {
+ tweetManager.showTimelineTemplate(templateId, true);
+ } else {
+ tweetManager.hideTimelineTemplate(templateId);
+ }
+ } else if((idx = optionName.indexOf('_include_unified')) != -1) {
+ templateId = optionName.substring(0, idx);
+ tweetManager.toggleUnified(templateId, newValue);
+ } else if(optionName == 'trending_topics_woeid') {
+ tweetManager.cachedTrendingTopics = null;
+ }
+ });
+ options.onsave(function() {
+ if($("#noti_desktop").is(":checked")) {
+ try {
+ var notificationCenter = window.notifications || window.webkitNotifications;
+ if(!notificationCenter) {
+ throw 'out';
+ }
+ var authStatus = notificationCenter.checkPermission();
+ if(authStatus == 1 || authStatus == 2) { // Not allowed or Denied
+ notificationCenter.requestPermission(function() {
+ var authStatus = notificationCenter.checkPermission();
+ if(authStatus !== 0) { // Permission denied
+ $("#noti_on_page").click();
+ options.save();
+ }
+ });
+ }
+ } catch(boom) {
+ $("#noti_on_page").click();
+ options.save();
+ }
+ }
+ });
+ options.load();
+
+ var createTTSelect = function(ttLocales) {
+ $("select[name='trending_topics_woeid']").empty();
+ $.each(ttLocales, function(i, locale){
+ $("select[name='trending_topics_woeid']").append($("<option>").attr('value', locale.woeid).text(locale.name));
+ });
+ $("select[name='trending_topics_woeid']").val(OptionsBackend.get('trending_topics_woeid'));
+ };
+ var woeids = tweetManager.retrieveTrendingRegions(function(woeids) {
+ createTTSelect(woeids);
+ });
+ createTTSelect(woeids);
+
+ updatePredictedHitsCount();
+ $('table.timelines input, table.timelines select').
+ keyup(updatePredictedHitsCount).
+ blur(updatePredictedHitsCount).
+ click(updatePredictedHitsCount).
+ change(updatePredictedHitsCount);
+
+ $("input[name='microblogging_service'],label[for='service_twitter'],label[for='service_identica']").mousedown(function(e) {
+ var el = $(e.target);
+ if(el.is('label')) {
+ el = $('#' + el.attr('for'));
+ }
+ if(!el.is(':checked')) {
+ var proceed = confirm("This will reset any custom API URL configuration. Proceed?");
+ if(proceed) {
+ el.click();
+ var sameSigningEl = $("input[name='same_signing_urls']");
+ var baseUrlEl = $("input[name='base_url']");
+ var baseOauthUrlEl = $("input[name='base_oauth_url']");
+
+ if(el.val() == 'twitter') {
+ baseUrlEl.val('http://api.twitter.com/1/');
+ baseOauthUrlEl.val('https://twitter.com/oauth/');
+ } else if(el.val() == 'identica') {
+ baseUrlEl.val('http://identi.ca/api/');
+ baseOauthUrlEl.val('https://identi.ca/api/oauth/');
+ }
+ baseUrlEl.blur();
+ baseOauthUrlEl.blur();
+ if(!sameSigningEl.is(':checked')) {
+ sameSigningEl.attr('checked', true).click().attr('checked', true);
+ }
+ }
+ }
+ return true;
+ });
+
+ $("#nerds_link").click(function() {
+ var $canvas = $("#nerds");
+ $canvas.toggle();
+ if($canvas.is(":visible")) {
+ var points = chrome.extension.getBackgroundPage().TweetManager.instance.apiHitsStates;
+ Math.generateTendencyGraph($canvas[0], points, resetDateObj.getTime());
+ }
+ });
+});
+
+function updatePredictedHitsCount() {
+ var totalHits = 0;
+ var unifiedVisible = $('input[name="unified_visible"]').is(':checked');
+
+ TimelineTemplate.eachTimelineTemplate(function(template) {
+ if(template.id == TimelineTemplate.UNIFIED) {
+ return true;
+ }
+ var inputUnifiedEl = $('input[name="' + template.id + '_include_unified"]');
+ if(!unifiedVisible) {
+ inputUnifiedEl.attr('disabled', 'disabled');
+ } else {
+ inputUnifiedEl.removeAttr('disabled');
+ }
+ if(template.id == TimelineTemplate.SEARCH) {
+ return true;
+ }
+ var inputVisibleEl = $('input[name="' + template.id + '_visible"]');
+ if(!inputVisibleEl.is(':checked') && !(unifiedVisible && inputUnifiedEl.is(':checked'))) {
+ return true;
+ }
+
+ var inputRefreshEl = $('input[name="' + template.id + '_refresh_interval"]');
+ var intVal = parseInt(inputRefreshEl.val(), 10);
+ var timelineHits = (60 * 60) / intVal;
+ var timelineCount = 1;
+ if(template.id == TimelineTemplate.DMS) {
+ timelineCount = 2;
+ } else {
+ var userData = template.getUserData();
+ if(userData && userData.length > 0) {
+ timelineCount = userData.length;
+ }
+ }
+
+ totalHits += timelineHits * timelineCount;
+ return true;
+ });
+ totalHits += (60 * 60) / parseInt($('input[name="blockedusers_refresh_interval"]').val(), 10);
+ totalHits = parseInt(totalHits, 10);
+ $('#predicted_hits_count').text(totalHits);
+ if(totalHits >= hourlyLimit) {
+ $('#predicted_hits_count').css('backgroundColor', 'red');
+ } else if(totalHits >= hourlyLimit * 0.85) {
+ $('#predicted_hits_count').css('backgroundColor', 'yellow');
+ } else {
+ $('#predicted_hits_count').css('backgroundColor', 'white');
+ }
+ return totalHits;
+}
View
12 lib/tweet_manager.js
@@ -773,7 +773,17 @@ TweetManager.prototype = {
},
getCurrentTimeline: function() {
- return this.timelines[this.currentTimelineId];
+ var currentTimeline = this.timelines[this.currentTimelineId];
+
+ if (!currentTimeline) {
+ var _this = this;
+ this.orderedEachTimeline(function(timeline) {
+ currentTimeline = _this.currentTimelineId = timeline.timelineId;
+ return false;
+ }, true);
+ }
+
+ return currentTimeline;
},
getTimeline: function(timelineId) {
View
186 locales.html
@@ -3,188 +3,6 @@
<head>
<title>Locales Data</title>
-<script>
-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;
- }
-};
-</script>
<style>
#localeTable {
border-collapse: collapse;
@@ -210,8 +28,6 @@
</style>
</head>
<body>
- <script>
- new LocaleTable();
- </script>
+<script src="lib/locales/page.js"></script>
</body>
</html>
View
304 options.html
@@ -11,297 +11,9 @@
<script src="lib/shortener_lib.js"></script>
<script src="lib/options/options.js"></script>
-<title>Silver Bird Options</title>
-
-<script>
-var LocaleTable = chrome.extension.getBackgroundPage().LocaleTable;
-var ImageService = chrome.extension.getBackgroundPage().ImageService;
-var IconCreator = chrome.extension.getBackgroundPage().IconCreator;
-var tweetManager = chrome.extension.getBackgroundPage().TweetManager.instance;
-
-chrome.i18n.getMessage = chrome.extension.getBackgroundPage().chrome.i18n.getMessage;
-
-var twitterBackend = tweetManager.twitterBackend;
-var options = new Options();
-var imgEl = null;
-
-function paintIcon(canvas, color) {
- if(!imgEl) {
- var img = $('<img>').attr('src', 'img/icon19.png');
- img.load(function() {
- imgEl = img[0];
- var imgData = IconCreator.paintIcon(imgEl, color);
- canvas.getContext("2d").putImageData(imgData, 0, 0);
- });
- } else {
- var imgData = IconCreator.paintIcon(imgEl, color);
- canvas.getContext("2d").putImageData(imgData, 0, 0);
- }
-}
-
-var hourlyLimit = 150;
-$(function() {
- $("input.i18n").each(function() {
- $(this).val(chrome.i18n.getMessage(this.id));
- });
-
- $(".i18n").not("input .htmlSafe").each(function() {
- $(this).text(chrome.i18n.getMessage(this.id));
- });
-
- $(".i18n.htmlSafe").each(function() {
- $(this).html(chrome.i18n.getMessage(this.id));
- });
-
- var resetDateObj = new Date();
- if(twitterBackend) {
- var hitsInfo = twitterBackend.remainingHitsInfo();
- $(".twitter_hits_left").text(hitsInfo[0]);
-
- resetDateObj.setTime(parseInt(hitsInfo[1], 10) * 1000);
- $(".twitter_hits_reset").text(resetDateObj.toLocaleDateString() + " " + resetDateObj.toLocaleTimeString());
-
- if(hitsInfo[2]) {
- hourlyLimit = parseInt(hitsInfo[2], 10);
- }
- }
- $(".__hourly_limit").text(hourlyLimit);
-
- $("select[name='default_locale']").append($("<option>").attr('value', 'auto').text(chrome.i18n.getMessage('automatic')));
- for(var localeCode in LocaleTable.instance.locales) {
- $("select[name='default_locale']").append($("<option>").attr('value', localeCode).text(localeCode));
- }
-
- for(var key in SHORTENERS_BACKEND) {
- var desc = SHORTENERS_BACKEND[key].desc;
- $("select[name='url_shortener']").append($("<option>").attr('value', key).text(desc));
- }
-
- for(var i = 0, len = ImageService.services.length; i < len; ++i) {
- var service = ImageService.services[i];
- if(service.hasUpload()) {
- $("select[name='image_upload_service']").append($("<option>").attr('value', service.domain).text(service.domain));
- }
- }
-
- var onShortenerChange = function() {
- $("#shortener_opts").hide();
- $("#yourls_opts").hide();
- $("#googl_opts").hide();
- var shortenerSelect = $("select[name='url_shortener']")[0];
- if(shortenerSelect.value == 'bitly' || shortenerSelect.value == 'jmp' || shortenerSelect.value == 'karmacracy') {
- $("#shortener_opts").show();
- } else if(shortenerSelect.value == 'yourls') {
- $("#yourls_opts").show();
- } else if(shortenerSelect.value == 'googl') {
- $("#googl_opts").show();
- }
- };
+<script src="lib/options/page.js"></script>
- var onShortenerAcctClick = function() {
- if($("input[name='shortener_acct']").is(':checked')) {
- $("input[name='shortener_login']").removeAttr('disabled');
- $("input[name='shortener_key']").removeAttr('disabled');
- } else {
- $("input[name='shortener_login']").val('').attr('disabled', 'disabled');
- $("input[name='shortener_key']").val('').attr('disabled', 'disabled');
- }
- };
- $("select[name='url_shortener']").change(onShortenerChange);
- $("input[name='shortener_acct']").click(onShortenerAcctClick);
-
- var onSigningUrlCheck = function() {
- var $check = $("input[name='same_signing_urls']");
- if($check.is(':checked')) {
- $("input[name='base_signing_url'], input[name='base_oauth_signing_url']").attr('disabled', 'disabled');
- $("input[name='base_signing_url']").val($("input[name='base_url']").val());
- $("input[name='base_oauth_signing_url']").val($("input[name='base_oauth_url']").val());
-
- $("input[name='base_url']").bind('keyup blur', function() {
- $("input[name='base_signing_url']").val($(this).val());
- });
- $("input[name='base_oauth_url']").bind('keyup blur', function() {
- $("input[name='base_oauth_signing_url']").val($(this).val());
- });
- } else {
- $("input[name='base_signing_url'], input[name='base_oauth_signing_url']").removeAttr('disabled');
-
- $("input[name='base_url']").unbind('keyup blur');
- $("input[name='base_oauth_url']").unbind('keyup blur');
- }
- };
- $("input[name='same_signing_urls']").click(onSigningUrlCheck);
-
- $('canvas.color_selector').ColorPicker({
- onChange: function (hsb, hex, rgb, rgbaStr) {
- var canvas = this.data('colorpicker').el;
- $(canvas).attr('strColor', rgbaStr);
- paintIcon(canvas, rgb);
- }
- });
- $('div.color_selector').ColorPicker({
- onChange: function (hsb, hex, rgb, rgbaStr) {
- var div = this.data('colorpicker').el;
- $(div).attr('strColor', rgbaStr);
- $(div).css('backgroundColor', rgbaStr);
- }
- });
- options.onload(function() {
- onShortenerChange();
- onShortenerAcctClick();
- onSigningUrlCheck();
- });
- options.onsaveChangedOption(function(optionName, oldValue, newValue) {
- var idx, templateId;
- if((idx = optionName.indexOf('_visible')) != -1) {
- templateId = optionName.substring(0, idx);
- if(newValue) {
- tweetManager.showTimelineTemplate(templateId, true);
- } else {
- tweetManager.hideTimelineTemplate(templateId);
- }
- } else if((idx = optionName.indexOf('_include_unified')) != -1) {
- templateId = optionName.substring(0, idx);
- tweetManager.toggleUnified(templateId, newValue);
- } else if(optionName == 'trending_topics_woeid') {
- tweetManager.cachedTrendingTopics = null;
- }
- });
- options.onsave(function() {
- if($("#noti_desktop").is(":checked")) {
- try {
- var notificationCenter = window.notifications || window.webkitNotifications;
- if(!notificationCenter) {
- throw 'out';
- }
- var authStatus = notificationCenter.checkPermission();
- if(authStatus == 1 || authStatus == 2) { // Not allowed or Denied
- notificationCenter.requestPermission(function() {
- var authStatus = notificationCenter.checkPermission();
- if(authStatus !== 0) { // Permission denied
- $("#noti_on_page").click();
- options.save();
- }
- });
- }
- } catch(boom) {
- $("#noti_on_page").click();
- options.save();
- }
- }
- });
- options.load();
-
- var createTTSelect = function(ttLocales) {
- $("select[name='trending_topics_woeid']").empty();
- $.each(ttLocales, function(i, locale){
- $("select[name='trending_topics_woeid']").append($("<option>").attr('value', locale.woeid).text(locale.name));
- });
- $("select[name='trending_topics_woeid']").val(OptionsBackend.get('trending_topics_woeid'));
- };
- var woeids = tweetManager.retrieveTrendingRegions(function(woeids) {
- createTTSelect(woeids);
- });
- createTTSelect(woeids);
-
- updatePredictedHitsCount();
- $('table.timelines input, table.timelines select').
- keyup(updatePredictedHitsCount).
- blur(updatePredictedHitsCount).
- click(updatePredictedHitsCount).
- change(updatePredictedHitsCount);
-
- $("input[name='microblogging_service'],label[for='service_twitter'],label[for='service_identica']").mousedown(function(e) {
- var el = $(e.target);
- if(el.is('label')) {
- el = $('#' + el.attr('for'));
- }
- if(!el.is(':checked')) {
- var proceed = confirm("This will reset any custom API URL configuration. Proceed?");
- if(proceed) {
- el.click();
- var sameSigningEl = $("input[name='same_signing_urls']");
- var baseUrlEl = $("input[name='base_url']");
- var baseOauthUrlEl = $("input[name='base_oauth_url']");
-
- if(el.val() == 'twitter') {
- baseUrlEl.val('http://api.twitter.com/1/');
- baseOauthUrlEl.val('https://twitter.com/oauth/');
- } else if(el.val() == 'identica') {
- baseUrlEl.val('http://identi.ca/api/');
- baseOauthUrlEl.val('https://identi.ca/api/oauth/');
- }
- baseUrlEl.blur();
- baseOauthUrlEl.blur();
- if(!sameSigningEl.is(':checked')) {
- sameSigningEl.attr('checked', true).click().attr('checked', true);
- }
- }
- }
- return true;
- });
-
- $("#nerds_link").click(function() {
- var $canvas = $("#nerds");
- $canvas.toggle();
- if($canvas.is(":visible")) {
- var points = chrome.extension.getBackgroundPage().TweetManager.instance.apiHitsStates;
- Math.generateTendencyGraph($canvas[0], points, resetDateObj.getTime());
- }
- });
-});
-
-function updatePredictedHitsCount() {
- var totalHits = 0;
- var unifiedVisible = $('input[name="unified_visible"]').is(':checked');
-
- TimelineTemplate.eachTimelineTemplate(function(template) {
- if(template.id == TimelineTemplate.UNIFIED) {
- return true;
- }
- var inputUnifiedEl = $('input[name="' + template.id + '_include_unified"]');
- if(!unifiedVisible) {
- inputUnifiedEl.attr('disabled', 'disabled');
- } else {
- inputUnifiedEl.removeAttr('disabled');
- }
- if(template.id == TimelineTemplate.SEARCH) {
- return true;
- }
- var inputVisibleEl = $('input[name="' + template.id + '_visible"]');
- if(!inputVisibleEl.is(':checked') && !(unifiedVisible && inputUnifiedEl.is(':checked'))) {
- return true;
- }
-
- var inputRefreshEl = $('input[name="' + template.id + '_refresh_interval"]');
- var intVal = parseInt(inputRefreshEl.val(), 10);
- var timelineHits = (60 * 60) / intVal;
- var timelineCount = 1;
- if(template.id == TimelineTemplate.DMS) {
- timelineCount = 2;
- } else {
- var userData = template.getUserData();
- if(userData && userData.length > 0) {
- timelineCount = userData.length;
- }
- }
-
- totalHits += timelineHits * timelineCount;
- return true;
- });
- totalHits += (60 * 60) / parseInt($('input[name="blockedusers_refresh_interval"]').val(), 10);
- totalHits = parseInt(totalHits, 10);
- $('#predicted_hits_count').text(totalHits);
- if(totalHits >= hourlyLimit) {
- $('#predicted_hits_count').css('backgroundColor', 'red');
- } else if(totalHits >= hourlyLimit * 0.85) {
- $('#predicted_hits_count').css('backgroundColor', 'yellow');
- } else {
- $('#predicted_hits_count').css('backgroundColor', 'white');
- }
- return totalHits;
-}
-</script>
+<title>Silver Bird Options</title>
</head>
<body>
@@ -316,8 +28,8 @@ <h1 class="i18n" id="options_title">Silver Bird Options</h1>
(This will reset your unread tweets count.)
</span>
<br>
- <input type="button" onclick="options.confirmRestart();" class="i18n" id="Yes" value="Yes">
- <input type="button" onclick="options.denyRestart();" class="i18n" id="No" value="No">
+ <input type="button" class="i18n" id="Yes" value="Yes">
+ <input type="button" class="i18n" id="No" value="No">
</div>
</div>
<div id="main_area">
@@ -411,7 +123,7 @@ <h1 class="i18n" id="options_title">Silver Bird Options</h1>
</td>
</tr>
</table><br>
- <input type="button" value="Reset Popup Size" class="i18n" id="btn_reset_popup_size" onclick="Persistence.popupSize().remove();">
+ <input type="button" value="Reset Popup Size" class="i18n" id="btn_reset_popup_size">
</fieldset>
<fieldset>
@@ -622,9 +334,9 @@ <h1 class="i18n" id="options_title">Silver Bird Options</h1>
<br>
<div id="buttons_area">
- <input type="button" class="i18n" value="Save" id="btn_save" onclick="options.save();">
- <input type="button" class="i18n" value="Reset" id="btn_reset" onclick="options.load();">
- <input type="button" class="i18n" value="Reset to default" id="btn_default" onclick="options.loadDefaults();">
+ <input type="button" class="i18n" value="Save" id="btn_save">
+ <input type="button" class="i18n" value="Reset" id="btn_reset">
+ <input type="button" class="i18n" value="Reset to default" id="btn_default">
</div>
</div>
View
39 tweets_notifier.html
@@ -15,44 +15,11 @@
<base target="_blank">
- <script>
- 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;
-
- $(function() {
- 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);
-
- });
- </script>
</head>
<body>
<div id="progress"></div>
+
+
+<script src="lib/notifier/init.js"></script>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.