Hi! If you see an error or something is missing (like :focus-within for few years :P) please let me know ❤️
Element -- selects all h2 elements on the page
h2 {This gist provides a simple JavaScript implementation of the non-standard WebKit method scrollIntoViewIfNeeded that can be called on DOM elements.
Just use the code in index.js in your app or website. You can see usage in the test page test.html.
The parent element will only scroll if the element being called is out of the view. The boolean can force the element to be centered in the scrolling area.
| function declOfNum(number, titles) { | |
| cases = [2, 0, 1, 1, 1, 2]; | |
| return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ]; | |
| } | |
| use: | |
| declOfNum(count, ['найдена', 'найдено', 'найдены']); |
| const TRACKS_SELECTOR = 'div.d-track__overflowable-column > div.d-track__overflowable-wrapper.deco-typo-secondary.block-layout'; | |
| const TRACK_NAME_SELECTOR = '.d-track__title'; | |
| const TRACK_VERSION_SELECTOR = '.d-track__version'; | |
| const TRACK_ARTISTS_SELECTOR = '.d-track__artists > a'; | |
| const trackElements = document.querySelectorAll(TRACKS_SELECTOR); | |
| const tracks = []; | |
| trackElements.forEach((trackElement) => { | |
| const name = trackElement.querySelector(TRACK_NAME_SELECTOR).innerHTML.trim(); | |
| const version = trackElement.querySelector(TRACK_VERSION_SELECTOR)?.innerHTML.trim(); |
| const SEARCH_INPUT_SELECTOR = 'div[role="search"] input[role="searchbox"]'; | |
| const ADD_BUTTON_SELECTOR = 'div[role="presentation"] > div[role="row"] button[aria-label="Add to Playlist"]'; | |
| const input = document.querySelector(SEARCH_INPUT_SELECTOR); | |
| const tracks = ['test']; | |
| const wait = async (timeout) => new Promise((resolve) => setTimeout(resolve, timeout)); | |
| const findTracks = async (track) => { |
| // Simple gist to test parallel promise resolution when using async / await | |
| function promiseWait(time) { | |
| return new Promise((resolve, reject) => { | |
| setTimeout(() => { | |
| resolve(true); | |
| }, time); | |
| }); | |
| } |
React Component Lifecycle
| var loaderUtils = require('loader-utils'); | |
| module.exports = function(source) { | |
| this.cacheable && this.cacheable(); | |
| var query = loaderUtils.parseQuery(this.query); | |
| var args = []; | |
| // apply?config=key => sourceFn(require('webpack.config').key) | |
| if (typeof query.config === 'string') { | |
| if (!query.config in this.options) |