Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #65 from paolostyle/master
Browse files Browse the repository at this point in the history
OP.GG plugin w/ stat shards included, Polish locale
  • Loading branch information
OrangeNote authored Nov 22, 2018
2 parents 4748a84 + 075c3e0 commit 9693b9c
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 4 deletions.
4 changes: 2 additions & 2 deletions plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var isDev = require('electron-is-dev');

if (!isDev) {
var plugins = ["local", "runeforge", "championgg", "koreanbuilds", "runeslol"];
var plugins = ["local", "runeforge", "championgg", "koreanbuilds", "runeslol", "opgg"];

var __hasProp = {}.hasOwnProperty;

Expand All @@ -18,7 +18,7 @@ if (!isDev) {
else {
console.log("isDev: dynamic plugins loader")
var collectExports, fs, path,
fs = require('fs');
fs = require('fs');
path = require('path');

var __hasProp = {}.hasOwnProperty;
Expand Down
156 changes: 156 additions & 0 deletions plugins/opgg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
const cheerio = require('cheerio');
const request = require('request');
const { upperFirst } = require('lodash');

const url = 'http://www.op.gg/champion/';

function extractRunePagesFromElement($, champion, position) {
const getPerkIdFromImg = (_, elem) =>
$(elem)
.attr('src')
.split('/')
.slice(-1)
.pop()
.split('.')[0];

return (runePageElement, index) => {
const stats = $(runePageElement)
.find('.champion-overview__stats strong')
.map((i, elem) => $(elem).text())
.get();

const name = `${champion} ${upperFirst(position)} PR${stats[0]} WR${stats[1]}`;

const styles = $(runePageElement)
.find('.champion-overview__data .perk-page .perk-page__item--mark img')
.map(getPerkIdFromImg)
.get();

// normal runes
let selectedPerkIds = $(runePageElement)
.find('.champion-overview__data .perk-page .perk-page__item--active img')
.map(getPerkIdFromImg)
.get();

// stat shards
selectedPerkIds = selectedPerkIds.concat(
$(runePageElement)
.find('.champion-overview__data .fragment__summary img')
.map(getPerkIdFromImg)
.get()
);

return {
name,
primaryStyleId: styles[0],
subStyleId: styles[1],
selectedPerkIds,
bookmark: {
src: url + champion + '/statistics/' + position,
meta: {
pageType: index,
champion
},
remote: {
name: 'OP.GG',
id: 'opgg'
}
}
};
};
}

function parsePage($, champion, position) {
return $("tbody[class*='ChampionKeystoneRune-'] tr")
.toArray()
.map(extractRunePagesFromElement($, champion, position));
}

function parseSinglePage($, champion, position, pageType) {
const element = $("tbody[class*='ChampionKeystoneRune-'] tr").get(pageType);
return extractRunePagesFromElement($, champion, position)(element, pageType);
}

function extractPages(html, champion, callback) {
const $ = cheerio.load(html);
let pages = [];
let initialPosition;

const positions = $('.champion-stats-position li')
.map((_, element) => {
if (element.attribs['class'].indexOf('champion-stats-header__position--active') !== -1) {
initialPosition = element.attribs['data-position'].toLowerCase();
}

return element.attribs['data-position'].toLowerCase();
})
.get();

pages = pages.concat(parsePage($, champion, initialPosition));

positions.splice(positions.indexOf(initialPosition), 1);

if (positions.length) {
positions.forEach((position, index) => {
const opggUrl = url + champion + '/statistics/' + position;
request.get(opggUrl, (error, response, newHtml) => {
if (!error && response.statusCode === 200) {
pages = pages.concat(parsePage(cheerio.load(newHtml), champion, position));
if (index === positions.length - 1) {
callback(pages);
}
}
});
});
} else {
callback(pages);
}
}

function _getPages(champion, callback) {
const runePages = { pages: {} };

const entryChampUrl = url + champion;
request.get(entryChampUrl, (error, response, html) => {
if (!error && response.statusCode === 200) {
extractPages(html, champion, pages => {
pages.forEach(page => {
runePages.pages[page.name] = page;
});
callback(runePages);
});
} else {
callback(runePages);
throw Error('rune page not loaded');
}
});
}

const plugin = {
id: 'opgg',
name: 'OP.GG',
active: true,
bookmarks: true,
getPages(champion, callback) {
_getPages(champion, callback);
},
syncBookmark(bookmark, callback) {
request.get(bookmark.src, (error, response, html) => {
if (!error && response.statusCode == 200) {
const position = bookmark.src.split('/').pop();
callback(
parseSinglePage(
cheerio.load(html),
bookmark.meta.champion,
position,
bookmark.meta.pageType
)
);
} else {
throw Error('rune page not loaded');
}
});
}
};

module.exports = { plugin };
42 changes: 42 additions & 0 deletions src/locales/pl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"settings.title": "Ustawienia",
"settings.client_path": "Ścieżka instalacyjna klienta League of Legends",
"champion.name": "Nazwa bohatera",
"champion.autopick.tooltip": "Gdy jesteś w fazie wyboru bohatera, wybrana postać zostanie wybrana także w RuneBook.",
"champion.autopick": "Automatyczny wybór",
"settings.pathdiscovery.help": "Automatyczna detekcja jest włączona. Wyłącz tę opcję, jeśli chcesz ustawić ścieżkę ręcznie.",
"settings.pathdiscovery": "Automatyczna detekcja ścieżki instalacyjna (zalecane)",
"settings.restart.warning": "Zrestartuj RuneBook, aby zastosować zmiany",
"settings.updates": "Aktualizacje",
"settings.newversion": "Dostępna jest nowa wersja!",
"settings.downloadupdate": "Pobierz aktualizację",
"settings.uptodate": "RuneBook jest aktualny.",
"settings.advanced": "Zaawansowane",
"settings.localrunefile": "Plik z lokalnymi stronami na runy",
"settings.choosefile": "Wybierz plik .json",
"settings.lang": "Język",
"chapters.title": "Rozdziały",
"chapters.welcome": "Witaj w RuneBook!",
"chapters.localpages": "Lokalne strony",
"chapters.startmessage": "Wybierz bohatera, by zarządzać swoimi stronami na runy.",
"whatsnew.title": "Co nowego...",
"connectionstatus.inprogress": "Logowanie...",
"connectionstatus.loggingout": "Wylogowywanie...",
"currentpage.title": "Aktywna strona",
"currentpage.unavailable": "Aktywna strona jest niedostępna.",
"currentpage.unavailable.subheader1": "Zaloguj się do klienta League of Legends, by mieć dostęp do swoich stron na runy.",
"currentpage.unavailable.subheader2": "Jeśli błąd nadal występuje, przejdź do Ustawień i ręcznie ustaw ścieżkę instalacyjną klienta.",
"currentpage.downloadcurrentpage": "Zaimportuj tę stronę",
"pagelist.uploadpage": "Wyślij tę stronę do klienta",
"pagelist.syncfrom": "Zsynchronizuj z ",
"pagelist.unlink": "Usuń tę stronę",
"pagelist.bookmarkpage": "Zapisz do lokalnych stron",
"pagelist.emptylocalpage": "Wygląda na to, że nie masz żadnych stron dla tego bohatera.",
"pagelist.emptylocalpage.subheader": "Kliknij przycisk poniżej, by zaimportować obecnie aktywną stronę.",
"pagelist.emptyremotepage": "Nie można było znaleźć stron dla tego bohatera",
"pagelist.emptyremotepage.subheader": "Nie znaleziono żadnych stron lub serwis jest chwilowo niedostępny.",
"pagelist.confirmdialog": "Jesteś pewien, że chcesz usunąć tę stronę?",
"settings.experimental": "Eksperymentalne",
"settings.darktheme": "Ciemny motyw",
"currentpage.retry": "Ponów"
}
5 changes: 3 additions & 2 deletions tags/settings-panel.tag
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<div class="item" data-value="fr"><i class="fr flag"></i>Français</div>
<div class="item" data-value="it"><i class="it flag"></i>Italiano</div>
<div class="item" data-value="hu"><i class="hu flag"></i>Magyar</div>
<div class="item" data-value="pl"><i class="pl flag"></i>Polski</div>
<div class="item" data-value="pt"><i class="pt flag"></i>Português</div>
<div class="item" data-value="pt_br"><i class="br flag"></i>Português Brasileiro</div>
<div class="item" data-value="ro"><i class="ro flag"></i>Română</div>
Expand All @@ -50,7 +51,7 @@
<input type="checkbox" name="leaguepath" onchange={ togglePathDiscovery } ref="pathdiscovery">
<label><i1-8n>settings.pathdiscovery</i1-8n></label>
</div>

<h4 class="ui horizontal divider header">
<i class="teal arrow alternate circle down outline icon" style="padding-right:.5em;font-size:1em"></i><i1-8n>settings.updates</i1-8n>
</h4>
Expand All @@ -59,7 +60,7 @@
<button if={ opts.updateready } class="ui teal button update-button" onclick={ doUpdate }><i1-8n>settings.downloadupdate</i1-8n></div>
<span if={ !opts.updateready }><i1-8n>settings.uptodate</i1-8n></span>
</div>

<h4 class="ui horizontal divider header">
<i class="red fire icon" style="padding-right:.5em;font-size:1em"></i><i1-8n>settings.advanced</i1-8n>
</h4>
Expand Down

0 comments on commit 9693b9c

Please sign in to comment.