This repository has been archived by the owner on Jan 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from paolostyle/master
OP.GG plugin w/ stat shards included, Polish locale
- Loading branch information
Showing
4 changed files
with
203 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters