From 75d43424f8833b7a321201f45baf9fd0449c79eb Mon Sep 17 00:00:00 2001 From: Zan Gerden Date: Sat, 14 Mar 2015 16:49:45 +0100 Subject: [PATCH 1/9] Formatted Manifest file --- manifest.json | 74 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/manifest.json b/manifest.json index c078774..4d3c330 100644 --- a/manifest.json +++ b/manifest.json @@ -1,26 +1,50 @@ { - "content_scripts": [ { - "js": [ "js/jquery.min.js", "js/plugins.js", "js/Chart.min.js", "better-envato.js" ], - "css": ["css/envato-styles.css"], - "matches": [ "*://*.themeforest.net/*", "*://*.codecanyon.net/*", "*://*.videohive.net/*", "*://*.audiojungle.net/*", "*://*.graphicriver.net/*", "*://*.photodune.net/*", "*://*.3docean.net/*", "*://*.activeden.net/*", "*://*.envato.com/*" ] - } ], -"browser_action": { - "name": "Better Envato" - }, -"background": { - "page": "background.html" - }, - "description": "Make Envato better by adding some cool features", - "icons": { - "128": "img/128.png", - "16": "img/16.png", - "48": "img/48.png" - }, - "manifest_version": 2, - "name": "Better Envato", - "short_name": "Better Envato", - "options_page": "options.html", - "permissions": [ "webRequest", "notifications", "background" ], - "update_url": "http://clients2.google.com/service/update2/crx", - "version": "1.2.5" -} + "content_scripts":[ + { + "js":[ + "js/jquery.min.js", + "js/plugins.js", + "js/Chart.min.js", + "better-envato.js" + ], + "css":[ + "css/envato-styles.css" + ], + "matches":[ + "*://*.themeforest.net/*", + "*://*.codecanyon.net/*", + "*://*.videohive.net/*", + "*://*.audiojungle.net/*", + "*://*.graphicriver.net/*", + "*://*.photodune.net/*", + "*://*.3docean.net/*", + "*://*.activeden.net/*", + "*://*.envato.com/*" + ] + } + ], + "browser_action":{ + "name":"Better Envato" + }, + "background":{ + "page":"background.html" + }, + "description":"Make Envato better by adding some cool features", + "icons":{ + "128":"img/128.png", + "16":"img/16.png", + "48":"img/48.png" + }, + "manifest_version":2, + "name":"Better Envato", + "short_name":"Better Envato", + "options_page":"options.html", + "permissions":[ + "storage", + "webRequest", + "notifications", + "background" + ], + "update_url":"http://clients2.google.com/service/update2/crx", + "version":"1.2.5" +} \ No newline at end of file From 675fa4f0b9fa7eb92fee3f7eae06bd55257cead0 Mon Sep 17 00:00:00 2001 From: Zan Gerden Date: Sat, 14 Mar 2015 18:26:38 +0100 Subject: [PATCH 2/9] Transition to chrome.storage API --- background.js | 295 ++++++++++++++++++++++++++++------------------- better-envato.js | 36 +++--- options.js | 135 ++++++++++++++-------- 3 files changed, 280 insertions(+), 186 deletions(-) diff --git a/background.js b/background.js index 829799a..ea830ad 100644 --- a/background.js +++ b/background.js @@ -1,37 +1,47 @@ // Show the config file on installation chrome.runtime.onInstalled.addListener(function(object) { - if (localStorage.firsttime != 'false' || localStorage.firsttime == 'undefined' || !localStorage.firsttime ) { - var optionsurl = chrome.extension.getURL("options.html"); - chrome.tabs.create({ - url: optionsurl - }, function(tab) {}); - - localStorage.firsttime = false; -} + get_option('firsttime', function(value){ + if(value != 'false' || !value) { + var optionsurl = chrome.extension.getURL("options.html"); + chrome.tabs.create({ + url: optionsurl + }, function(tab) {}); + + save_option('firsttime', 'false'); + } + }); -var currentversion = chrome.app.getDetails().version; + var currentversion = chrome.app.getDetails().version; - if (!localStorage.version || localStorage.version != currentversion) { - chrome.browserAction.setBadgeText({text:"NEW"}); - localStorage.version = currentversion -} + get_option('version', function(value){ + if(!value || value != currentversion) { + chrome.browserAction.setBadgeText({text:"NEW"}); + + save_option('version', currentversion); + } + }); //chrome.browserAction.setBadgeBackgroundColor({color:[255, 64, 64, 230]}); - - -}); + // Check if localStorage is in usage + if(!isEmpty(localStorage)) { + // localStorage is in use, so move all options from there to chrome.storage + //delete localStorage.apikey; + //alert(JSON.stringify(localStorage)); @todo Continue + } + +}); // Get Local Storage value in Content Script /*chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { - if (request.method == "getLocalStorage") - sendResponse({data: localStorage[request.key]}); - else - sendResponse({}); // snub them. -}); -*/ + if (request.method == "getLocalStorage") + sendResponse({data: localStorage[request.key]}); + else + sendResponse({}); // snub them. + }); + */ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { switch (message.method) { @@ -51,19 +61,26 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { }); } break; - // ... + // ... } }); -// Open Opeions Page if clicked on icons +// Open Options Page if clicked on icons chrome.browserAction.onClicked.addListener(function(tab) { //Fired when User Clicks ICON chrome.tabs.create({ url: "options.html" }); - chrome.browserAction.setBadgeText({text:""}); + chrome.browserAction.setBadgeText({text:""}); }); +function isEmpty(obj) { + for(var prop in obj) { + if(obj.hasOwnProperty(prop)) + return false; + } + return true; +} function updatedSettings() { //chrome.runtime.reload(); @@ -74,22 +91,22 @@ function updatedSettings() { // Test for notification support. if (window.Notification) { - if (localStorage.sales_notification != 'false') { - // While activated, show notifications at the display frequency. - sales_notification(); - setInterval(function() { + get_option('sales_notification', function(value){ + if(value != 'false') { sales_notification(); - }, 60000); - } - - if (localStorage.comment_notification != 'false') { - // While activated, show notifications at the display frequency. - comment_notification(); - setInterval(function() { + setInterval(function() { + sales_notification(); + }, 60000); + } + }); + get_option('comment_notification', function(value){ + if(value != 'false') { comment_notification(); - }, 60000); - } - + setInterval(function() { + comment_notification(); + }, 60000); + } + }); } @@ -97,56 +114,59 @@ if (window.Notification) { // Sales Notifications function sales_notification() { + get_option('username', function(value){ + var username = value; + if(typeof username == 'undefined') { + return false; + } + get_option('apikey', function(value){ + var apikey = value; + if(typeof apikey == 'undefined') { + return false; + } + get_option('earnings', function(value){ + var earnings = value; - var username = localStorage.username; - var apikey = localStorage.apikey; - var earnings = localStorage.earnings; + // Use Envato API to check sales + $.get('http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json', function(data) { - if (typeof username == 'undefined' || typeof apikey == 'undefined') { - return false; - } + //get current sales + var new_earnings = data.account.available_earnings; + var first_name = data.account.firstname; - // Use Envato API to check sales - $.get('http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json', function(data) { + if (earnings < new_earnings) { - //get current sales - var new_earnings = data.account.available_earnings; - var first_name = data.account.firstname; + $.get('http://marketplace.envato.com/api/v3/' + username + '/' + apikey + '/recent-sales.json', function(salesdata) { - //earnings < new_earnings - // testing: new_earnings > 1 + //get current sales + var sold_item = salesdata["recent-sales"][0].item; + var item_price = salesdata["recent-sales"][0].amount; + show_notification(new_earnings, item_price, first_name, sold_item, 'item'); + play_sound(); - if (earnings < new_earnings) { + }); + } - $.get('http://marketplace.envato.com/api/v3/' + username + '/' + apikey + '/recent-sales.json', function(salesdata) { - - //get current sales - var sold_item = salesdata["recent-sales"][0].item; - var item_price = salesdata["recent-sales"][0].amount; - show_notification(new_earnings, item_price, first_name, sold_item, 'item'); - play_sound(); + save_option('earnings', new_earnings); + }); }); - } - - - localStorage.earnings = new_earnings; - + }); }); - } // Play a sound on new sale function play_sound() { - if (localStorage.play_sound != 'false') { - if ($('#cha-ching').length) $('#cha-ching').remove(); - $('').appendTo('body'); - } - return false; + get_option('play_sound', function(value){ + if(value != 'false') { + if ($('#cha-ching').length) $('#cha-ching').remove(); + $('').appendTo('body'); + } + return false; + }); } function show_notification(new_earnings, item_price, first_name, sold_item, item) { - var praiseArray = ['Woohoo', 'Bravo', 'Wow', 'Ahoy', 'Yay', 'Yikes', 'Hooray', 'Whoa', 'Woot', 'Oh joy', first_name]; var randomPraise = praiseArray[Math.floor(Math.random() * praiseArray.length)]; @@ -158,69 +178,102 @@ function show_notification(new_earnings, item_price, first_name, sold_item, item notification.onclick = function() { window.open("http://themeforest.net/statement"); } - if (localStorage.auto_hide_sales_notification != 'false') { - setTimeout(function() { - notification.close() - }, 15000); - } + get_option('auto_hide_sales_notification', function(value){ + if(value != 'false') { + setTimeout(function() { + notification.close() + }, 15000); + } + }); } function comment_notification() { + get_option('username', function(value){ + var username = value; + get_option('new_comment_id', function(value){ + var last_comment_id = value; + + $.get('http://themeforest.net/feeds/user_item_comments/' + username + '.atom', function(data) { + //console.log(data); + var comment_feed = $.xml2json(data); + //console.log(comment_feed); + var comment_id = comment_feed.entry[0].id; + var comment_id_hash = comment_id.substr(comment_id.lastIndexOf('/') + 1); + var comment_author = comment_feed.entry[0].author.name; + var new_comment = /* $(comment_feed.entry[0].content.text).text(); */ comment_feed.entry[0].content.text.replace(/(<([^>]+)>)/ig, ""); + new_comment = new_comment.replace(/\s{2,}/g, ' '); + var new_comment_item = $.trim(comment_feed.entry[0].title).substring(0, 20).split(" ").slice(0, -1).join(" ") + "..."; + var new_comment_url = comment_feed.entry[0].link.href; + //console.log(new_comment); + + if (last_comment_id != comment_id && comment_author != username) { + show_comments(new_comment, new_comment_item, new_comment_url, comment_id_hash); + save_option('new_comment_id', comment_id); + play_notification(); + } - var username = localStorage.username; - var last_comment_id = localStorage.new_comment_id; - - $.get('http://themeforest.net/feeds/user_item_comments/' + username + '.atom', function(data) { - //console.log(data); - var comment_feed = $.xml2json(data); - //console.log(comment_feed); - var comment_id = comment_feed.entry[0].id; - var comment_id_hash = comment_id.substr(comment_id.lastIndexOf('/') + 1); - var comment_author = comment_feed.entry[0].author.name; - var new_comment = /* $(comment_feed.entry[0].content.text).text(); */ comment_feed.entry[0].content.text.replace(/(<([^>]+)>)/ig, ""); - new_comment = new_comment.replace(/\s{2,}/g, ' '); - var new_comment_item = $.trim(comment_feed.entry[0].title).substring(0, 20).split(" ").slice(0, -1).join(" ") + "..."; - var new_comment_url = comment_feed.entry[0].link.href; - //console.log(new_comment); - - if (last_comment_id != comment_id && comment_author != username) { - show_comments(new_comment, new_comment_item, new_comment_url, comment_id_hash); - localStorage.new_comment_id = comment_id; - play_notification(); - } + }); - }); + // Play a sound on new comment + function play_notification() { + get_option('comment_sound', function(value){ + if(value != 'false') { + if ($('#comment_sound').length) $('#comment_sound').remove(); + $('').appendTo('body'); + } + return false; + }); + } - // Play a sound on new comment - function play_notification() { - if (localStorage.comment_sound != 'false') { - if ($('#comment_sound').length) $('#comment_sound').remove(); - $('').appendTo('body'); - } - return false; - } + function show_comments(new_comment, new_comment_item, new_comment_url, comment_id_hash) { + var c_notification = new Notification('New Comment for ' + new_comment_item, { + icon: 'img/48.png', + body: new_comment + }); + c_notification.onclick = function() { + window.open(new_comment_url + '/' + comment_id_hash); + } - function show_comments(new_comment, new_comment_item, new_comment_url, comment_id_hash) { + get_option('auto_hide_comment_notification', function(value){ + if(value != 'false') { + setTimeout(function() { + c_notification.close() + }, 15000); + } + }); + + } - var c_notification = new Notification('New Comment for ' + new_comment_item, { - icon: 'img/48.png', - body: new_comment }); + }); + } - c_notification.onclick = function() { - window.open(new_comment_url + '/' + comment_id_hash); +/** + * Saves option to Chrome.storage + */ +function save_option(name, value){ + var object = {}; + object[name] = value; + + chrome.storage.sync.set(object, function() { + if(chrome.extension.lastError) { + console.log('An error occured: ' + chrome.extension.lastError.message); + return false; + } else { + return true; } - - if (localStorage.auto_hide_comment_notification != 'false') { - setTimeout(function() { - c_notification.close() - }, 15000); - } - - } + }); +} +/** + * Gets option from Chrome.storage + */ +function get_option(name, callback) { + chrome.storage.sync.get(name, function(response) { + callback(response[name], name); + }) } \ No newline at end of file diff --git a/better-envato.js b/better-envato.js index b21927f..4074d62 100644 --- a/better-envato.js +++ b/better-envato.js @@ -5,24 +5,20 @@ Created by: Surjith S M © 2015-2020 */ var username, apikey, openexchange, currency, localise_earnings, localise_earnings_table, localise_earnings_page, hide_statement, verify_purchase, create_hrefs; -chrome.runtime.sendMessage({ - method: "getLocalStorage", - keys: ["username", "apikey", "openexchange", "currency", "localise_earnings", 'localise_earnings_table', 'localise_earnings_page', 'hide_statement', 'verify_purchase', 'create_hrefs', 'hide_earnings' ] - }, - function(response) { - username = response.data.username; - apikey = response.data.apikey; - openexchange = response.data.openexchange; - currency = response.data.currency; - localise_earnings = response.data.localise_earnings; - localise_earnings_table = response.data.localise_earnings_table; - localise_earnings_page = response.data.localise_earnings_page; - hide_statement = response.data.hide_statement; - verify_purchase = response.data.verify_purchase; - create_hrefs = response.data.create_hrefs; - hide_earnings = response.data.hide_earnings; - } -); +// Load options from Chrome's storage +chrome.storage.sync.get(null, function(response){ + username = response.username; + apikey = response.apikey; + openexchange = response.openexchange; + currency = response.currency; + localise_earnings = response.localise_earnings; + localise_earnings_table = response.localise_earnings_table; + localise_earnings_page = response.localise_earnings_page; + hide_statement = response.hide_statement; + verify_purchase = response.verify_purchase; + create_hrefs = response.create_hrefs; + hide_earnings = response.hide_earnings; +}); $(document).ready(function() { if (localise_earnings != 'false') { @@ -77,8 +73,8 @@ function dollartToInr() { $.getJSON(conversionurl, function(data) { convertrate = data.rates[currency]; /* * 0.975 Midmarket rate*/ - - console.log(data); + + //console.log(data); $.getJSON(posturl, function(data) { earningsdollar = data.account.available_earnings; /*- 3 payoneer commision $3*/ diff --git a/options.js b/options.js index 824ffd4..3247849 100644 --- a/options.js +++ b/options.js @@ -5,35 +5,52 @@ function init_options() { // console.log("function: init_options"); + var current_object = []; + //load currently stored options configuration var $inputs = $('#options-area :input'); $inputs.each(function() { - if (typeof localStorage[this.name] != 'undefined') { - $(this).val(localStorage[this.name]); - } + current_object[$(this).attr('name')] = $(this); + + get_option($(this).attr('name'), function(value, name) { + current_object[name].val(value); + }); }); var $checkboxes = $('#options-area :input[type=checkbox]'); $checkboxes.each(function() { - if (localStorage[this.name] == 'false') { - //alert(localStorage[this.name]) - $(this).attr('checked', false); - } else if (localStorage[this.name] == 'true') { - $(this).attr('checked', true); - } + current_object[$(this).attr('name')] = $(this); + + get_option($(this).attr('name'), function(value, name){ + if(value == 'false') { + current_object[name].attr('checked', false); + } else if (value == 'true') { + current_object[name].attr('checked', true); + } + }); }); + get_option('currency', function(value, name){ + $('select[name='+name+']').select(value); + }); } function save_options() { // console.log("function: save_options"); + chrome.storage.sync.clear(); $("input[type=text],select,textarea").each(function() { - localStorage[$(this).attr("name")] = $(this).val(); + var name = $(this).attr('name'); + var value = $(this).val(); + + save_option(name, value); }); $("input[type=checkbox]").each(function() { - localStorage[$(this).attr("name")] = $(this).prop("checked"); + var name = $(this).attr('name'); + var value = $(this).prop('checked').toString(); + + save_option(name, value); }); $(this).text('Saving...').removeClass("btn-success"); @@ -41,20 +58,43 @@ function save_options() { setTimeout(function() { $('#save-options-button').text('Options Saved'); }, 700); - - - // Ask for a good review - if( ! localStorage.reviewed ) { - $('#rate-it').html('
Enjoying Better Envato? Head over to the Chrome Web Store and give it 5 stars. We will love you forever.
'); - } + get_option('reviewed', function(value){ + if(value != 'true') { + $('#rate-it').html('
Enjoying Better Envato? Head over to the Chrome Web Store and give it 5 stars. We will love you forever.
'); + } + }); get_sales_data(); get_comment_data(); chrome.extension.getBackgroundPage().updatedSettings(); +} +/** + * Saves option to Chrome.storage + */ +function save_option(name, value){ + var object = {}; + object[name] = value; + + chrome.storage.sync.set(object, function() { + if(chrome.extension.lastError) { + console.log('An error occured: ' + chrome.extension.lastError.message); + return false; + } else { + return true; + } + }); } +/** + * Gets option from Chrome.storage + */ +function get_option(name, callback) { + chrome.storage.sync.get(name, function(response) { + callback(response[name], name); + }) +} /** * Reset the save button @@ -69,45 +109,50 @@ $('input, select').on('keyup click', function () { */ $('body').on('click', '.fivestars', function () { - localStorage.reviewed = true; - $('#rate-it').html('
You\'re awesome ♥'); + save_option('reviewed', 'true'); + $('#rate-it').html('
You\'re awesome ♥'); }); - - - // Sales Notifications function get_sales_data() { - var username = localStorage.username; - var apikey = localStorage.apikey; - var earnings = localStorage.earnings; - - if (typeof username == 'undefined' || typeof apikey == 'undefined') { - return false; - } - - // Use Envato API to check sales - $.get('http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json', function(data) { - - //get current sales - var new_earnings = data.account.available_earnings; - localStorage.earnings = new_earnings; - + get_option('username', function(value) { + if(typeof value == 'undefined') { + return false; + } + var username = value; + get_option('apikey', function(value) { + if(typeof value == 'undefined') { + return false; + } + var apikey = value; + get_option('earnings', function(value) { + var earnings = value; + + // Use Envato API to check sales + $.get('http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json', function(data) { + + //get current sales + var new_earnings = data.account.available_earnings; + save_option('earnings', new_earnings); + + }); + }); + }); }); - } - function get_comment_data() { - var username = localStorage.username; + get_option('username', function(value) { + var username = value; - $.get('http://themeforest.net/feeds/user_item_comments/' + username + '.atom', function(data) { - var comment_feed = $.xml2json(data); - //console.log(comment_feed); - var comment_id = comment_feed.entry[0].id; - localStorage.new_comment_id = comment_id; + $.get('http://themeforest.net/feeds/user_item_comments/' + username + '.atom', function(data) { + var comment_feed = $.xml2json(data); + //console.log(comment_feed); + var comment_id = comment_feed.entry[0].id; + save_option('new_comment_id', comment_id); + }); }); } From 8130f8b0ea29a7fc1ea4232041a94885eaea85ac Mon Sep 17 00:00:00 2001 From: Zan Gerden Date: Sat, 14 Mar 2015 19:06:03 +0100 Subject: [PATCH 3/9] Migration from localStorage to chrome.storage --- background.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index ea830ad..4695d4d 100644 --- a/background.js +++ b/background.js @@ -28,7 +28,15 @@ chrome.runtime.onInstalled.addListener(function(object) { if(!isEmpty(localStorage)) { // localStorage is in use, so move all options from there to chrome.storage //delete localStorage.apikey; - //alert(JSON.stringify(localStorage)); @todo Continue + + for(var i = 0; i < localStorage.length; i++) { + var name = localStorage.key(i); + var value = localStorage.getItem(localStorage.key(i)); + + save_option(name, value); + + delete localStorage[name]; + } } }); @@ -262,6 +270,7 @@ function save_option(name, value){ chrome.storage.sync.set(object, function() { if(chrome.extension.lastError) { console.log('An error occured: ' + chrome.extension.lastError.message); + alert('An error occured: ' + chrome.extension.lastError.message); return false; } else { return true; From 3d05cd9dc2fc0c97c5c0b8960885a1a1ac60cc80 Mon Sep 17 00:00:00 2001 From: Zan Gerden Date: Sat, 14 Mar 2015 19:12:14 +0100 Subject: [PATCH 4/9] Fixed code layout --- background.html | 8 +- background.js | 2 +- better-envato.js | 56 ++-- css/options.css | 130 +++++----- options.html | 646 +++++++++++++++++++++++------------------------ options.js | 12 +- 6 files changed, 427 insertions(+), 427 deletions(-) diff --git a/background.html b/background.html index 931d41b..26e80ad 100644 --- a/background.html +++ b/background.html @@ -1,11 +1,11 @@ - Envato sales desktop notification - - + Envato sales desktop notification + + - + diff --git a/background.js b/background.js index 4695d4d..7f85c04 100644 --- a/background.js +++ b/background.js @@ -258,7 +258,7 @@ function comment_notification() { }); }); - } +} /** * Saves option to Chrome.storage diff --git a/better-envato.js b/better-envato.js index 4074d62..6a82b4d 100644 --- a/better-envato.js +++ b/better-envato.js @@ -1,8 +1,8 @@ /* -Name: Better Envato -Keywords: make Envato Better -Created by: Surjith S M © 2015-2020 -*/ + Name: Better Envato + Keywords: make Envato Better + Created by: Surjith S M © 2015-2020 + */ var username, apikey, openexchange, currency, localise_earnings, localise_earnings_table, localise_earnings_page, hide_statement, verify_purchase, create_hrefs; // Load options from Chrome's storage @@ -74,7 +74,7 @@ function dollartToInr() { $.getJSON(conversionurl, function(data) { convertrate = data.rates[currency]; /* * 0.975 Midmarket rate*/ - //console.log(data); + //console.log(data); $.getJSON(posturl, function(data) { earningsdollar = data.account.available_earnings; /*- 3 payoneer commision $3*/ @@ -263,28 +263,28 @@ $(document).ready(function() { convertPrice($('.earnings-widget__amount:eq(2)').text().substr(1), function(data){ $('.earnings-widget__amount:eq(2)').text(data); }); - // Reduce font size to avoid design breakage in local currency - $('.earnings-widget__amount').css('font-size','30px'); + // Reduce font size to avoid design breakage in local currency + $('.earnings-widget__amount').css('font-size','30px'); // Convert prices in table - if(pathname.indexOf('/earnings/sales') > -1) { - $('.table-general tbody, tfoot').find('tr').each(function(index){ - current_object[index] = $(this); - convertPrice($(this).find('td').eq(2).text().substr(1), function(data){ - current_object[index].find('td').eq(2).text(data); - }); - }); - } else if(pathname.indexOf('/earnings/referrals') > -1) { - $('.table-general tbody, tfoot').find('tr').each(function(index){ - current_object[index] = $(this); - convertPrice($(this).find('td').eq(4).text().substr(1), function(data){ - current_object[index].find('td').eq(4).text(data); - }); - convertPrice($(this).find('td').eq(5).text().substr(1), function(data){ - current_object[index].find('td').eq(5).text(data); - }); - }); - } + if(pathname.indexOf('/earnings/sales') > -1) { + $('.table-general tbody, tfoot').find('tr').each(function(index){ + current_object[index] = $(this); + convertPrice($(this).find('td').eq(2).text().substr(1), function(data){ + current_object[index].find('td').eq(2).text(data); + }); + }); + } else if(pathname.indexOf('/earnings/referrals') > -1) { + $('.table-general tbody, tfoot').find('tr').each(function(index){ + current_object[index] = $(this); + convertPrice($(this).find('td').eq(4).text().substr(1), function(data){ + current_object[index].find('td').eq(4).text(data); + }); + convertPrice($(this).find('td').eq(5).text().substr(1), function(data){ + current_object[index].find('td').eq(5).text(data); + }); + }); + } } } @@ -386,9 +386,9 @@ $(document).ready(function() { // Hide Author Earnings // Author is browsing in public and do not want to reveal his balance -if (hide_earnings == 'true') { - $('.header-logo-account__balance').hide(); -} + if (hide_earnings == 'true') { + $('.header-logo-account__balance').hide(); + } }); /*End Document Ready*/ diff --git a/css/options.css b/css/options.css index f4cae03..7b0f51b 100644 --- a/css/options.css +++ b/css/options.css @@ -1,124 +1,124 @@ /*Options Page*/ body { - background:#eee; - font-family:Arial, Helvetica, Sans-serif; - font-size:14px; - color:#3D3D3D; + background:#eee; + font-family:Arial, Helvetica, Sans-serif; + font-size:14px; + color:#3D3D3D; } .settings { - background:#FFF; - margin:50px auto; - padding:30px; - max-width:800px; + background:#FFF; + margin:50px auto; + padding:30px; + max-width:800px; } h1 { - text-align:center; - color:#313131; + text-align:center; + color:#313131; } p { - color:#707070; + color:#707070; } a { - color:#53A2EC; - text-decoration:none; + color:#53A2EC; + text-decoration:none; } a:hover { - color:#2473BD; + color:#2473BD; } hr { - -moz-box-sizing: content-box; - box-sizing: content-box; - height: 0; - margin-top: 20px; - margin-bottom: 20px; - border: 0; - border-top: 1px solid #eee; + -moz-box-sizing: content-box; + box-sizing: content-box; + height: 0; + margin-top: 20px; + margin-bottom: 20px; + border: 0; + border-top: 1px solid #eee; } #options-area { - margin-top:50px; + margin-top:50px; } .text-center { - text-align:center; -} + text-align:center; +} .control-group { - margin-bottom:20px; + margin-bottom:20px; } .control-label { - float:left; - margin:7px; + float:left; + margin:7px; } .help-block { - font-size:12px; + font-size:12px; } .controls { - margin-left:250px; + margin-left:250px; } .controls input[type=text], .controls select { - padding:5px 10px; - border:solid 1px #CCC; - width:300px; + padding:5px 10px; + border:solid 1px #CCC; + width:300px; } select[disabled], input[disabled] { -cursor: not-allowed; -background-color: #eee; -opacity: 1; + cursor: not-allowed; + background-color: #eee; + opacity: 1; } .btn { -display: inline-block; -padding: 6px 12px; -margin-bottom: 0; -font-size: 14px; -font-weight: 400; -line-height: 1.42857143; -text-align: center; -white-space: nowrap; -vertical-align: middle; -cursor: pointer; --webkit-user-select: none; --moz-user-select: none; --ms-user-select: none; -user-select: none; -background-image: none; -border: 1px solid transparent; -border-radius: 4px; -color: #939393; --webkit-transition:all .1s linear; -transition:all .1s linear; -outline:none; + display: inline-block; + padding: 6px 12px; + margin-bottom: 0; + font-size: 14px; + font-weight: 400; + line-height: 1.42857143; + text-align: center; + white-space: nowrap; + vertical-align: middle; + cursor: pointer; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + background-image: none; + border: 1px solid transparent; + border-radius: 4px; + color: #939393; + -webkit-transition:all .1s linear; + transition:all .1s linear; + outline:none; } .btn-success { -background-color: #2cc76a; -background-image: none; -border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); -color:#FFF; + background-color: #2cc76a; + background-image: none; + border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); + color:#FFF; } .highlight { -background: #f5e9a3; -padding: 1em 1.5em; --webkit-transition: background .1s linear; -transition: background .1s linear; + background: #f5e9a3; + padding: 1em 1.5em; + -webkit-transition: background .1s linear; + transition: background .1s linear; } .highlight.love { -background: #f5a3cc; + background: #f5a3cc; } diff --git a/options.html b/options.html index 0743d83..80c5ffc 100644 --- a/options.html +++ b/options.html @@ -1,340 +1,340 @@ -Better Envato Options - + Better Envato Options +
-

