Giter Site home page Giter Site logo

yoshows's Introduction

YoShows

Расширение для сайта myshows.me, которое добавляет ссылку на yohoho.cc для онлайн-просмотра любимого сериала.

Установка с магазина расширений

FireFox: YoShows

Chrome: скоро...

yoshows's People

Contributors

johnny-silverhand avatar

Watchers

James Cloos avatar  avatar

yoshows's Issues

L64-L75

yoshows/main.js

Lines 64 to 75 in c79e558

const renderProfile = () => {
return Promise.all(Array.from(document.getElementsByClassName("Unwatched-showTitle"), item => {
const showId = item.href.match(/\d+/g).shift()
const element = Array.from(item.closest("div.Row-container").getElementsByClassName("Unwatched-remain")).pop()
return fetchQuery(showId).then(result => {
return {
id: result,
element: element,
}
})
})).then(result => result.map(value => createYoNode(value)))
}

  1. Предлагаю варить массив промисов отдельно от Promise.all для лучшей читаемости кода

  2. Опять же в строке 66 можно использовать const showId = item.href.match(/\d+/g)[0]

  3.  return fetchQuery(showId).then(id=> ({
             id,
             element,
     })
    

})).then(result => result.map(value => createYoNode(value)))

})).then(result => result.map(createYoNode))

Количество параметров лямба функции равно 1, входящий параметр тоже 1. Значит необязательно ее описывать

L39-L41

yoshows/main.js

Lines 33 to 42 in c79e558

const render = () => {
const path = window.location.pathname
if (path === "/profile/") {
renderProfile().catch(error => console.log(error.message))
} else if (path === "/search/all/") {
renderSearch().catch(error => console.log(error.message))
} else if (/view\/\d+\/+$/ig.exec(path)) {
renderView(path.match(/\d+/g).shift()).catch(error => console.log(error.message))
}
}

renderView(path.match(/\d+/g).shift()).catch(error => console.log(error.message))

Проблема pop заключается в том, что она мутирует переменную path.
Да и создавался он для удаления элемента из массива, а не взятия из него элемента
Предлагаю использовать path.match(/\d+/g)[0] или еще для лучшей читаемости кода использовать диструктуризацию в данном месте

`
const [yourVariableName,...orher] = path.match(/\d+/g)

renderView(path.match(yourVariableName).catch(error => console.log(error.message))
`

Паттерн /\d+/g думаю можно и вынести, тк используется в нескольких местах

Обработку error => console.log(error.message) думаю можно и в отдельную функцию. Тк повторяется

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.