Skip to content

Commit

Permalink
Merge tag '1.4.0' into develop
Browse files Browse the repository at this point in the history
+ Added sale calculator
+ Removed ajax
+ Added optional fixer.io request
  • Loading branch information
rodel77 committed Dec 30, 2017
2 parents 2c1a4af + 96b8def commit 25e8cd2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 43 deletions.
49 changes: 25 additions & 24 deletions author/author.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function onReady(convert, options, $, ajax){
function onReady(convert, options, $){
var userLogged = $(".accountUsername").innerHTML;
var title = $(".titleBar h1").innerHTML;
var resources = document.querySelectorAll(".resourceListItem");
Expand Down Expand Up @@ -27,32 +27,33 @@ function onReady(convert, options, $, ajax){

for(var i = 0; i < resourcesD.length; i++){
var id = resourcesD[i];
ajax({
url: `https://www.spigotmc.org/resources/${id}/buyers`,
success: function(response){
fetch("https://www.spigotmc.org/resources/"+id+"/buyers", {
'credentials': 'same-origin'
}).then(function(response){
return response.text();
}).then(function(body){
var page = document.createElement("div");
page.innerHTML = body;
console.log(page);
var data = getBuyersData(page.querySelectorAll(".memberListItem"))
console.log(data);

var page = document.createElement("div");
page.innerHTML = response;
var data = getBuyersData(page.querySelectorAll(".memberListItem"))
console.log(data);

var totalUSD = 0;
for(var ex in data.exchanges){
var usd = convert(data.exchanges[ex], ex, getSelectedExchange());
totalUSD+=usd;
}
var totalUSD = 0;
for(var ex in data.exchanges){
var usd = convert(data.exchanges[ex], ex, getSelectedExchange());
totalUSD+=usd;
}

total+=totalUSD;
totalSales+=data.pricedSales;
resourcesData.push({data: data, name: page.querySelector(".resourceInfo h1").innerText});
total+=totalUSD;
totalSales+=data.pricedSales;
resourcesData.push({data: data, name: page.querySelector(".resourceInfo h1").innerText});

loadIndex++;
console.debug("[Author] Resource", loadIndex, "loaded!")
$("#loadingState").innerHTML = `Loading ${loadIndex}/${resourcesD.length}`;
if(loadIndex==resourcesD.length){
$("#loadingState").remove();
requestEnd();
}
loadIndex++;
console.debug("[Author] Resource", loadIndex, "loaded!")
$("#loadingState").innerHTML = `Loading ${loadIndex}/${resourcesD.length}`;
if(loadIndex==resourcesD.length){
$("#loadingState").remove();
requestEnd();
}
});
}
Expand Down
38 changes: 25 additions & 13 deletions common/money.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
fetch("https://api.fixer.io/latest?base=USD").then(function(e){
return e.json();
}).then(function(e){
console.debug("[Request] Fixer request successfully");
ready(e.rates);
}).catch(function(e){
console.debug("[Request] Error getting fixer json");
ready(undefined);
});

var base = "USD";
var rates = {"AUD":1.2957,"BGN":1.65,"BRL":3.3198,"CAD":1.2703,"CHF":0.99004,"CNY":6.576,"CZK":21.724,"DKK":6.2805,"GBP":0.74722,"HKD":7.8164,"HRK":6.3629,"HUF":263.07,"IDR":13558.0,"ILS":3.4848,"INR":64.039,"JPY":113.36,"KRW":1076.8,"MXN":19.511,"MYR":4.0795,"NOK":8.3492,"NZD":1.4261,"PHP":50.099,"PLN":3.5413,"RON":3.9163,"RUB":58.293,"SEK":8.3799,"SGD":1.3439,"THB":32.76,"TRY":3.8176,"ZAR":12.705,"EUR":0.84367}
rates["USD"] = 1;

function ready(apiRates){
console.debug("[Request] Money request ended");

rates = apiRates==undefined ? apiRates : rates;

onReady(convert, getExchangesInOptions(), function(selector){
return document.querySelector(selector);
});
}


// (function(){$.ajax({
// url: MONEY_URL,
// dataType: "json",
// success: function(json){

console.debug("[Request] Money request ended");
var base = "USD";
var rates = {"AUD":1.2957,"BGN":1.65,"BRL":3.3198,"CAD":1.2703,"CHF":0.99004,"CNY":6.576,"CZK":21.724,"DKK":6.2805,"GBP":0.74722,"HKD":7.8164,"HRK":6.3629,"HUF":263.07,"IDR":13558.0,"ILS":3.4848,"INR":64.039,"JPY":113.36,"KRW":1076.8,"MXN":19.511,"MYR":4.0795,"NOK":8.3492,"NZD":1.4261,"PHP":50.099,"PLN":3.5413,"RON":3.9163,"RUB":58.293,"SEK":8.3799,"SGD":1.3439,"THB":32.76,"TRY":3.8176,"ZAR":12.705,"EUR":0.84367}
rates["USD"] = 1;

function getRate(from, to){
if(from===base){
Expand Down Expand Up @@ -34,15 +55,6 @@
return options;
}

setTimeout(function(){
onReady(convert, getExchangesInOptions(), function(selector){
return document.querySelector(selector);
}, $.ajax)
}, 10);

document.onreadystatechange = function(){
console.log("LOADED!")
}
// },
// error: function(err){
// console.log(err)
Expand Down
9 changes: 4 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@
},

"permissions": [
"https://www.spigotmc.org/*",
"storage"
"https://www.spigotmc.org/*"
],

"content_scripts": [
{
"matches": ["https://www.spigotmc.org/*/buyers"],
"js": ["libs/ajax.js", "libs/highcharts.js", "libs/exporting.js", "common/helper.js", "common/money.js", "resource/buyers.js", "resource/dashboard.js"],
"js": ["libs/highcharts.js", "libs/exporting.js", "common/helper.js", "common/money.js", "resource/buyers.js", "resource/dashboard.js"],
"run_at": "document_idle"
},
{
"matches": ["https://www.spigotmc.org/*/authors/*"],
"js": ["libs/ajax.js", "common/helper.js", "common/money.js", "author/author.js"]
"js": ["common/helper.js", "common/money.js", "author/author.js"]
},
{
"matches": ["https://www.spigotmc.org/resources/*/edit*"],
"js": ["libs/ajax.js", "common/helper.js", "resource/edit/sale_calculator.js"]
"js": ["common/helper.js", "resource/edit/sale_calculator.js"]
}
]
}
2 changes: 1 addition & 1 deletion resource/buyers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function onReady(convert, options, selector, ajax){
function onReady(convert, options, selector){
console.debug("[Buyers] Buyers initialized ");
var data = getBuyersData(document.querySelectorAll(".memberListItem"));

Expand Down

0 comments on commit 25e8cd2

Please sign in to comment.