From 5d3bfbf37a71fddc10dd6a70e2c686e61973b9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20D=C4=85browski?= Date: Tue, 20 Nov 2018 22:36:51 +0100 Subject: [PATCH 1/4] opgg plugin without bookmarks --- plugins/opgg.js | 125 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 plugins/opgg.js diff --git a/plugins/opgg.js b/plugins/opgg.js new file mode 100644 index 0000000..49bc37c --- /dev/null +++ b/plugins/opgg.js @@ -0,0 +1,125 @@ +const cheerio = require('cheerio'); +const request = require('request'); +const { upperFirst } = require('lodash'); + +const url = 'http://www.op.gg/champion/'; + +const getPerkIdFromImg = $ => (_, elem) => + $(elem) + .attr('src') + .split('/') + .slice(-1) + .pop() + .split('.')[0]; + +function extractRunePagesFromElement($, champion, position) { + 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(); + + const selectedPerkIds = $(runePageElement) + .find('.champion-overview__data .perk-page .perk-page__item--active 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 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); + + 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); + } + } + }); + }); +} + +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 new Error('Rune page not loaded'); + } + }); +} + +const plugin = { + id: 'opgg', + name: 'OP.GG', + active: true, + bookmarks: false, // todo + + getPages(champion, callback) { + _getPages(champion, callback); + } + // ... +}; + +module.exports = { plugin }; + +_getPages('Aatrox', response => console.log(JSON.stringify(response))); From d94b68fb495ff72c6ef5ce3fb5bcad2655e1cc5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20D=C4=85browski?= Date: Tue, 20 Nov 2018 22:52:54 +0100 Subject: [PATCH 2/4] bookmarks updating in opgg --- plugins/opgg.js | 50 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/plugins/opgg.js b/plugins/opgg.js index 49bc37c..6415344 100644 --- a/plugins/opgg.js +++ b/plugins/opgg.js @@ -4,15 +4,15 @@ const { upperFirst } = require('lodash'); const url = 'http://www.op.gg/champion/'; -const getPerkIdFromImg = $ => (_, elem) => - $(elem) - .attr('src') - .split('/') - .slice(-1) - .pop() - .split('.')[0]; - 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') @@ -23,12 +23,12 @@ function extractRunePagesFromElement($, champion, position) { const styles = $(runePageElement) .find('.champion-overview__data .perk-page .perk-page__item--mark img') - .map(getPerkIdFromImg($)) + .map(getPerkIdFromImg) .get(); const selectedPerkIds = $(runePageElement) .find('.champion-overview__data .perk-page .perk-page__item--active img') - .map(getPerkIdFromImg($)) + .map(getPerkIdFromImg) .get(); return { @@ -57,6 +57,11 @@ function parsePage($, champion, position) { .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 = []; @@ -103,7 +108,7 @@ function _getPages(champion, callback) { }); } else { callback(runePages); - throw new Error('Rune page not loaded'); + throw Error('rune page not loaded'); } }); } @@ -112,14 +117,27 @@ const plugin = { id: 'opgg', name: 'OP.GG', active: true, - bookmarks: false, // todo - + 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 }; - -_getPages('Aatrox', response => console.log(JSON.stringify(response))); From 441340ef3a934c5bd284b7fe41495a6ded90fc4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20D=C4=85browski?= Date: Tue, 20 Nov 2018 23:55:06 +0100 Subject: [PATCH 3/4] fixed an issue with no results when only one position --- plugins/index.js | 4 ++-- plugins/opgg.js | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/plugins/index.js b/plugins/index.js index 69446df..14d0289 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -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; @@ -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; diff --git a/plugins/opgg.js b/plugins/opgg.js index 6415344..218eed0 100644 --- a/plugins/opgg.js +++ b/plugins/opgg.js @@ -19,7 +19,7 @@ function extractRunePagesFromElement($, champion, position) { .map((i, elem) => $(elem).text()) .get(); - const name = `${champion} ${upperFirst(position)} PR ${stats[0]} WR ${stats[1]}`; + 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') @@ -81,17 +81,21 @@ function extractPages(html, champion, callback) { positions.splice(positions.indexOf(initialPosition), 1); - 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); + 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) { From 075c3e0c728b64e05a8b3f84ec05cbb5cf42405a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20D=C4=85browski?= Date: Wed, 21 Nov 2018 19:38:23 +0100 Subject: [PATCH 4/4] opgg with stat shards, added polish locale --- plugins/opgg.js | 11 ++++++++++- src/locales/pl.json | 42 +++++++++++++++++++++++++++++++++++++++++ tags/settings-panel.tag | 5 +++-- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/locales/pl.json diff --git a/plugins/opgg.js b/plugins/opgg.js index 218eed0..e18c073 100644 --- a/plugins/opgg.js +++ b/plugins/opgg.js @@ -26,11 +26,20 @@ function extractRunePagesFromElement($, champion, position) { .map(getPerkIdFromImg) .get(); - const selectedPerkIds = $(runePageElement) + // 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], diff --git a/src/locales/pl.json b/src/locales/pl.json new file mode 100644 index 0000000..a772ce8 --- /dev/null +++ b/src/locales/pl.json @@ -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" +} \ No newline at end of file diff --git a/tags/settings-panel.tag b/tags/settings-panel.tag index edee2f0..efc7288 100644 --- a/tags/settings-panel.tag +++ b/tags/settings-panel.tag @@ -25,6 +25,7 @@
Français
Italiano
Magyar
+
Polski
Português
Português Brasileiro
Русский
@@ -49,7 +50,7 @@ - +

settings.updates

@@ -58,7 +59,7 @@