Better Envato Options

- - -
- -
-
-
-
- -
- -
-
-
- -
- -
-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
-
- -
-
- -
-
- -
-
- -
-

Please Fill below details to localize earnings

-
-
-
- -
- -

Signup free to get API Key from Open Exchange rate

-
-
-
- -
- -
-
-
-
- -
-
- -
-
-
-
-
- -
-
- -
-
-
-
-
- -
-
- +

Better Envato Options

+ + +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+

Please Fill below details to localize earnings

+
+
+
+ +
+ +

Signup free to get API Key from Open Exchange rate

+
+
+
+ +
+ +
+
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
-
-
-
- -
-
- -
-
+
+
-
-
-
-
-
-

Made with ♥ by Surjith S M (Envato Portfolio).
- Fork on Github | Found an issue? | Credits : Envato API | Contributors: Zan Gerden

+ Fork on Github | Found an issue? | Credits : Envato API | Contributors: Zan Gerden

- - + + \ No newline at end of file diff --git a/options.js b/options.js index 3247849..3732d84 100644 --- a/options.js +++ b/options.js @@ -53,10 +53,10 @@ function save_options() { save_option(name, value); }); - $(this).text('Saving...').removeClass("btn-success"); - - setTimeout(function() { - $('#save-options-button').text('Options Saved'); + $(this).text('Saving...').removeClass("btn-success"); + + setTimeout(function() { + $('#save-options-button').text('Options Saved'); }, 700); get_option('reviewed', function(value){ @@ -100,14 +100,14 @@ function get_option(name, callback) { * Reset the save button */ $('input, select').on('keyup click', function () { - $('#save-options-button').text('Save Options').addClass("btn-success"); + $('#save-options-button').text('Save Options').addClass("btn-success"); }); /** * Store that the user has already been to the Web Store (:. we <3 them) */ - + $('body').on('click', '.fivestars', function () { save_option('reviewed', 'true'); $('#rate-it').html('
You\'re awesome ♥'); From cd4bd1263a75e59dc078d19b533362a2d2c5b92a Mon Sep 17 00:00:00 2001 From: Zan Gerden Date: Sat, 14 Mar 2015 19:16:23 +0100 Subject: [PATCH 5/9] Fixed special character in my name --- options.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options.html b/options.html index 80c5ffc..37feb28 100644 --- a/options.html +++ b/options.html @@ -331,7 +331,7 @@

Better Envato Options

Made with ♥ by Surjith S M (Envato Portfolio).
- Fork on Github | Found an issue? | Credits : Envato API | Contributors: Zan Gerden

+ Fork on Github | Found an issue? | Credits : Envato API | Contributors: Žan Gerden

From d7cd4d738255e6ce55e5c7dfcd07be6197993663 Mon Sep 17 00:00:00 2001 From: Zan Gerden Date: Sat, 14 Mar 2015 22:05:15 +0100 Subject: [PATCH 6/9] Cache for currency rate --- better-envato.js | 631 ++++++++++++++++++++++++++--------------------- options.html | 6 + options.js | 13 + 3 files changed, 367 insertions(+), 283 deletions(-) diff --git a/better-envato.js b/better-envato.js index 6a82b4d..ce19f76 100644 --- a/better-envato.js +++ b/better-envato.js @@ -3,7 +3,7 @@ Keywords: make Envato Better Created by: Surjith S M © 2015-2020 */ -var username, apikey, openexchange, currency, localise_earnings, localise_earnings_table, localise_earnings_page, hide_statement, verify_purchase, create_hrefs; +var username, apikey, openexchange, currency, localise_earnings, localise_earnings_table, localise_earnings_page, hide_statement, verify_purchase, create_hrefs, cache_currency_rate, currency_rate; // Load options from Chrome's storage chrome.storage.sync.get(null, function(response){ @@ -18,101 +18,166 @@ chrome.storage.sync.get(null, function(response){ verify_purchase = response.verify_purchase; create_hrefs = response.create_hrefs; hide_earnings = response.hide_earnings; -}); + cache_currency_rate = response.cache_currency_rate; + currency_rate = response.currency_rate; -$(document).ready(function() { - if (localise_earnings != 'false') { - if (username == 'undefined' || apikey == 'undefined' || openexchange == 'undefined') { - return false; - } else { - dollartToInr(); + $(document).ready(function() { + if (localise_earnings != 'false') { + if (username == 'undefined' || apikey == 'undefined' || openexchange == 'undefined') { + return false; + } else { + dollartToInr(); + } } - } - -}); + if(cache_currency_rate != 'false') { + var exchange_rate = currency_rate.split('||') || 1; + + var last_cached_time = exchange_rate[0]; + var last_exchange_rate = exchange_rate[1]; + var current_timestamp = Math.floor(Date.now() / 1000); + var day_ago_time = current_timestamp - 86400; + + if(last_cached_time < day_ago_time) { + // Fetch latest currency rate + var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange; + $.getJSON(conversionurl, function(data) { + save_option('currency_rate', current_timestamp+'||'+data.rates[currency]); + }); + } + } + }); //function for converting string into indian currency format -function inr_currency(nStr) { - nStr += ''; - x = nStr.split('.'); - x1 = x[0]; - x2 = x.length > 1 ? '.' + x[1] : ''; - var rgx = /(\d+)(\d{3})/; - var z = 0; - var len = String(x1).length; - var num = parseInt((len / 2) - 1); - - while (rgx.test(x1)) { - if (z > 0) { - x1 = x1.replace(rgx, '$1' + ',' + '$2'); - } else { - x1 = x1.replace(rgx, '$1' + ',' + '$2'); - rgx = /(\d+)(\d{2})/; - } - z++; - num--; - if (num == 0) { - break; + function inr_currency(nStr) { + nStr += ''; + x = nStr.split('.'); + x1 = x[0]; + x2 = x.length > 1 ? '.' + x[1] : ''; + var rgx = /(\d+)(\d{3})/; + var z = 0; + var len = String(x1).length; + var num = parseInt((len / 2) - 1); + + while (rgx.test(x1)) { + if (z > 0) { + x1 = x1.replace(rgx, '$1' + ',' + '$2'); + } else { + x1 = x1.replace(rgx, '$1' + ',' + '$2'); + rgx = /(\d+)(\d{2})/; + } + z++; + num--; + if (num == 0) { + break; + } } + return x1 + x2; } - return x1 + x2; -} // GLOBAL CURRENCY FORMAT -function format_currency(n) { - return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"); -} - -function dollartToInr() { - var posturl = 'http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json'; - var earningsdollar, finalearnings, convertrate; + function format_currency(n) { + return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"); + } - var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange; + function dollartToInr() { + var posturl = 'http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json'; + var earningsdollar, finalearnings, convertrate; - // Use jQuery.ajax to get the latest exchange rates, with JSONP: + var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange; - $.getJSON(conversionurl, function(data) { - convertrate = data.rates[currency]; /* * 0.975 Midmarket rate*/ + // Use jQuery.ajax to get the latest exchange rates, with JSONP: + if(cache_currency_rate == 'false') { + $.getJSON(conversionurl, function (data) { + convertrate = data.rates[currency]; + /* * 0.975 Midmarket rate*/ - //console.log(data); + //console.log(data); - $.getJSON(posturl, function(data) { - earningsdollar = data.account.available_earnings; /*- 3 payoneer commision $3*/ - finalearnings = earningsdollar * convertrate; + $.getJSON(posturl, function (data) { + earningsdollar = data.account.available_earnings; + /*- 3 payoneer commision $3*/ + finalearnings = earningsdollar * convertrate; - if (currency == 'INR') { - currency_sign = '₹'; - } else if (currency == 'EUR') { - currency_sign = '€'; - } else if (currency == 'GBP') { - currency_sign = '£'; - } else { - currency_sign = currency; - } + if (currency == 'INR') { + currency_sign = '₹'; + } else if (currency == 'EUR') { + currency_sign = '€'; + } else if (currency == 'GBP') { + currency_sign = '£'; + } else { + currency_sign = currency; + } - if (currency == 'INR') { - $('.header-logo-account__balance').text(currency_sign + ' ' + inr_currency(finalearnings.toFixed(2))).parent().attr('title', 'Actual Earnings: $' + earningsdollar); - } else { - $('.header-logo-account__balance').text(currency_sign + ' ' + format_currency(finalearnings)).parent().attr('title', 'Actual Earnings: $' + earningsdollar); - } + if (currency == 'INR') { + $('.header-logo-account__balance').text(currency_sign + ' ' + inr_currency(finalearnings.toFixed(2))).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + } else { + $('.header-logo-account__balance').text(currency_sign + ' ' + format_currency(finalearnings)).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + } - }); - }); -} + }); + }); + } else { + $.getJSON(posturl, function (data) { + earningsdollar = data.account.available_earnings; + /*- 3 payoneer commision $3*/ + finalearnings = earningsdollar * currency_rate.split('||')[1]; + + if (currency == 'INR') { + currency_sign = '₹'; + } else if (currency == 'EUR') { + currency_sign = '€'; + } else if (currency == 'GBP') { + currency_sign = '£'; + } else { + currency_sign = currency; + } -function convertPrice(unconverted_price, handleData) { - var conversion_rate, converted_price; + if (currency == 'INR') { + $('.header-logo-account__balance').text(currency_sign + ' ' + inr_currency(finalearnings.toFixed(2))).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + } else { + $('.header-logo-account__balance').text(currency_sign + ' ' + format_currency(finalearnings)).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + } - if($.type(unconverted_price) === 'string') { - unconverted_price = unconverted_price.replace(/[^0-9\.]/g, ''); + }); + } } - $.ajax({ - url: 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange, - success:function(data){ + function convertPrice(unconverted_price, handleData) { + var conversion_rate, converted_price; + + if($.type(unconverted_price) === 'string') { + unconverted_price = unconverted_price.replace(/[^0-9\.]/g, ''); + } + + if(cache_currency_rate == 'false') { + $.ajax({ + url: 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange, + success: function (data) { + + conversion_rate = data.rates[currency]; + + if (currency == 'INR') { + currency_sign = '₹'; + } else if (currency == 'EUR') { + currency_sign = '€'; + } else if (currency == 'GBP') { + currency_sign = '£'; + } else { + currency_sign = currency; + } + + converted_price = unconverted_price * conversion_rate; - conversion_rate = data.rates[currency]; + if (currency == 'INR') { + converted_price = currency_sign + ' ' + inr_currency(converted_price.toFixed(2)); + } else { + converted_price = currency_sign + ' ' + format_currency(converted_price); + } + handleData(converted_price); + } + }); + } else { if (currency == 'INR') { currency_sign = '₹'; } else if (currency == 'EUR') { @@ -123,7 +188,7 @@ function convertPrice(unconverted_price, handleData) { currency_sign = currency; } - converted_price = unconverted_price * conversion_rate; + converted_price = unconverted_price * currency_rate.split('||')[1]; if (currency == 'INR') { converted_price = currency_sign + ' ' + inr_currency(converted_price.toFixed(2)); @@ -133,271 +198,271 @@ function convertPrice(unconverted_price, handleData) { handleData(converted_price); } - }); -} - -$(document).ready(function() { - - // REMOVE STATEMENTS - AUTHOR FEE - // CONVERT CURRENCIES + } - if (hide_statement != 'false') { - var pathname = window.location.pathname; - var amount = 0; - var amount_string = ''; - var order_id = 0; - var next_amount = ''; + $(document).ready(function() { - var unconverted, converted, current_object = [], conversion_rate; + // REMOVE STATEMENTS - AUTHOR FEE + // CONVERT CURRENCIES - if (pathname.indexOf('statement') > -1) { - $("#stored_statement").find("tr").each(function(i) { + if (hide_statement != 'false') { + var pathname = window.location.pathname; + var amount = 0; + var amount_string = ''; + var order_id = 0; + var next_amount = ''; - if ($(this).find("td").eq(3).find("span").text() == "Author Fee") { + var unconverted, converted, current_object = [], conversion_rate; - order_id = $(this).find('.statement__order_id').text(); - amount_string = $(this).find('.statement__amount').text(); - amount = parseFloat(amount_string.substring(1, amount_string.length)); - next_amount = $(this).next().find('.statement__amount').text(); - next_amount = parseFloat(next_amount.substring(1, next_amount.length)); + if (pathname.indexOf('statement') > -1) { + $("#stored_statement").find("tr").each(function(i) { - amount = amount + next_amount; + if ($(this).find("td").eq(3).find("span").text() == "Author Fee") { - $(this).next().find('.statement__amount').text('$' + amount.toFixed(2)); - $(this).hide(); - } + order_id = $(this).find('.statement__order_id').text(); + amount_string = $(this).find('.statement__amount').text(); + amount = parseFloat(amount_string.substring(1, amount_string.length)); + next_amount = $(this).next().find('.statement__amount').text(); + next_amount = parseFloat(next_amount.substring(1, next_amount.length)); - if(localise_earnings_table != 'false') { - if (openexchange == 'undefined') { - return false; - } else { - if ($(this).is(':visible')) { - current_object[i] = $(this); + amount = amount + next_amount; - if (current_object[i].find('td').eq(7).text() != '') { - unconverted = current_object[i].find('td').eq(7).text(); - unconverted = parseFloat(unconverted.substring(1, unconverted.length)); + $(this).next().find('.statement__amount').text('$' + amount.toFixed(2)); + $(this).hide(); + } - converted = convertPrice(unconverted, function(data){ - current_object[i].find('td').eq(7).text(data).attr('title', 'Actual Earnings: $' + unconverted); - }); - } - if (current_object[i].find('td').eq(8).text() != '') { - unconverted = current_object[i].find('td').eq(8).text(); - unconverted = unconverted.substring(1, unconverted.length); - converted = convertPrice(unconverted, function(data){ - current_object[i].find('td').eq(8).text(data).attr('title', 'Actual Earnings: $' + unconverted); - }); + if(localise_earnings_table != 'false') { + if (openexchange == 'undefined') { + return false; + } else { + if ($(this).is(':visible')) { + current_object[i] = $(this); + + if (current_object[i].find('td').eq(7).text() != '') { + unconverted = current_object[i].find('td').eq(7).text(); + unconverted = parseFloat(unconverted.substring(1, unconverted.length)); + + converted = convertPrice(unconverted, function(data){ + current_object[i].find('td').eq(7).text(data).attr('title', 'Actual Earnings: $' + unconverted); + }); + } + if (current_object[i].find('td').eq(8).text() != '') { + unconverted = current_object[i].find('td').eq(8).text(); + unconverted = unconverted.substring(1, unconverted.length); + converted = convertPrice(unconverted, function(data){ + current_object[i].find('td').eq(8).text(data).attr('title', 'Actual Earnings: $' + unconverted); + }); + } } } } - } - }); + }); + } } - } - // CONVERT CURRENCIES IN EARNINGS TAB - if(localise_earnings_page != 'false') { - var pathname = window.location.pathname; - if(pathname.indexOf('/earnings/') > -1) { - - // Generate new graph - var graph_data = $.parseJSON($('body script[id="graphdata"]').text()); - var current_object, unconverted, converted, data_indexes, counter; - counter = 0; - data_indexes = graph_data.datasets[0]['data'].length; - - $.each(graph_data.datasets[0]['data'], function(i, val){ - if(val > 0) { - // Localize - if (openexchange == 'undefined') { - return false; + // CONVERT CURRENCIES IN EARNINGS TAB + if(localise_earnings_page != 'false') { + var pathname = window.location.pathname; + if(pathname.indexOf('/earnings/') > -1) { + + // Generate new graph + var graph_data = $.parseJSON($('body script[id="graphdata"]').text()); + var current_object, unconverted, converted, data_indexes, counter; + counter = 0; + data_indexes = graph_data.datasets[0]['data'].length; + + $.each(graph_data.datasets[0]['data'], function(i, val){ + if(val > 0) { + // Localize + if (openexchange == 'undefined') { + return false; + } else { + current_object = $(this); + unconverted = parseFloat(val); + + converted = convertPrice(unconverted, function (data) { + if (parseFloat(data.replace(/[^0-9\.]/g, '')) > 0) { + graph_data.datasets[0]['data'][i] = parseFloat(data.replace(/[^0-9\.]/g, '')); + counter++; + } + }); + } } else { - current_object = $(this); - unconverted = parseFloat(val); - - converted = convertPrice(unconverted, function (data) { - if (parseFloat(data.replace(/[^0-9\.]/g, '')) > 0) { - graph_data.datasets[0]['data'][i] = parseFloat(data.replace(/[^0-9\.]/g, '')); - counter++; - } - }); + counter++; } - } else { - counter++; - } - }); + }); - var renderGraph = setInterval(function(){ - if(data_indexes == counter) { - $('.-sales').text('Sales Earnings ('+currency+')'); + var renderGraph = setInterval(function(){ + if(data_indexes == counter) { + $('.-sales').text('Sales Earnings ('+currency+')'); - var chart_data = { - animationEasing: "easeInOutCirc", - animationSteps: 60, - scaleFontSize: 12, - scaleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", - scaleLabel: "<%=parseFloat(value).toLocaleString('en-EN', {style: 'currency', currency: '"+currency+"', minimumFractionDigits: 2})%>", - scaleStartValue: 0, - showTooltips: !1, - bezierCurve: !1 - }; + var chart_data = { + animationEasing: "easeInOutCirc", + animationSteps: 60, + scaleFontSize: 12, + scaleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", + scaleLabel: "<%=parseFloat(value).toLocaleString('en-EN', {style: 'currency', currency: '"+currency+"', minimumFractionDigits: 2})%>", + scaleStartValue: 0, + showTooltips: !1, + bezierCurve: !1 + }; - $(".js-graph__canvas").remove(); - $('.graph__container').append(''); + $(".js-graph__canvas").remove(); + $('.graph__container').append(''); - var canvas = $(".graph__canvas").get(0).getContext('2d'); - new Chart(canvas).Line(graph_data, chart_data); + var canvas = $(".graph__canvas").get(0).getContext('2d'); + new Chart(canvas).Line(graph_data, chart_data); - clearInterval(renderGraph); - } - }, 100); + clearInterval(renderGraph); + } + }, 100); - // Convert headers (This month, balance, total value) - convertPrice($('.earnings-widget__amount:eq(0)').text().substr(1), function(data){ - $('.earnings-widget__amount:eq(0)').text(data); - }); - convertPrice($('.earnings-widget__amount:eq(1)').text().substr(1), function(data){ - $('.earnings-widget__amount:eq(1)').text(data); - }); - convertPrice($('.earnings-widget__amount:eq(2)').text().substr(1), function(data){ - $('.earnings-widget__amount:eq(2)').text(data); - }); - // Reduce font size to avoid design breakage in local currency - $('.earnings-widget__amount').css('font-size','30px'); - - // Convert prices in table - if(pathname.indexOf('/earnings/sales') > -1) { - $('.table-general tbody, tfoot').find('tr').each(function(index){ - current_object[index] = $(this); - convertPrice($(this).find('td').eq(2).text().substr(1), function(data){ - current_object[index].find('td').eq(2).text(data); - }); + // Convert headers (This month, balance, total value) + convertPrice($('.earnings-widget__amount:eq(0)').text().substr(1), function(data){ + $('.earnings-widget__amount:eq(0)').text(data); }); - } else if(pathname.indexOf('/earnings/referrals') > -1) { - $('.table-general tbody, tfoot').find('tr').each(function(index){ - current_object[index] = $(this); - convertPrice($(this).find('td').eq(4).text().substr(1), function(data){ - current_object[index].find('td').eq(4).text(data); + convertPrice($('.earnings-widget__amount:eq(1)').text().substr(1), function(data){ + $('.earnings-widget__amount:eq(1)').text(data); + }); + convertPrice($('.earnings-widget__amount:eq(2)').text().substr(1), function(data){ + $('.earnings-widget__amount:eq(2)').text(data); + }); + // Reduce font size to avoid design breakage in local currency + $('.earnings-widget__amount').css('font-size','30px'); + + // Convert prices in table + if(pathname.indexOf('/earnings/sales') > -1) { + $('.table-general tbody, tfoot').find('tr').each(function(index){ + current_object[index] = $(this); + convertPrice($(this).find('td').eq(2).text().substr(1), function(data){ + current_object[index].find('td').eq(2).text(data); + }); }); - convertPrice($(this).find('td').eq(5).text().substr(1), function(data){ - current_object[index].find('td').eq(5).text(data); + } else if(pathname.indexOf('/earnings/referrals') > -1) { + $('.table-general tbody, tfoot').find('tr').each(function(index){ + current_object[index] = $(this); + convertPrice($(this).find('td').eq(4).text().substr(1), function(data){ + current_object[index].find('td').eq(4).text(data); + }); + convertPrice($(this).find('td').eq(5).text().substr(1), function(data){ + current_object[index].find('td').eq(5).text(data); + }); }); - }); + } } } - } - // SHOW LINKS IN REFERRALS PAGE - if(create_hrefs != 'false') { - var pathname = window.location.pathname; - if (pathname.indexOf('/referrals') > -1) { - var source = ''; - var path = ''; - var url = ''; - - var ifTableExists = setInterval(function () { - if ($('#results').length) { - clearInterval(ifTableExists); - $('#results').find('tr').each(function () { - if ($(this).find('td').eq(1).text() != '(not set)') { - source = $(this).find('td').eq(0).text(); - path = $(this).find('td').eq(1).text(); - - url = '' + path + ''; - - $(this).find('td').eq(1).html(url); - } - }); - } - }, 100); + // SHOW LINKS IN REFERRALS PAGE + if(create_hrefs != 'false') { + var pathname = window.location.pathname; + if (pathname.indexOf('/referrals') > -1) { + var source = ''; + var path = ''; + var url = ''; + + var ifTableExists = setInterval(function () { + if ($('#results').length) { + clearInterval(ifTableExists); + $('#results').find('tr').each(function () { + if ($(this).find('td').eq(1).text() != '(not set)') { + source = $(this).find('td').eq(0).text(); + path = $(this).find('td').eq(1).text(); + + url = '' + path + ''; + + $(this).find('td').eq(1).html(url); + } + }); + } + }, 100); + } } - } - // VERIFY PURCHASE + // VERIFY PURCHASE - if (verify_purchase != 'false') { - var pathname = window.location.pathname; - if (pathname.indexOf('author_dashboard') > -1) { - var verify_html_block = '

Verify Purchase Code

'; + if (verify_purchase != 'false') { + var pathname = window.location.pathname; + if (pathname.indexOf('author_dashboard') > -1) { + var verify_html_block = '

Verify Purchase Code

'; - //$("#content .content-s").append(verify_html_block); - $(verify_html_block).insertBefore("#content .content-s .content-s"); - //alert('done'); + //$("#content .content-s").append(verify_html_block); + $(verify_html_block).insertBefore("#content .content-s .content-s"); + //alert('done'); + } } - } - $("#verifypurchase").submit(function(e) { - e.preventDefault(); - var purchase_code = $("#purchase_code"); - var flag = false; - if (purchase_code.val() == "") { - purchase_code.focus(); - flag = false; - return false; - } else { - flag = true; - } - var item_purchase_code = purchase_code.val(); - $(".loading").fadeIn("slow").html("

Please wait...

"); + $("#verifypurchase").submit(function(e) { + e.preventDefault(); + var purchase_code = $("#purchase_code"); + var flag = false; + if (purchase_code.val() == "") { + purchase_code.focus(); + flag = false; + return false; + } else { + flag = true; + } + var item_purchase_code = purchase_code.val(); + $(".loading").fadeIn("slow").html("

Please wait...

"); - var posturl = 'http://marketplace.envato.com/api/v3/' + username + '/' + apikey + '/verify-purchase:' + item_purchase_code + '.json'; + var posturl = 'http://marketplace.envato.com/api/v3/' + username + '/' + apikey + '/verify-purchase:' + item_purchase_code + '.json'; - $.ajax({ - type: 'GET', - url: posturl, - data: { - get_param: 'value' - }, - dataType: 'json', - success: function(data) { + $.ajax({ + type: 'GET', + url: posturl, + data: { + get_param: 'value' + }, + dataType: 'json', + success: function(data) { - if (data['verify-purchase'].buyer == '' || data['verify-purchase'].buyer == null) { + if (data['verify-purchase'].buyer == '' || data['verify-purchase'].buyer == null) { - $('.loading').fadeIn('slow').html('

Sorry. That was a wrong verification code!

'); + $('.loading').fadeIn('slow').html('

Sorry. That was a wrong verification code!

'); - } else if (data.code == 'not_authenticated') { - $('.loading').fadeIn('slow').html('

Sorry. Username and/or API Key is invalid.

'); - } else { + } else if (data.code == 'not_authenticated') { + $('.loading').fadeIn('slow').html('

Sorry. Username and/or API Key is invalid.

'); + } else { - var buyer = data['verify-purchase'].buyer; - var item_name = data['verify-purchase'].item_name; - var licence = data['verify-purchase'].licence; - var timestamp = data['verify-purchase'].created_at; + var buyer = data['verify-purchase'].buyer; + var item_name = data['verify-purchase'].item_name; + var licence = data['verify-purchase'].licence; + var timestamp = data['verify-purchase'].created_at; - $('.loading').fadeIn('slow').html('

' + buyer + ' purchased a ' + licence + ' of ' + item_name + ' ' + $.timeago(timestamp) + '

'); + $('.loading').fadeIn('slow').html('

' + buyer + ' purchased a ' + licence + ' of ' + item_name + ' ' + $.timeago(timestamp) + '

'); - } + } - }, + }, - error: function(data) { - $('.loading').fadeIn('slow').html('

Sorry. Something went wrong!

'); - } + error: function(data) { + $('.loading').fadeIn('slow').html('

Sorry. Something went wrong!

'); + } - }); + }); - }); + }); // Hide Author Earnings // Author is browsing in public and do not want to reveal his balance - if (hide_earnings == 'true') { - $('.header-logo-account__balance').hide(); - } + if (hide_earnings == 'true') { + $('.header-logo-account__balance').hide(); + } -}); /*End Document Ready*/ + }); /*End Document Ready*/ -var current_url = window.location.pathname; + var current_url = window.location.pathname; -$(document).click(function() { - if(window.location.pathname.indexOf('/earnings/') > -1) { - if (current_url != window.location.pathname) { - location.reload(); + $(document).click(function() { + if(window.location.pathname.indexOf('/earnings/') > -1) { + if (current_url != window.location.pathname) { + location.reload(); + } } - } + }); }); \ No newline at end of file diff --git a/options.html b/options.html index 37feb28..8eaa5b5 100644 --- a/options.html +++ b/options.html @@ -276,6 +276,12 @@

Better Envato Options

+
+ +

diff --git a/options.js b/options.js index 3732d84..6bb2f06 100644 --- a/options.js +++ b/options.js @@ -51,6 +51,19 @@ function save_options() { var value = $(this).prop('checked').toString(); save_option(name, value); + + if(name == 'cache_currency_rate') { + // Fetch latest currency rate + get_option('openexchange', function(apikey){ + var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + apikey; + var current_timestamp = Math.floor(Date.now() / 1000); + $.getJSON(conversionurl, function(data) { + get_option('currency', function(currency){ + save_option('currency_rate', current_timestamp+'||'+data.rates[currency]); + }); + }); + }); + } }); $(this).text('Saving...').removeClass("btn-success"); From d321c35d7a7b89b1caca73409cf138d8afe384bb Mon Sep 17 00:00:00 2001 From: Zan Gerden Date: Mon, 16 Mar 2015 06:02:54 +0100 Subject: [PATCH 7/9] Fix: Re-cache if currency is changed, and re-caching on request not on page load --- better-envato.js | 145 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 109 insertions(+), 36 deletions(-) diff --git a/better-envato.js b/better-envato.js index ce19f76..f945d18 100644 --- a/better-envato.js +++ b/better-envato.js @@ -37,11 +37,11 @@ chrome.storage.sync.get(null, function(response){ var current_timestamp = Math.floor(Date.now() / 1000); var day_ago_time = current_timestamp - 86400; - if(last_cached_time < day_ago_time) { + if(exchange_rate[2] != currency || last_cached_time < day_ago_time) { // Fetch latest currency rate var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange; $.getJSON(conversionurl, function(data) { - save_option('currency_rate', current_timestamp+'||'+data.rates[currency]); + save_option('currency_rate', current_timestamp+'||'+data.rates[currency]+'||'+currency); }); } } @@ -117,28 +117,66 @@ chrome.storage.sync.get(null, function(response){ }); }); } else { - $.getJSON(posturl, function (data) { - earningsdollar = data.account.available_earnings; - /*- 3 payoneer commision $3*/ - finalearnings = earningsdollar * currency_rate.split('||')[1]; + var exchange_rate = currency_rate.split('||') || 1; - if (currency == 'INR') { - currency_sign = '₹'; - } else if (currency == 'EUR') { - currency_sign = '€'; - } else if (currency == 'GBP') { - currency_sign = '£'; - } else { - currency_sign = currency; - } + var last_cached_time = exchange_rate[0]; + var last_exchange_rate = exchange_rate[1]; + var current_timestamp = Math.floor(Date.now() / 1000); + var day_ago_time = current_timestamp - 86400; - if (currency == 'INR') { - $('.header-logo-account__balance').text(currency_sign + ' ' + inr_currency(finalearnings.toFixed(2))).parent().attr('title', 'Actual Earnings: $' + earningsdollar); - } else { - $('.header-logo-account__balance').text(currency_sign + ' ' + format_currency(finalearnings)).parent().attr('title', 'Actual Earnings: $' + earningsdollar); - } + if(exchange_rate[2] != currency || last_cached_time < day_ago_time) { + // Fetch latest currency rate + var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange; + $.getJSON(conversionurl, function(data) { + save_option('currency_rate', current_timestamp+'||'+data.rates[currency]+'||'+currency); + + $.getJSON(posturl, function (data) { + earningsdollar = data.account.available_earnings; + /*- 3 payoneer commision $3*/ + finalearnings = earningsdollar * data.rates[currency]; + + if (currency == 'INR') { + currency_sign = '₹'; + } else if (currency == 'EUR') { + currency_sign = '€'; + } else if (currency == 'GBP') { + currency_sign = '£'; + } else { + currency_sign = currency; + } - }); + if (currency == 'INR') { + $('.header-logo-account__balance').text(currency_sign + ' ' + inr_currency(finalearnings.toFixed(2))).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + } else { + $('.header-logo-account__balance').text(currency_sign + ' ' + format_currency(finalearnings)).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + } + + }); + }); + } else { + $.getJSON(posturl, function (data) { + earningsdollar = data.account.available_earnings; + /*- 3 payoneer commision $3*/ + finalearnings = earningsdollar * currency_rate.split('||')[1]; + + if (currency == 'INR') { + currency_sign = '₹'; + } else if (currency == 'EUR') { + currency_sign = '€'; + } else if (currency == 'GBP') { + currency_sign = '£'; + } else { + currency_sign = currency; + } + + if (currency == 'INR') { + $('.header-logo-account__balance').text(currency_sign + ' ' + inr_currency(finalearnings.toFixed(2))).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + } else { + $('.header-logo-account__balance').text(currency_sign + ' ' + format_currency(finalearnings)).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + } + + }); + } } } @@ -178,25 +216,60 @@ chrome.storage.sync.get(null, function(response){ } }); } else { - if (currency == 'INR') { - currency_sign = '₹'; - } else if (currency == 'EUR') { - currency_sign = '€'; - } else if (currency == 'GBP') { - currency_sign = '£'; - } else { - currency_sign = currency; - } + var exchange_rate = currency_rate.split('||') || 1; + + var last_cached_time = exchange_rate[0]; + var last_exchange_rate = exchange_rate[1]; + var current_timestamp = Math.floor(Date.now() / 1000); + var day_ago_time = current_timestamp - 86400; + + if(exchange_rate[2] != currency || last_cached_time < day_ago_time) { + // Fetch latest currency rate + var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange; + $.getJSON(conversionurl, function(data) { + save_option('currency_rate', current_timestamp+'||'+data.rates[currency]+'||'+currency); + + if (currency == 'INR') { + currency_sign = '₹'; + } else if (currency == 'EUR') { + currency_sign = '€'; + } else if (currency == 'GBP') { + currency_sign = '£'; + } else { + currency_sign = currency; + } - converted_price = unconverted_price * currency_rate.split('||')[1]; + converted_price = unconverted_price * currency_rate.split('||')[1]; - if (currency == 'INR') { - converted_price = currency_sign + ' ' + inr_currency(converted_price.toFixed(2)); + if (currency == 'INR') { + converted_price = currency_sign + ' ' + inr_currency(converted_price.toFixed(2)); + } else { + converted_price = currency_sign + ' ' + format_currency(converted_price); + } + + handleData(converted_price); + }); } else { - converted_price = currency_sign + ' ' + format_currency(converted_price); - } + if (currency == 'INR') { + currency_sign = '₹'; + } else if (currency == 'EUR') { + currency_sign = '€'; + } else if (currency == 'GBP') { + currency_sign = '£'; + } else { + currency_sign = currency; + } - handleData(converted_price); + converted_price = unconverted_price * currency_rate.split('||')[1]; + + if (currency == 'INR') { + converted_price = currency_sign + ' ' + inr_currency(converted_price.toFixed(2)); + } else { + converted_price = currency_sign + ' ' + format_currency(converted_price); + } + + handleData(converted_price); + } } } From a960796f0ded195eb39ab3931fd9359d4d533787 Mon Sep 17 00:00:00 2001 From: Zan Gerden Date: Mon, 23 Mar 2015 16:34:31 +0100 Subject: [PATCH 8/9] Fix: Fix when some options weren't saved --- better-envato.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/better-envato.js b/better-envato.js index f945d18..443861d 100644 --- a/better-envato.js +++ b/better-envato.js @@ -5,6 +5,23 @@ */ var username, apikey, openexchange, currency, localise_earnings, localise_earnings_table, localise_earnings_page, hide_statement, verify_purchase, create_hrefs, cache_currency_rate, currency_rate; +/** + * Saves option to Chrome.storage + */ +function save_option(name, value){ + var object = {}; + object[name] = value; + + chrome.storage.sync.set(object, function() { + if(chrome.extension.lastError) { + console.log('An error occured: ' + chrome.extension.lastError.message); + return false; + } else { + return true; + } + }); +} + // Load options from Chrome's storage chrome.storage.sync.get(null, function(response){ username = response.username; From d10c3463b7b261f66fb77599516bb498d3a5755f Mon Sep 17 00:00:00 2001 From: surjithctly Date: Sat, 5 Sep 2015 16:35:16 +0530 Subject: [PATCH 9/9] Better Envato v1.2.6 Option to change the look of new forums for better readability + close envato item preview bar automatically. --- background.html | 8 +- background.js | 304 ++++++--------- better-envato.js | 940 +++++++++++++++++++++-------------------------- css/forums.css | 169 +++++++++ css/options.css | 88 +++-- manifest.json | 83 ++--- options.html | 666 +++++++++++++++++---------------- options.js | 160 +++----- 8 files changed, 1217 insertions(+), 1201 deletions(-) create mode 100644 css/forums.css diff --git a/background.html b/background.html index 26e80ad..931d41b 100644 --- a/background.html +++ b/background.html @@ -1,11 +1,11 @@ - Envato sales desktop notification - - + Envato sales desktop notification + + - + diff --git a/background.js b/background.js index 7f85c04..829799a 100644 --- a/background.js +++ b/background.js @@ -1,55 +1,37 @@ // Show the config file on installation chrome.runtime.onInstalled.addListener(function(object) { - get_option('firsttime', function(value){ - if(value != 'false' || !value) { - var optionsurl = chrome.extension.getURL("options.html"); - chrome.tabs.create({ - url: optionsurl - }, function(tab) {}); - - save_option('firsttime', 'false'); - } - }); - - var currentversion = chrome.app.getDetails().version; + if (localStorage.firsttime != 'false' || localStorage.firsttime == 'undefined' || !localStorage.firsttime ) { + var optionsurl = chrome.extension.getURL("options.html"); + chrome.tabs.create({ + url: optionsurl + }, function(tab) {}); + + localStorage.firsttime = false; +} - get_option('version', function(value){ - if(!value || value != currentversion) { - chrome.browserAction.setBadgeText({text:"NEW"}); +var currentversion = chrome.app.getDetails().version; - save_option('version', currentversion); - } - }); + if (!localStorage.version || localStorage.version != currentversion) { + chrome.browserAction.setBadgeText({text:"NEW"}); + localStorage.version = currentversion +} //chrome.browserAction.setBadgeBackgroundColor({color:[255, 64, 64, 230]}); - - // Check if localStorage is in usage - if(!isEmpty(localStorage)) { - // localStorage is in use, so move all options from there to chrome.storage - //delete localStorage.apikey; - - for(var i = 0; i < localStorage.length; i++) { - var name = localStorage.key(i); - var value = localStorage.getItem(localStorage.key(i)); - - save_option(name, value); - - delete localStorage[name]; - } - } - + + }); + // Get Local Storage value in Content Script /*chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { - if (request.method == "getLocalStorage") - sendResponse({data: localStorage[request.key]}); - else - sendResponse({}); // snub them. - }); - */ + if (request.method == "getLocalStorage") + sendResponse({data: localStorage[request.key]}); + else + sendResponse({}); // snub them. +}); +*/ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { switch (message.method) { @@ -69,26 +51,19 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { }); } break; - // ... + // ... } }); -// Open Options Page if clicked on icons +// Open Opeions Page if clicked on icons chrome.browserAction.onClicked.addListener(function(tab) { //Fired when User Clicks ICON chrome.tabs.create({ url: "options.html" }); - chrome.browserAction.setBadgeText({text:""}); + chrome.browserAction.setBadgeText({text:""}); }); -function isEmpty(obj) { - for(var prop in obj) { - if(obj.hasOwnProperty(prop)) - return false; - } - return true; -} function updatedSettings() { //chrome.runtime.reload(); @@ -99,22 +74,22 @@ function updatedSettings() { // Test for notification support. if (window.Notification) { - get_option('sales_notification', function(value){ - if(value != 'false') { + if (localStorage.sales_notification != 'false') { + // While activated, show notifications at the display frequency. + sales_notification(); + setInterval(function() { sales_notification(); - setInterval(function() { - sales_notification(); - }, 60000); - } - }); - get_option('comment_notification', function(value){ - if(value != 'false') { + }, 60000); + } + + if (localStorage.comment_notification != 'false') { + // While activated, show notifications at the display frequency. + comment_notification(); + setInterval(function() { comment_notification(); - setInterval(function() { - comment_notification(); - }, 60000); - } - }); + }, 60000); + } + } @@ -122,59 +97,56 @@ if (window.Notification) { // Sales Notifications function sales_notification() { - get_option('username', function(value){ - var username = value; - if(typeof username == 'undefined') { - return false; - } - get_option('apikey', function(value){ - var apikey = value; - if(typeof apikey == 'undefined') { - return false; - } - get_option('earnings', function(value){ - var earnings = value; - // Use Envato API to check sales - $.get('http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json', function(data) { + var username = localStorage.username; + var apikey = localStorage.apikey; + var earnings = localStorage.earnings; - //get current sales - var new_earnings = data.account.available_earnings; - var first_name = data.account.firstname; + if (typeof username == 'undefined' || typeof apikey == 'undefined') { + return false; + } - if (earnings < new_earnings) { + // Use Envato API to check sales + $.get('http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json', function(data) { - $.get('http://marketplace.envato.com/api/v3/' + username + '/' + apikey + '/recent-sales.json', function(salesdata) { + //get current sales + var new_earnings = data.account.available_earnings; + var first_name = data.account.firstname; - //get current sales - var sold_item = salesdata["recent-sales"][0].item; - var item_price = salesdata["recent-sales"][0].amount; - show_notification(new_earnings, item_price, first_name, sold_item, 'item'); - play_sound(); + //earnings < new_earnings + // testing: new_earnings > 1 - }); - } + if (earnings < new_earnings) { - save_option('earnings', new_earnings); + $.get('http://marketplace.envato.com/api/v3/' + username + '/' + apikey + '/recent-sales.json', function(salesdata) { + + //get current sales + var sold_item = salesdata["recent-sales"][0].item; + var item_price = salesdata["recent-sales"][0].amount; + show_notification(new_earnings, item_price, first_name, sold_item, 'item'); + play_sound(); - }); }); - }); + } + + + localStorage.earnings = new_earnings; + }); + } // Play a sound on new sale function play_sound() { - get_option('play_sound', function(value){ - if(value != 'false') { - if ($('#cha-ching').length) $('#cha-ching').remove(); - $('').appendTo('body'); - } - return false; - }); + if (localStorage.play_sound != 'false') { + if ($('#cha-ching').length) $('#cha-ching').remove(); + $('').appendTo('body'); + } + return false; } function show_notification(new_earnings, item_price, first_name, sold_item, item) { + var praiseArray = ['Woohoo', 'Bravo', 'Wow', 'Ahoy', 'Yay', 'Yikes', 'Hooray', 'Whoa', 'Woot', 'Oh joy', first_name]; var randomPraise = praiseArray[Math.floor(Math.random() * praiseArray.length)]; @@ -186,103 +158,69 @@ function show_notification(new_earnings, item_price, first_name, sold_item, item notification.onclick = function() { window.open("http://themeforest.net/statement"); } + if (localStorage.auto_hide_sales_notification != 'false') { + setTimeout(function() { + notification.close() + }, 15000); + } - get_option('auto_hide_sales_notification', function(value){ - if(value != 'false') { - setTimeout(function() { - notification.close() - }, 15000); - } - }); } function comment_notification() { - get_option('username', function(value){ - var username = value; - get_option('new_comment_id', function(value){ - var last_comment_id = value; - - $.get('http://themeforest.net/feeds/user_item_comments/' + username + '.atom', function(data) { - //console.log(data); - var comment_feed = $.xml2json(data); - //console.log(comment_feed); - var comment_id = comment_feed.entry[0].id; - var comment_id_hash = comment_id.substr(comment_id.lastIndexOf('/') + 1); - var comment_author = comment_feed.entry[0].author.name; - var new_comment = /* $(comment_feed.entry[0].content.text).text(); */ comment_feed.entry[0].content.text.replace(/(<([^>]+)>)/ig, ""); - new_comment = new_comment.replace(/\s{2,}/g, ' '); - var new_comment_item = $.trim(comment_feed.entry[0].title).substring(0, 20).split(" ").slice(0, -1).join(" ") + "..."; - var new_comment_url = comment_feed.entry[0].link.href; - //console.log(new_comment); - - if (last_comment_id != comment_id && comment_author != username) { - show_comments(new_comment, new_comment_item, new_comment_url, comment_id_hash); - save_option('new_comment_id', comment_id); - play_notification(); - } - - }); - // Play a sound on new comment - function play_notification() { - get_option('comment_sound', function(value){ - if(value != 'false') { - if ($('#comment_sound').length) $('#comment_sound').remove(); - $('').appendTo('body'); - } - return false; - }); - } + var username = localStorage.username; + var last_comment_id = localStorage.new_comment_id; + + $.get('http://themeforest.net/feeds/user_item_comments/' + username + '.atom', function(data) { + //console.log(data); + var comment_feed = $.xml2json(data); + //console.log(comment_feed); + var comment_id = comment_feed.entry[0].id; + var comment_id_hash = comment_id.substr(comment_id.lastIndexOf('/') + 1); + var comment_author = comment_feed.entry[0].author.name; + var new_comment = /* $(comment_feed.entry[0].content.text).text(); */ comment_feed.entry[0].content.text.replace(/(<([^>]+)>)/ig, ""); + new_comment = new_comment.replace(/\s{2,}/g, ' '); + var new_comment_item = $.trim(comment_feed.entry[0].title).substring(0, 20).split(" ").slice(0, -1).join(" ") + "..."; + var new_comment_url = comment_feed.entry[0].link.href; + //console.log(new_comment); + + if (last_comment_id != comment_id && comment_author != username) { + show_comments(new_comment, new_comment_item, new_comment_url, comment_id_hash); + localStorage.new_comment_id = comment_id; + play_notification(); + } - function show_comments(new_comment, new_comment_item, new_comment_url, comment_id_hash) { + }); - var c_notification = new Notification('New Comment for ' + new_comment_item, { - icon: 'img/48.png', - body: new_comment - }); + // Play a sound on new comment + function play_notification() { + if (localStorage.comment_sound != 'false') { + if ($('#comment_sound').length) $('#comment_sound').remove(); + $('').appendTo('body'); + } + return false; + } - c_notification.onclick = function() { - window.open(new_comment_url + '/' + comment_id_hash); - } - get_option('auto_hide_comment_notification', function(value){ - if(value != 'false') { - setTimeout(function() { - c_notification.close() - }, 15000); - } - }); - } + function show_comments(new_comment, new_comment_item, new_comment_url, comment_id_hash) { + var c_notification = new Notification('New Comment for ' + new_comment_item, { + icon: 'img/48.png', + body: new_comment }); - }); -} -/** - * Saves option to Chrome.storage - */ -function save_option(name, value){ - var object = {}; - object[name] = value; - - chrome.storage.sync.set(object, function() { - if(chrome.extension.lastError) { - console.log('An error occured: ' + chrome.extension.lastError.message); - alert('An error occured: ' + chrome.extension.lastError.message); - return false; - } else { - return true; + c_notification.onclick = function() { + window.open(new_comment_url + '/' + comment_id_hash); } - }); -} + + if (localStorage.auto_hide_comment_notification != 'false') { + setTimeout(function() { + c_notification.close() + }, 15000); + } + + } -/** - * Gets option from Chrome.storage - */ -function get_option(name, callback) { - chrome.storage.sync.get(name, function(response) { - callback(response[name], name); - }) } \ No newline at end of file diff --git a/better-envato.js b/better-envato.js index 443861d..3a9e58e 100644 --- a/better-envato.js +++ b/better-envato.js @@ -1,558 +1,470 @@ /* - Name: Better Envato - Keywords: make Envato Better - Created by: Surjith S M © 2015-2020 - */ -var username, apikey, openexchange, currency, localise_earnings, localise_earnings_table, localise_earnings_page, hide_statement, verify_purchase, create_hrefs, cache_currency_rate, currency_rate; - -/** - * Saves option to Chrome.storage - */ -function save_option(name, value){ - var object = {}; - object[name] = value; - - chrome.storage.sync.set(object, function() { - if(chrome.extension.lastError) { - console.log('An error occured: ' + chrome.extension.lastError.message); +Name: Better Envato +Keywords: make Envato Better +Created by: Surjith S M © 2015-2020 +*/ +var username, apikey, openexchange, currency, localise_earnings, localise_earnings_table, localise_earnings_page, hide_statement, verify_purchase, create_hrefs, old_forum_look, close_iframe_preview; +chrome.runtime.sendMessage({ + method: "getLocalStorage", + keys: ["username", "apikey", "openexchange", "currency", "localise_earnings", 'localise_earnings_table', 'localise_earnings_page', 'hide_statement', 'verify_purchase', 'create_hrefs', 'hide_earnings', 'old_forum_look', 'close_iframe_preview'] + }, + function(response) { + username = response.data.username; + apikey = response.data.apikey; + openexchange = response.data.openexchange; + currency = response.data.currency; + localise_earnings = response.data.localise_earnings; + localise_earnings_table = response.data.localise_earnings_table; + localise_earnings_page = response.data.localise_earnings_page; + hide_statement = response.data.hide_statement; + verify_purchase = response.data.verify_purchase; + create_hrefs = response.data.create_hrefs; + hide_earnings = response.data.hide_earnings; + old_forum_look = response.data.old_forum_look; + close_iframe_preview = response.data.close_iframe_preview; + } +); +/*hide_forum_posts = response.data.hide_forum_posts; + forum_blacklist = response.data.forum_blacklist; + forum_whitelist = response.data.forum_whitelist;*/ +$(document).ready(function() { + if (localise_earnings != 'false') { + if (username == 'undefined' || apikey == 'undefined' || openexchange == 'undefined') { return false; } else { - return true; + dollartToInr(); } - }); + } +}); +//function for converting string into indian currency format +function inr_currency(nStr) { + nStr += ''; + x = nStr.split('.'); + x1 = x[0]; + x2 = x.length > 1 ? '.' + x[1] : ''; + var rgx = /(\d+)(\d{3})/; + var z = 0; + var len = String(x1).length; + var num = parseInt((len / 2) - 1); + while (rgx.test(x1)) { + if (z > 0) { + x1 = x1.replace(rgx, '$1' + ',' + '$2'); + } else { + x1 = x1.replace(rgx, '$1' + ',' + '$2'); + rgx = /(\d+)(\d{2})/; + } + z++; + num--; + if (num == 0) { + break; + } + } + return x1 + x2; +} +// GLOBAL CURRENCY FORMAT +function format_currency(n) { + return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"); } -// Load options from Chrome's storage -chrome.storage.sync.get(null, function(response){ - username = response.username; - apikey = response.apikey; - openexchange = response.openexchange; - currency = response.currency; - localise_earnings = response.localise_earnings; - localise_earnings_table = response.localise_earnings_table; - localise_earnings_page = response.localise_earnings_page; - hide_statement = response.hide_statement; - verify_purchase = response.verify_purchase; - create_hrefs = response.create_hrefs; - hide_earnings = response.hide_earnings; - cache_currency_rate = response.cache_currency_rate; - currency_rate = response.currency_rate; - - $(document).ready(function() { - if (localise_earnings != 'false') { - if (username == 'undefined' || apikey == 'undefined' || openexchange == 'undefined') { - return false; +function dollartToInr() { + var posturl = 'https://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json'; + var earningsdollar, finalearnings, convertrate; + var conversionurl = 'https://openexchangerates.org/api/latest.json?app_id=' + openexchange; + // Use jQuery.ajax to get the latest exchange rates, with JSONP: + $.getJSON(conversionurl, function(data) { + convertrate = data.rates[currency]; /* * 0.975 Midmarket rate*/ + console.log(data); + $.getJSON(posturl, function(data) { + earningsdollar = data.account.available_earnings; /*- 3 payoneer commision $3*/ + finalearnings = earningsdollar * convertrate; + if (currency == 'INR') { + currency_sign = '₹'; + } else if (currency == 'EUR') { + currency_sign = '€'; + } else if (currency == 'GBP') { + currency_sign = '£'; } else { - dollartToInr(); + currency_sign = currency; } - } - if(cache_currency_rate != 'false') { - var exchange_rate = currency_rate.split('||') || 1; - - var last_cached_time = exchange_rate[0]; - var last_exchange_rate = exchange_rate[1]; - var current_timestamp = Math.floor(Date.now() / 1000); - var day_ago_time = current_timestamp - 86400; - - if(exchange_rate[2] != currency || last_cached_time < day_ago_time) { - // Fetch latest currency rate - var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange; - $.getJSON(conversionurl, function(data) { - save_option('currency_rate', current_timestamp+'||'+data.rates[currency]+'||'+currency); - }); + if (currency == 'INR') { + $('.header-logo-account__balance').text(currency_sign + ' ' + inr_currency(finalearnings.toFixed(2))).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + } else { + $('.header-logo-account__balance').text(currency_sign + ' ' + format_currency(finalearnings)).parent().attr('title', 'Actual Earnings: $' + earningsdollar); } - } + }); }); +} -//function for converting string into indian currency format - function inr_currency(nStr) { - nStr += ''; - x = nStr.split('.'); - x1 = x[0]; - x2 = x.length > 1 ? '.' + x[1] : ''; - var rgx = /(\d+)(\d{3})/; - var z = 0; - var len = String(x1).length; - var num = parseInt((len / 2) - 1); - - while (rgx.test(x1)) { - if (z > 0) { - x1 = x1.replace(rgx, '$1' + ',' + '$2'); +function convertPrice(unconverted_price, handleData) { + var conversion_rate, converted_price; + if ($.type(unconverted_price) === 'string') { + unconverted_price = unconverted_price.replace(/[^0-9\.]/g, ''); + } + $.ajax({ + url: 'https://openexchangerates.org/api/latest.json?app_id=' + openexchange, + success: function(data) { + conversion_rate = data.rates[currency]; + if (currency == 'INR') { + currency_sign = '₹'; + } else if (currency == 'EUR') { + currency_sign = '€'; + } else if (currency == 'GBP') { + currency_sign = '£'; } else { - x1 = x1.replace(rgx, '$1' + ',' + '$2'); - rgx = /(\d+)(\d{2})/; + currency_sign = currency; } - z++; - num--; - if (num == 0) { - break; + converted_price = unconverted_price * conversion_rate; + if (currency == 'INR') { + converted_price = currency_sign + ' ' + inr_currency(converted_price.toFixed(2)); + } else { + converted_price = currency_sign + ' ' + format_currency(converted_price); } + handleData(converted_price); } - return x1 + x2; - } - -// GLOBAL CURRENCY FORMAT - function format_currency(n) { - return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"); - } - - function dollartToInr() { - var posturl = 'http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json'; - var earningsdollar, finalearnings, convertrate; - - var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange; - - // Use jQuery.ajax to get the latest exchange rates, with JSONP: - if(cache_currency_rate == 'false') { - $.getJSON(conversionurl, function (data) { - convertrate = data.rates[currency]; - /* * 0.975 Midmarket rate*/ - - //console.log(data); - - $.getJSON(posturl, function (data) { - earningsdollar = data.account.available_earnings; - /*- 3 payoneer commision $3*/ - finalearnings = earningsdollar * convertrate; - - if (currency == 'INR') { - currency_sign = '₹'; - } else if (currency == 'EUR') { - currency_sign = '€'; - } else if (currency == 'GBP') { - currency_sign = '£'; - } else { - currency_sign = currency; - } - - if (currency == 'INR') { - $('.header-logo-account__balance').text(currency_sign + ' ' + inr_currency(finalearnings.toFixed(2))).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + }); +} +$(document).ready(function() { + // REMOVE STATEMENTS - AUTHOR FEE + // CONVERT CURRENCIES + // TODO : SUPPORT PACKS LAUNCHED NEED RE_WORK + /* if (hide_statement != 'false') { + var pathname = window.location.pathname; + var amount = 0; + var amount_string = ''; + var order_id = 0; + var next_amount = ''; + + var unconverted, converted, current_object = [], conversion_rate; + + if (pathname.indexOf('statement') > -1) { + $("#stored_statement").find("tr").each(function(i) { + + if ($(this).find("td").eq(3).find("span").text() == "Author Fee") { + + order_id = $(this).find('.statement__order_id').text(); + amount_string = $(this).find('.statement__amount').text(); + amount = parseFloat(amount_string.substring(1, amount_string.length)); + next_amount = $(this).next().find('.statement__amount').text(); + next_amount = parseFloat(next_amount.substring(1, next_amount.length)); + + amount = amount + next_amount; + + $(this).next().find('.statement__amount').text('$' + amount.toFixed(2)); + $(this).hide(); + } + + if(localise_earnings_table != 'false') { + if (openexchange == 'undefined') { + return false; + } else { + if ($(this).is(':visible')) { + current_object[i] = $(this); + + if (current_object[i].find('td').eq(7).text() != '') { + unconverted = current_object[i].find('td').eq(7).text(); + unconverted = parseFloat(unconverted.substring(1, unconverted.length)); + + converted = convertPrice(unconverted, function(data){ + current_object[i].find('td').eq(7).text(data).attr('title', 'Actual Earnings: $' + unconverted); + }); + } + if (current_object[i].find('td').eq(8).text() != '') { + unconverted = current_object[i].find('td').eq(8).text(); + unconverted = unconverted.substring(1, unconverted.length); + converted = convertPrice(unconverted, function(data){ + current_object[i].find('td').eq(8).text(data).attr('title', 'Actual Earnings: $' + unconverted); + }); + } + } + } + } + }); + } + } */ + // CONVERT CURRENCIES IN EARNINGS TAB + if (localise_earnings_page != 'false') { + var pathname = window.location.pathname; + if (pathname.indexOf('/earnings/') > -1) { + // Generate new graph + var graph_data = $.parseJSON($('body script[id="graphdata"]').text()); + var current_object, unconverted, converted, data_indexes, counter; + counter = 0; + data_indexes = graph_data.datasets[0]['data'].length; + $.each(graph_data.datasets[0]['data'], function(i, val) { + if (val > 0) { + // Localize + if (openexchange == 'undefined') { + return false; } else { - $('.header-logo-account__balance').text(currency_sign + ' ' + format_currency(finalearnings)).parent().attr('title', 'Actual Earnings: $' + earningsdollar); + current_object = $(this); + unconverted = parseFloat(val); + converted = convertPrice(unconverted, function(data) { + if (parseFloat(data.replace(/[^0-9\.]/g, '')) > 0) { + graph_data.datasets[0]['data'][i] = parseFloat(data.replace(/[^0-9\.]/g, '')); + counter++; + } + }); } - - }); + } else { + counter++; + } }); - } else { - var exchange_rate = currency_rate.split('||') || 1; - - var last_cached_time = exchange_rate[0]; - var last_exchange_rate = exchange_rate[1]; - var current_timestamp = Math.floor(Date.now() / 1000); - var day_ago_time = current_timestamp - 86400; - - if(exchange_rate[2] != currency || last_cached_time < day_ago_time) { - // Fetch latest currency rate - var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange; - $.getJSON(conversionurl, function(data) { - save_option('currency_rate', current_timestamp+'||'+data.rates[currency]+'||'+currency); - - $.getJSON(posturl, function (data) { - earningsdollar = data.account.available_earnings; - /*- 3 payoneer commision $3*/ - finalearnings = earningsdollar * data.rates[currency]; - - if (currency == 'INR') { - currency_sign = '₹'; - } else if (currency == 'EUR') { - currency_sign = '€'; - } else if (currency == 'GBP') { - currency_sign = '£'; - } else { - currency_sign = currency; - } - - if (currency == 'INR') { - $('.header-logo-account__balance').text(currency_sign + ' ' + inr_currency(finalearnings.toFixed(2))).parent().attr('title', 'Actual Earnings: $' + earningsdollar); - } else { - $('.header-logo-account__balance').text(currency_sign + ' ' + format_currency(finalearnings)).parent().attr('title', 'Actual Earnings: $' + earningsdollar); - } - + var renderGraph = setInterval(function() { + if (data_indexes == counter) { + $('.-sales').text('Sales Earnings (' + currency + ')'); + var chart_data = { + animationEasing: "easeInOutCirc", + animationSteps: 60, + scaleFontSize: 12, + scaleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", + scaleLabel: "<%=parseFloat(value).toLocaleString('en-EN', {style: 'currency', currency: '" + currency + "', minimumFractionDigits: 2})%>", + scaleStartValue: 0, + showTooltips: !1, + bezierCurve: !1 + }; + $(".js-graph__canvas").remove(); + $('.graph__container').append(''); + var canvas = $(".graph__canvas").get(0).getContext('2d'); + new Chart(canvas).Line(graph_data, chart_data); + clearInterval(renderGraph); + } + }, 100); + // Convert headers (This month, balance, total value) + convertPrice($('.earnings-widget__amount:eq(0)').text().substr(1), function(data) { + $('.earnings-widget__amount:eq(0)').text(data); + }); + convertPrice($('.earnings-widget__amount:eq(1)').text().substr(1), function(data) { + $('.earnings-widget__amount:eq(1)').text(data); + }); + convertPrice($('.earnings-widget__amount:eq(2)').text().substr(1), function(data) { + $('.earnings-widget__amount:eq(2)').text(data); + }); + // Reduce font size to avoid design breakage in local currency + $('.earnings-widget__amount').css('font-size', '30px'); + // Convert prices in table + if (pathname.indexOf('/earnings/sales') > -1) { + $('.table-general tbody, tfoot').find('tr').each(function(index) { + current_object[index] = $(this); + convertPrice($(this).find('td').eq(2).text().substr(1), function(data) { + current_object[index].find('td').eq(2).text(data); }); }); - } else { - $.getJSON(posturl, function (data) { - earningsdollar = data.account.available_earnings; - /*- 3 payoneer commision $3*/ - finalearnings = earningsdollar * currency_rate.split('||')[1]; - - if (currency == 'INR') { - currency_sign = '₹'; - } else if (currency == 'EUR') { - currency_sign = '€'; - } else if (currency == 'GBP') { - currency_sign = '£'; - } else { - currency_sign = currency; - } - - if (currency == 'INR') { - $('.header-logo-account__balance').text(currency_sign + ' ' + inr_currency(finalearnings.toFixed(2))).parent().attr('title', 'Actual Earnings: $' + earningsdollar); - } else { - $('.header-logo-account__balance').text(currency_sign + ' ' + format_currency(finalearnings)).parent().attr('title', 'Actual Earnings: $' + earningsdollar); - } - + } else if (pathname.indexOf('/earnings/referrals') > -1) { + $('.table-general tbody, tfoot').find('tr').each(function(index) { + current_object[index] = $(this); + convertPrice($(this).find('td').eq(4).text().substr(1), function(data) { + current_object[index].find('td').eq(4).text(data); + }); + convertPrice($(this).find('td').eq(5).text().substr(1), function(data) { + current_object[index].find('td').eq(5).text(data); + }); }); } } } - - function convertPrice(unconverted_price, handleData) { - var conversion_rate, converted_price; - - if($.type(unconverted_price) === 'string') { - unconverted_price = unconverted_price.replace(/[^0-9\.]/g, ''); - } - - if(cache_currency_rate == 'false') { - $.ajax({ - url: 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange, - success: function (data) { - - conversion_rate = data.rates[currency]; - - if (currency == 'INR') { - currency_sign = '₹'; - } else if (currency == 'EUR') { - currency_sign = '€'; - } else if (currency == 'GBP') { - currency_sign = '£'; - } else { - currency_sign = currency; - } - - converted_price = unconverted_price * conversion_rate; - - if (currency == 'INR') { - converted_price = currency_sign + ' ' + inr_currency(converted_price.toFixed(2)); - } else { - converted_price = currency_sign + ' ' + format_currency(converted_price); - } - - handleData(converted_price); + // SHOW LINKS IN REFERRALS PAGE + if (create_hrefs != 'false') { + var pathname = window.location.pathname; + if (pathname.indexOf('/referrals') > -1) { + var source = ''; + var path = ''; + var url = ''; + var ifTableExists = setInterval(function() { + if ($('#results').length) { + clearInterval(ifTableExists); + $('#results').find('tr').each(function() { + if ($(this).find('td').eq(1).text() != '(not set)') { + source = $(this).find('td').eq(0).text(); + path = $(this).find('td').eq(1).text(); + url = '' + path + ''; + $(this).find('td').eq(1).html(url); + } + }); } - }); + }, 100); + } + } + // VERIFY PURCHASE + if (verify_purchase == 'true') { + var pathname = window.location.pathname; + if (pathname.indexOf('author_dashboard') > -1) { + var verify_html_block = '

Verify Purchase Code Better Envato

'; + //$("#content .content-s").append(verify_html_block); + $(verify_html_block).insertBefore("#content .content-s .content-s"); + //alert('done'); + } + } + $("#verifypurchase").submit(function(e) { + e.preventDefault(); + var purchase_code = $("#purchase_code"); + var flag = false; + if (purchase_code.val() == "") { + purchase_code.focus(); + flag = false; + return false; } else { - var exchange_rate = currency_rate.split('||') || 1; - - var last_cached_time = exchange_rate[0]; - var last_exchange_rate = exchange_rate[1]; - var current_timestamp = Math.floor(Date.now() / 1000); - var day_ago_time = current_timestamp - 86400; - - if(exchange_rate[2] != currency || last_cached_time < day_ago_time) { - // Fetch latest currency rate - var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + openexchange; - $.getJSON(conversionurl, function(data) { - save_option('currency_rate', current_timestamp+'||'+data.rates[currency]+'||'+currency); - - if (currency == 'INR') { - currency_sign = '₹'; - } else if (currency == 'EUR') { - currency_sign = '€'; - } else if (currency == 'GBP') { - currency_sign = '£'; - } else { - currency_sign = currency; - } - - converted_price = unconverted_price * currency_rate.split('||')[1]; - - if (currency == 'INR') { - converted_price = currency_sign + ' ' + inr_currency(converted_price.toFixed(2)); - } else { - converted_price = currency_sign + ' ' + format_currency(converted_price); - } - - handleData(converted_price); - }); - } else { - if (currency == 'INR') { - currency_sign = '₹'; - } else if (currency == 'EUR') { - currency_sign = '€'; - } else if (currency == 'GBP') { - currency_sign = '£'; - } else { - currency_sign = currency; - } - - converted_price = unconverted_price * currency_rate.split('||')[1]; - - if (currency == 'INR') { - converted_price = currency_sign + ' ' + inr_currency(converted_price.toFixed(2)); + flag = true; + } + var item_purchase_code = purchase_code.val(); + $(".loading").fadeIn("slow").html("

Please wait...

"); + var posturl = 'https://marketplace.envato.com/api/v3/' + username + '/' + apikey + '/verify-purchase:' + item_purchase_code + '.json'; + $.ajax({ + type: 'GET', + url: posturl, + data: { + get_param: 'value' + }, + dataType: 'json', + success: function(data) { + if (data['verify-purchase'].buyer == '' || data['verify-purchase'].buyer == null) { + $('.loading').fadeIn('slow').html('

Sorry. That was a wrong verification code!

'); + } else if (data.code == 'not_authenticated') { + $('.loading').fadeIn('slow').html('

Sorry. Username and/or API Key is invalid.

'); } else { - converted_price = currency_sign + ' ' + format_currency(converted_price); + var buyer = data['verify-purchase'].buyer; + var item_name = data['verify-purchase'].item_name; + var licence = data['verify-purchase'].licence; + var timestamp = data['verify-purchase'].created_at; + $('.loading').fadeIn('slow').html('

' + buyer + ' purchased a ' + licence + ' of ' + item_name + ' ' + $.timeago(timestamp) + '

'); } - - handleData(converted_price); + }, + error: function(data) { + $('.loading').fadeIn('slow').html('

Sorry. Something went wrong!

'); } - } + }); + }); + // Hide Author Earnings + // Author is browsing in public and do not want to reveal his balance + if (hide_earnings == 'true') { + $('.header-logo-account__balance').hide(); } - - $(document).ready(function() { - - // REMOVE STATEMENTS - AUTHOR FEE - // CONVERT CURRENCIES - - if (hide_statement != 'false') { - var pathname = window.location.pathname; - var amount = 0; - var amount_string = ''; - var order_id = 0; - var next_amount = ''; - - var unconverted, converted, current_object = [], conversion_rate; - - if (pathname.indexOf('statement') > -1) { - $("#stored_statement").find("tr").each(function(i) { - - if ($(this).find("td").eq(3).find("span").text() == "Author Fee") { - - order_id = $(this).find('.statement__order_id').text(); - amount_string = $(this).find('.statement__amount').text(); - amount = parseFloat(amount_string.substring(1, amount_string.length)); - next_amount = $(this).next().find('.statement__amount').text(); - next_amount = parseFloat(next_amount.substring(1, next_amount.length)); - - amount = amount + next_amount; - - $(this).next().find('.statement__amount').text('$' + amount.toFixed(2)); - $(this).hide(); - } - - if(localise_earnings_table != 'false') { - if (openexchange == 'undefined') { - return false; - } else { - if ($(this).is(':visible')) { - current_object[i] = $(this); - - if (current_object[i].find('td').eq(7).text() != '') { - unconverted = current_object[i].find('td').eq(7).text(); - unconverted = parseFloat(unconverted.substring(1, unconverted.length)); - - converted = convertPrice(unconverted, function(data){ - current_object[i].find('td').eq(7).text(data).attr('title', 'Actual Earnings: $' + unconverted); - }); - } - if (current_object[i].find('td').eq(8).text() != '') { - unconverted = current_object[i].find('td').eq(8).text(); - unconverted = unconverted.substring(1, unconverted.length); - converted = convertPrice(unconverted, function(data){ - current_object[i].find('td').eq(8).text(data).attr('title', 'Actual Earnings: $' + unconverted); - }); - } - } - } + /* OLD FORUM LOOK */ + if (old_forum_look == 'true') { + var pathname = window.location.href; + if (pathname.indexOf('forums.envato') > -1) { + // insert styles from manifest :) + // DomChange Function + var observeDOM = (function() { + var MutationObserver = window.MutationObserver || window.WebKitMutationObserver, + eventListenerSupported = window.addEventListener; + return function(obj, callback) { + if (MutationObserver) { + // define a new observer + var obs = new MutationObserver(function(mutations, observer) { + if (mutations[0].addedNodes.length || mutations[0].removedNodes.length) + callback(); + }); + // have the observer observe foo for changes in children + obs.observe(obj, { + childList: true, + subtree: true + }); + } else if (eventListenerSupported) { + obj.addEventListener('DOMNodeInserted', callback, false); + obj.addEventListener('DOMNodeRemoved', callback, false); } - }); + } + })(); + // Cut URL Part + function cutUrl(str) { + var matched = str.match(/([^/]*\/){4}/); + return matched ? matched[0] : str /* or null if you wish */ ; + } + var poster_avatar, + poster_avatar_big, + last_reply_avatar, + last_reply_avatar_med, + started_by_name, + last_reply_name, + started_by_url, + last_reply_url; + //$('.topic-list thead tr').prepend('Avatar') + function showAvatars(thisObj) { + poster_avatar = $('.posters a:first-child img', thisObj).attr('src'); + poster_avatar_big = poster_avatar.replace("25", "80"); + last_reply_avatar = $('.posters .latest img', thisObj).attr('src'); + last_reply_avatar_mid = last_reply_avatar.replace("25", "40"); + started_by_name = $('.posters a:first-child', thisObj).data('user-card'); + last_reply_name = $('.posters .latest', thisObj).data('user-card'); + started_by_url = cutUrl($('.main-link .title', thisObj).attr('href')); + last_reply_url = $('.activity a', thisObj).attr('href'); + $('.main-link', thisObj).prepend('
'); + if ($(".topic-post-badges", thisObj).length) { + $(".main-link .topic-post-badges", thisObj).after(''); + } else { + $(".main-link .title", thisObj).after(''); + } + $('.thread-quick-links', thisObj).append('
Started by ' + started_by_name + '
Last reply by ' + last_reply_name + '
') + $('.topic-list-item').addClass('old-forum-loaded'); } - } - - // CONVERT CURRENCIES IN EARNINGS TAB - if(localise_earnings_page != 'false') { - var pathname = window.location.pathname; - if(pathname.indexOf('/earnings/') > -1) { - - // Generate new graph - var graph_data = $.parseJSON($('body script[id="graphdata"]').text()); - var current_object, unconverted, converted, data_indexes, counter; - counter = 0; - data_indexes = graph_data.datasets[0]['data'].length; - - $.each(graph_data.datasets[0]['data'], function(i, val){ - if(val > 0) { - // Localize - if (openexchange == 'undefined') { - return false; - } else { - current_object = $(this); - unconverted = parseFloat(val); - converted = convertPrice(unconverted, function (data) { - if (parseFloat(data.replace(/[^0-9\.]/g, '')) > 0) { - graph_data.datasets[0]['data'][i] = parseFloat(data.replace(/[^0-9\.]/g, '')); - counter++; - } - }); - } - } else { - counter++; - } + function hideCustomTags(thisObj) { + var foundtags = []; + $('.discourse-tag', thisObj).each(function() { + foundtags.push($(this).text()); }); - - var renderGraph = setInterval(function(){ - if(data_indexes == counter) { - $('.-sales').text('Sales Earnings ('+currency+')'); - - var chart_data = { - animationEasing: "easeInOutCirc", - animationSteps: 60, - scaleFontSize: 12, - scaleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", - scaleLabel: "<%=parseFloat(value).toLocaleString('en-EN', {style: 'currency', currency: '"+currency+"', minimumFractionDigits: 2})%>", - scaleStartValue: 0, - showTooltips: !1, - bezierCurve: !1 - }; - - $(".js-graph__canvas").remove(); - $('.graph__container').append(''); - - var canvas = $(".graph__canvas").get(0).getContext('2d'); - new Chart(canvas).Line(graph_data, chart_data); - - clearInterval(renderGraph); + for (var i = 0; i < foundtags.length; i++) { + if (forum_blacklist.indexOf(foundtags[i]) > -1) { + thisObj.hide(); } - }, 100); - - // Convert headers (This month, balance, total value) - convertPrice($('.earnings-widget__amount:eq(0)').text().substr(1), function(data){ - $('.earnings-widget__amount:eq(0)').text(data); - }); - convertPrice($('.earnings-widget__amount:eq(1)').text().substr(1), function(data){ - $('.earnings-widget__amount:eq(1)').text(data); - }); - convertPrice($('.earnings-widget__amount:eq(2)').text().substr(1), function(data){ - $('.earnings-widget__amount:eq(2)').text(data); - }); - // Reduce font size to avoid design breakage in local currency - $('.earnings-widget__amount').css('font-size','30px'); - - // Convert prices in table - if(pathname.indexOf('/earnings/sales') > -1) { - $('.table-general tbody, tfoot').find('tr').each(function(index){ - current_object[index] = $(this); - convertPrice($(this).find('td').eq(2).text().substr(1), function(data){ - current_object[index].find('td').eq(2).text(data); - }); - }); - } else if(pathname.indexOf('/earnings/referrals') > -1) { - $('.table-general tbody, tfoot').find('tr').each(function(index){ - current_object[index] = $(this); - convertPrice($(this).find('td').eq(4).text().substr(1), function(data){ - current_object[index].find('td').eq(4).text(data); - }); - convertPrice($(this).find('td').eq(5).text().substr(1), function(data){ - current_object[index].find('td').eq(5).text(data); - }); - }); } - } - } - - // SHOW LINKS IN REFERRALS PAGE - if(create_hrefs != 'false') { - var pathname = window.location.pathname; - if (pathname.indexOf('/referrals') > -1) { - var source = ''; - var path = ''; - var url = ''; - - var ifTableExists = setInterval(function () { - if ($('#results').length) { - clearInterval(ifTableExists); - $('#results').find('tr').each(function () { - if ($(this).find('td').eq(1).text() != '(not set)') { - source = $(this).find('td').eq(0).text(); - path = $(this).find('td').eq(1).text(); - - url = '' + path + ''; - - $(this).find('td').eq(1).html(url); - } - }); + for (var g = 0; g < foundtags.length; g++) { + if (forum_whitelist.indexOf(foundtags[g]) > -1) { + thisObj.show(); } - }, 100); + } } - } - - // VERIFY PURCHASE - - if (verify_purchase != 'false') { + $('.topic-list-item').each(function() { + showAvatars($(this)); + }); + observeDOM(document.getElementById('main-outlet'), function() { + setTimeout(function() { + $('.topic-list-item').not('.old-forum-loaded').each(function() { + showAvatars($(this)); + }); + }, 1000) + }); + /*if (hide_forum_posts == 'true') { + $('.topic-list-item').each(function() { + hideCustomTags($(this)); + }); + observeDOM(document.getElementById('list-area'), function() { + setTimeout(function() { + $('.topic-list-item').each(function() { + hideCustomTags($(this)); + }); + }, 1000) + }); + }*/ + } /*end pathname fn*/ + } /*end if ole forum*/ + /* + * + * Auto Close Item Preview Frame + * + */ + if (close_iframe_preview == 'true') { + //do this + checkPreviewURL(); + + function checkPreviewURL() { var pathname = window.location.pathname; - if (pathname.indexOf('author_dashboard') > -1) { - var verify_html_block = '

Verify Purchase Code

'; - - //$("#content .content-s").append(verify_html_block); - $(verify_html_block).insertBefore("#content .content-s .content-s"); - //alert('done'); + if (pathname.indexOf('/full_screen_preview/') > -1) { + var originalpath = $('body > iframe').attr('src'); + removeiframe(originalpath); } } - - - $("#verifypurchase").submit(function(e) { - e.preventDefault(); - var purchase_code = $("#purchase_code"); - var flag = false; - if (purchase_code.val() == "") { - purchase_code.focus(); - flag = false; - return false; - } else { - flag = true; - } - var item_purchase_code = purchase_code.val(); - $(".loading").fadeIn("slow").html("

Please wait...

"); - - var posturl = 'http://marketplace.envato.com/api/v3/' + username + '/' + apikey + '/verify-purchase:' + item_purchase_code + '.json'; - - $.ajax({ - type: 'GET', - url: posturl, - data: { - get_param: 'value' - }, - dataType: 'json', - success: function(data) { - - if (data['verify-purchase'].buyer == '' || data['verify-purchase'].buyer == null) { - - - $('.loading').fadeIn('slow').html('

Sorry. That was a wrong verification code!

'); - - } else if (data.code == 'not_authenticated') { - $('.loading').fadeIn('slow').html('

Sorry. Username and/or API Key is invalid.

'); - } else { - - var buyer = data['verify-purchase'].buyer; - var item_name = data['verify-purchase'].item_name; - var licence = data['verify-purchase'].licence; - var timestamp = data['verify-purchase'].created_at; - - $('.loading').fadeIn('slow').html('

' + buyer + ' purchased a ' + licence + ' of ' + item_name + ' ' + $.timeago(timestamp) + '

'); - - - } - - }, - - error: function(data) { - $('.loading').fadeIn('slow').html('

Sorry. Something went wrong!

'); - } - - }); - - }); - -// Hide Author Earnings -// Author is browsing in public and do not want to reveal his balance - - if (hide_earnings == 'true') { - $('.header-logo-account__balance').hide(); + function removeiframe(originalpath) { + top.location.replace(originalpath); } - - }); /*End Document Ready*/ - - var current_url = window.location.pathname; - - $(document).click(function() { - if(window.location.pathname.indexOf('/earnings/') > -1) { - if (current_url != window.location.pathname) { - location.reload(); - } + } +}); /*End Document Ready*/ +var current_url = window.location.pathname; +$(document).click(function() { + if (window.location.pathname.indexOf('/earnings/') > -1) { + if (current_url != window.location.pathname) { + location.reload(); } - }); -}); \ No newline at end of file + } +}); diff --git a/css/forums.css b/css/forums.css new file mode 100644 index 0000000..eae592c --- /dev/null +++ b/css/forums.css @@ -0,0 +1,169 @@ +/* + * + * ENVATO FORUM CUSTOMIZATION + * BY SURJITH S M (surjithctly) + * + */ + + +/* + * + * GLOBAL PAGE + * + */ + +.d-header { + background-color: #f4f4f4; +} + + +/* + * + * HOME PAGE + * + */ + +.topic-list { + background-color: #fbfbfb; + border: 1px solid #e1e8ed; +} + +.list-controls { + margin-bottom: 10px; +} + +.topic-list:not(.categories) > tbody > tr:nth-child(even) td:first-child { + border-left: 0; +} + +.topic-list:not(.categories) > tbody > tr:nth-child(even) td:last-child { + border-right: 0; +} + +.topic-list td { + padding: 20px 5px; +} + +.topic-list th:first-of-type, +.topic-list td:first-of-type { + padding-left: 20px; +} + +.topic-list:not(.categories) > tbody > tr:nth-child(even) td { + background-color: #fbfbfb; +} + +.old-forum-loaded .discourse-tags, +.thread-quick-links { + margin-left: 110px; +} + +.topic-list .main-link { + box-sizing: border-box; + color: rgb(68, 68, 68); + text-align: left; + text-decoration: none; + border: 0px none rgb(68, 68, 68); + font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; + font-size: 24px; + line-height: 28px; + list-style: none outside none; + outline: rgb(68, 68, 68) none 0px; + vertical-align: top; +} + +.topic-list .main-link .title { + font-size: 24px; +} + + +/*#A_1*/ + +.topic-list .topic-excerpt, +.topic-list .views, +.topic-list .posters { + display: none; +} + + +/* .topic-list .category */ + +.topic-list .posts { + width: 80px; +} + +.topic-list .posts-map.badge-posts { + font-size: 24px; + background: #ECECEC; + border-radius: 4px; + display: block; + margin-top: 5px; + padding: 10px 0 25px!important; + position: relative; + width: 80px; +} + +.topic-list .posts-map.badge-posts:after { + content: 'Replies'; + position: absolute; + bottom: 8px; + left: 0; + right: auto; + text-transform: uppercase; + font-size: 11px; + font-weight: normal; + width: 80px; +} + +.thread_thumbs { + float: left; + position: relative; + width: 90px; + height: 90px; + margin-right: 20px; +} + +.thread-last-reply { + position: absolute; + right: 0; + bottom: 0; +} + +.topic-list .badge-notification.new-topic { + font-size: 14px; +} + +.thread-quick-links { + font-size: 12px; + margin-top: 10px; + margin-bottom: 5px; +} + +.thread-quick-links div { + line-height: 1.7; +} + +.show-more.has-topics { + top: 0; +} + +.show-more.has-topics .alert { + padding: 13px 35px 12px 14px; +} + + +/* + * + * TOPIC PAGE + * + */ + +.topic-body { + font-size: 16px; + line-height: 24px; +} + +.topic-post .topic-avatar img { + border-radius: 0; +} + diff --git a/css/options.css b/css/options.css index 7b0f51b..34686fd 100644 --- a/css/options.css +++ b/css/options.css @@ -1,35 +1,47 @@ /*Options Page*/ body { - background:#eee; - font-family:Arial, Helvetica, Sans-serif; - font-size:14px; - color:#3D3D3D; + background: #eee; + font-family: Arial, Helvetica, Sans-serif; + font-size: 14px; + color: #3D3D3D; + line-height: 1.5; } .settings { - background:#FFF; - margin:50px auto; - padding:30px; - max-width:800px; + background: #FFF; + margin: 50px auto; + padding: 30px; + max-width: 800px; } h1 { - text-align:center; - color:#313131; + text-align: center; + color: #313131; +} + +h2 { + text-align: center; + color: #545454; + background: #F6F6F6; + border-bottom: 1px solid #EBEBEB; + padding: 10px 0; + margin-top: 30px; + margin-bottom: 25px; + font-size: 16px; } p { - color:#707070; + color: #707070; } a { - color:#53A2EC; - text-decoration:none; + color: #53A2EC; + text-decoration: none; } a:hover { - color:#2473BD; + color: #2473BD; } hr { @@ -43,37 +55,39 @@ hr { } #options-area { - margin-top:50px; + margin-top: 50px; } .text-center { - text-align:center; + text-align: center; } .control-group { - margin-bottom:20px; + margin-bottom: 20px; } .control-label { - float:left; - margin:7px; + float: left; + margin: 7px; } .help-block { - font-size:12px; + font-size: 12px; } .controls { - margin-left:250px; + margin-left: 250px; } -.controls input[type=text], .controls select { - padding:5px 10px; - border:solid 1px #CCC; - width:300px; +.controls input[type=text], +.controls select { + padding: 5px 10px; + border: solid 1px #CCC; + width: 300px; } -select[disabled], input[disabled] { +select[disabled], +input[disabled] { cursor: not-allowed; background-color: #eee; opacity: 1; @@ -98,27 +112,35 @@ select[disabled], input[disabled] { border: 1px solid transparent; border-radius: 4px; color: #939393; - -webkit-transition:all .1s linear; - transition:all .1s linear; - outline:none; + -webkit-transition: all .1s linear; + transition: all .1s linear; + outline: none; } .btn-success { background-color: #2cc76a; background-image: none; border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); - color:#FFF; + color: #FFF; } - - - .highlight { background: #f5e9a3; padding: 1em 1.5em; -webkit-transition: background .1s linear; transition: background .1s linear; } + .highlight.love { background: #f5a3cc; } + +.badge { + font-size: 10px; + font-weight: normal; + color: #FFF; + padding: 2px 6px; + background-color: #F97171; + border-radius: 3px; +} + diff --git a/manifest.json b/manifest.json index 4d3c330..2a7f058 100644 --- a/manifest.json +++ b/manifest.json @@ -1,50 +1,35 @@ { - "content_scripts":[ - { - "js":[ - "js/jquery.min.js", - "js/plugins.js", - "js/Chart.min.js", - "better-envato.js" - ], - "css":[ - "css/envato-styles.css" - ], - "matches":[ - "*://*.themeforest.net/*", - "*://*.codecanyon.net/*", - "*://*.videohive.net/*", - "*://*.audiojungle.net/*", - "*://*.graphicriver.net/*", - "*://*.photodune.net/*", - "*://*.3docean.net/*", - "*://*.activeden.net/*", - "*://*.envato.com/*" - ] - } - ], - "browser_action":{ - "name":"Better Envato" - }, - "background":{ - "page":"background.html" - }, - "description":"Make Envato better by adding some cool features", - "icons":{ - "128":"img/128.png", - "16":"img/16.png", - "48":"img/48.png" - }, - "manifest_version":2, - "name":"Better Envato", - "short_name":"Better Envato", - "options_page":"options.html", - "permissions":[ - "storage", - "webRequest", - "notifications", - "background" - ], - "update_url":"http://clients2.google.com/service/update2/crx", - "version":"1.2.5" -} \ No newline at end of file + "content_scripts": [ { + "js": [ "js/jquery.min.js", "js/plugins.js", "js/Chart.min.js", "better-envato.js" ], + "css": ["css/envato-styles.css"], + "matches": [ "*://*.themeforest.net/*", "*://*.codecanyon.net/*", "*://*.videohive.net/*", "*://*.audiojungle.net/*", "*://*.graphicriver.net/*", "*://*.photodune.net/*", "*://*.3docean.net/*", "*://*.activeden.net/*", "*://forums.envato.com/*" ] + + }, +{ + "css": ["css/forums.css"], +"matches": ["*://forums.envato.com/*" ], +"run_at": "document_start" +} + + ], +"web_accessible_resources": ["css/forums.css"], +"browser_action": { + "name": "Better Envato" + }, +"background": { + "page": "background.html" + }, + "description": "Make Envato better by adding some cool features", + "icons": { + "128": "img/128.png", + "16": "img/16.png", + "48": "img/48.png" + }, + "manifest_version": 2, + "name": "Better Envato", + "short_name": "Better Envato", + "options_page": "options.html", + "permissions": [ "tabs", "webRequest", "notifications", "background" ], + "update_url": "http://clients2.google.com/service/update2/crx", + "version": "1.2.6" +} diff --git a/options.html b/options.html index 8eaa5b5..674d628 100644 --- a/options.html +++ b/options.html @@ -1,346 +1,394 @@ + Better Envato Options + +
+

Better Envato

+

Make Envato Better by adding some cool features. +
Made with ♥ by Surjith S M

-
-

Better Envato Options

+
+
+
+
-
+

Extension Settings

-
-
-
-
- -
- -
-
-
- -
- -
-
-
-
- -
-
- -
-
- -
-
- +
+ +
+
-
-
-
- -
-
- +
+ +
+
-
- +
+ +

Desktop Notifications

+
+ +
+
+ +
+
+ +
+
+ +
-
- +
+
+
+ +
+
+ +
+
+ +
+
+ +
-
-
-
- -
-
- + +

Localize Earnings

+
+ +
+
+ +
+
+ +
+
+ +
+

Please Fill below details to localize earnings

-
- +
+
+ +
+ +

Signup free to get API Key from Open Exchange rate

-
- +
+
+ +
+
-

Please Fill below details to localize earnings

-
-
- -
- -

Signup free to get API Key from Open Exchange rate

+ +

Forums NEW

+ +
+ +
+
+ + ( See Preview )
+ +
-
-
- -
- -
- + + + +

Item Pages NEW

+ +
+ +
+
+ +
-
-
-
- -
-
- + +

Other Features

+ +
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
+
-
-
-
- +
+ +
-
-

Made with ♥ by Surjith S M (Envato Portfolio).
- Fork on Github | Found an issue? | Credits : Envato API | Contributors: Žan Gerden

-
- - - +

Made with ♥ by Surjith S M (Envato Portfolio). +
Fork on Github | Found an issue? | Credits : Envato API | Contributors: Zan Gerden

+
+ + + - \ No newline at end of file + + diff --git a/options.js b/options.js index 6bb2f06..824ffd4 100644 --- a/options.js +++ b/options.js @@ -5,167 +5,109 @@ function init_options() { // console.log("function: init_options"); - var current_object = []; - //load currently stored options configuration var $inputs = $('#options-area :input'); $inputs.each(function() { - current_object[$(this).attr('name')] = $(this); - - get_option($(this).attr('name'), function(value, name) { - current_object[name].val(value); - }); + if (typeof localStorage[this.name] != 'undefined') { + $(this).val(localStorage[this.name]); + } }); var $checkboxes = $('#options-area :input[type=checkbox]'); $checkboxes.each(function() { - current_object[$(this).attr('name')] = $(this); - - get_option($(this).attr('name'), function(value, name){ - if(value == 'false') { - current_object[name].attr('checked', false); - } else if (value == 'true') { - current_object[name].attr('checked', true); - } - }); + if (localStorage[this.name] == 'false') { + //alert(localStorage[this.name]) + $(this).attr('checked', false); + } else if (localStorage[this.name] == 'true') { + $(this).attr('checked', true); + } }); - get_option('currency', function(value, name){ - $('select[name='+name+']').select(value); - }); } function save_options() { // console.log("function: save_options"); - chrome.storage.sync.clear(); $("input[type=text],select,textarea").each(function() { - var name = $(this).attr('name'); - var value = $(this).val(); - - save_option(name, value); + localStorage[$(this).attr("name")] = $(this).val(); }); $("input[type=checkbox]").each(function() { - var name = $(this).attr('name'); - var value = $(this).prop('checked').toString(); - - save_option(name, value); - - if(name == 'cache_currency_rate') { - // Fetch latest currency rate - get_option('openexchange', function(apikey){ - var conversionurl = 'http://openexchangerates.org/api/latest.json?app_id=' + apikey; - var current_timestamp = Math.floor(Date.now() / 1000); - $.getJSON(conversionurl, function(data) { - get_option('currency', function(currency){ - save_option('currency_rate', current_timestamp+'||'+data.rates[currency]); - }); - }); - }); - } + localStorage[$(this).attr("name")] = $(this).prop("checked"); }); - $(this).text('Saving...').removeClass("btn-success"); - - setTimeout(function() { - $('#save-options-button').text('Options Saved'); + $(this).text('Saving...').removeClass("btn-success"); + + setTimeout(function() { + $('#save-options-button').text('Options Saved'); }, 700); + + - get_option('reviewed', function(value){ - if(value != 'true') { - $('#rate-it').html('
Enjoying Better Envato? Head over to the Chrome Web Store and give it 5 stars. We will love you forever.
'); - } - }); + // Ask for a good review + if( ! localStorage.reviewed ) { + $('#rate-it').html('
Enjoying Better Envato? Head over to the Chrome Web Store and give it 5 stars. We will love you forever.
'); + } get_sales_data(); get_comment_data(); chrome.extension.getBackgroundPage().updatedSettings(); -} -/** - * Saves option to Chrome.storage - */ -function save_option(name, value){ - var object = {}; - object[name] = value; - - chrome.storage.sync.set(object, function() { - if(chrome.extension.lastError) { - console.log('An error occured: ' + chrome.extension.lastError.message); - return false; - } else { - return true; - } - }); } -/** - * Gets option from Chrome.storage - */ -function get_option(name, callback) { - chrome.storage.sync.get(name, function(response) { - callback(response[name], name); - }) -} /** * Reset the save button */ $('input, select').on('keyup click', function () { - $('#save-options-button').text('Save Options').addClass("btn-success"); + $('#save-options-button').text('Save Options').addClass("btn-success"); }); /** * Store that the user has already been to the Web Store (:. we <3 them) */ - + $('body').on('click', '.fivestars', function () { - save_option('reviewed', 'true'); - $('#rate-it').html('
You\'re awesome ♥'); + localStorage.reviewed = true; + $('#rate-it').html('
You\'re awesome ♥'); }); + + + // Sales Notifications function get_sales_data() { - get_option('username', function(value) { - if(typeof value == 'undefined') { - return false; - } - var username = value; - get_option('apikey', function(value) { - if(typeof value == 'undefined') { - return false; - } - var apikey = value; - get_option('earnings', function(value) { - var earnings = value; - - // Use Envato API to check sales - $.get('http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json', function(data) { - - //get current sales - var new_earnings = data.account.available_earnings; - save_option('earnings', new_earnings); - - }); - }); - }); + var username = localStorage.username; + var apikey = localStorage.apikey; + var earnings = localStorage.earnings; + + if (typeof username == 'undefined' || typeof apikey == 'undefined') { + return false; + } + + // Use Envato API to check sales + $.get('http://marketplace.envato.com/api/edge/' + username + '/' + apikey + '/account.json', function(data) { + + //get current sales + var new_earnings = data.account.available_earnings; + localStorage.earnings = new_earnings; + }); + } + function get_comment_data() { - get_option('username', function(value) { - var username = value; + var username = localStorage.username; - $.get('http://themeforest.net/feeds/user_item_comments/' + username + '.atom', function(data) { - var comment_feed = $.xml2json(data); - //console.log(comment_feed); - var comment_id = comment_feed.entry[0].id; - save_option('new_comment_id', comment_id); - }); + $.get('http://themeforest.net/feeds/user_item_comments/' + username + '.atom', function(data) { + var comment_feed = $.xml2json(data); + //console.log(comment_feed); + var comment_id = comment_feed.entry[0].id; + localStorage.new_comment_id = comment_id; }); }