code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function mkdtemp() { return new Promise((resolve, reject) => { tmp.dir({unsafeCleanup: true}, (err, tmpPath) => { if (err) { return reject(err); } resolve(tmpPath); }); }); }
@return {Promise<string>} A promise that resolves to the path.
mkdtemp
javascript
tschaub/gh-pages
test/helper.js
https://github.com/tschaub/gh-pages/blob/master/test/helper.js
MIT
function setupRepo(fixtureName, options) { const branch = options.branch || 'gh-pages'; const userEmail = (options.user && options.user.email) || '[email protected]'; const userName = (options.user && options.user.name) || 'User Name'; return mkdtemp() .then((dir) => { const fixturePath = path.join(fixtures, fixtureName, 'remote'); return fs.copy(fixturePath, dir).then(() => new Git(dir)); }) .then((git) => git.init()) .then((git) => git.exec('config', 'user.email', userEmail)) .then((git) => git.exec('config', 'user.name', userName)) .then((git) => git.exec('checkout', '--orphan', branch)) .then((git) => git.add('.')) .then((git) => git.commit('Initial commit')) .then((git) => git.cwd); }
Creates a git repo with the contents of a fixture. @param {string} fixtureName Name of fixture. @param {Object} options Repo options. @return {Promise<string>} A promise for the path to the repo.
setupRepo
javascript
tschaub/gh-pages
test/helper.js
https://github.com/tschaub/gh-pages/blob/master/test/helper.js
MIT
function setupRemote(fixtureName, options) { const branch = options.branch || 'gh-pages'; return setupRepo(fixtureName, options).then((dir) => mkdtemp() .then((remote) => { return new Git(remote).exec('init', '--bare').then(() => remote); }) .then((remote) => { const git = new Git(dir); const url = 'file://' + remote; return git.exec('push', url, branch).then(() => url); }), ); }
Creates a git repo with the contents of a fixture and pushes to a remote. @param {string} fixtureName Name of the fixture. @param {Object} options Repo options. @return {Promise} A promise.
setupRemote
javascript
tschaub/gh-pages
test/helper.js
https://github.com/tschaub/gh-pages/blob/master/test/helper.js
MIT
function assertContentsMatch(dir, url, branch) { return mkdtemp() .then((root) => { const clone = path.join(root, 'repo'); const options = {git: 'git', remote: 'origin', depth: 1}; return Git.clone(url, clone, branch, options); }) .then((git) => { const comparison = compare(dir, git.cwd, {excludeFilter: '.git'}); if (comparison.same) { return true; } else { const message = comparison.diffSet .map((entry) => { const state = { equal: '==', left: '->', right: '<-', distinct: '<>', }[entry.state]; const name1 = entry.name1 ? entry.name1 : '<none>'; const name2 = entry.name2 ? entry.name2 : '<none>'; return [name1, state, name2].join(' '); }) .join('\n'); throw new Error('Directories do not match:\n' + message); } }); }
@param {string} dir The dir. @param {string} url The url. @param {string} branch The branch. @return {Promise} A promise.
assertContentsMatch
javascript
tschaub/gh-pages
test/helper.js
https://github.com/tschaub/gh-pages/blob/master/test/helper.js
MIT
function Maplace(args) { this.VERSION = '@VERSION'; this.loaded = false; this.markers = []; this.circles = []; this.oMap = false; this.view_all_key = 'all'; this.infowindow = null; this.maxZIndex = 0; this.ln = 0; this.oMap = false; this.oBounds = null; this.map_div = null; this.canvas_map = null; this.controls_wrapper = null; this.current_control = null; this.current_index = null; this.Polyline = null; this.Polygon = null; this.Fusion = null; this.directionsService = null; this.directionsDisplay = null; //default options this.o = { debug: false, map_div: '#gmap', controls_div: '#controls', generate_controls: true, controls_type: 'dropdown', controls_cssclass: '', controls_title: '', controls_on_map: true, controls_applycss: true, controls_position: google.maps.ControlPosition.RIGHT_TOP, type: 'marker', view_all: true, view_all_text: 'View All', pan_on_click: true, start: 0, locations: [], shared: {}, map_options: { mapTypeId: google.maps.MapTypeId.ROADMAP }, stroke_options: { strokeColor: '#0000FF', strokeOpacity: 0.8, strokeWeight: 2, fillColor: '#0000FF', fillOpacity: 0.4 }, directions_options: { travelMode: google.maps.TravelMode.DRIVING, unitSystem: google.maps.UnitSystem.METRIC, optimizeWaypoints: false, provideRouteAlternatives: false, avoidHighways: false, avoidTolls: false }, circle_options: { radius: 100, visible: true }, styles: {}, fusion_options: {}, directions_panel: null, draggable: false, editable: false, show_infowindows: true, show_markers: true, infowindow_type: 'bubble', listeners: {}, //events beforeViewAll: function() {}, afterViewAll: function() {}, beforeShow: function(index, location, marker) {}, afterShow: function(index, location, marker) {}, afterCreateMarker: function(index, location, marker) {}, beforeCloseInfowindow: function(index, location) {}, afterCloseInfowindow: function(index, location) {}, beforeOpenInfowindow: function(index, location, marker) {}, afterOpenInfowindow: function(index, location, marker) {}, afterRoute: function(distance, status, result) {}, onPolylineClick: function(obj) {}, onPolygonClick: function(obj) {}, circleRadiusChanged: function(index, circle, marker) {}, circleCenterChanged: function(index, circle, marker) {}, drag: function(index, location, marker) {}, dragEnd: function(index, location, marker) {}, dragStart: function(index, location, marker) {} }; //default menu types this.AddControl('dropdown', html_dropdown); this.AddControl('list', html_ullist); if (args && args.type === 'directions') { !args.show_markers && (args.show_markers = false); !args.show_infowindows && (args.show_infowindows = false); } //init $.extend(true, this.o, args); }
Create a new instance @class Maplace @constructor
Maplace
javascript
danielemoraschi/maplace.js
src/maplace.js
https://github.com/danielemoraschi/maplace.js/blob/master/src/maplace.js
MIT
resolveTests = testComponents => { if (!isArray(testComponents)) { return false } forEach(testComponents, testComponent => forEach(testComponent, fn => fn())) }
Calls all reactcards Component tests for mocha/jasmine cli tests resolveTests calls all component tests instead of having to manually execute all of them Import all Component tests and resolveTests will run all functions. import resolveTests from '../../src/utils/resolveTests' import * as advanced from './advanced' resolveTests([advanced]) @param {Array} testComponents @returns {boolean}
resolveTests
javascript
steos/reactcards
src/utils/resolveTests.js
https://github.com/steos/reactcards/blob/master/src/utils/resolveTests.js
BSD-3-Clause
resolveTests = testComponents => { if (!isArray(testComponents)) { return false } forEach(testComponents, testComponent => forEach(testComponent, fn => fn())) }
Calls all reactcards Component tests for mocha/jasmine cli tests resolveTests calls all component tests instead of having to manually execute all of them Import all Component tests and resolveTests will run all functions. import resolveTests from '../../src/utils/resolveTests' import * as advanced from './advanced' resolveTests([advanced]) @param {Array} testComponents @returns {boolean}
resolveTests
javascript
steos/reactcards
src/utils/resolveTests.js
https://github.com/steos/reactcards/blob/master/src/utils/resolveTests.js
BSD-3-Clause
chainWebpack(config) { // it can improve the speed of the first screen, it is recommended to turn on preload config.plugin('preload').tap(() => [ { rel: 'preload', // to ignore runtime.js // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171 fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/], include: 'initial' } ]) // when there are many pages, it will cause too many meaningless requests config.plugins.delete('prefetch') // set svg-sprite-loader config.module .rule('svg') .exclude.add(resolve('src/icons')) .end() config.module .rule('icons') .test(/\.svg$/) .include.add(resolve('src/icons')) .end() .use('svg-sprite-loader') .loader('svg-sprite-loader') .options({ symbolId: 'icon-[name]' }) .end() config .when(process.env.NODE_ENV !== 'development', config => { config .plugin('ScriptExtHtmlWebpackPlugin') .after('html') .use('script-ext-html-webpack-plugin', [{ // `runtime` must same as runtimeChunk name. default is `runtime` inline: /runtime\..*\.js$/ }]) .end() config .optimization.splitChunks({ chunks: 'all', cacheGroups: { libs: { name: 'chunk-libs', test: /[\\/]node_modules[\\/]/, priority: 10, chunks: 'initial' // only package third parties that are initially dependent }, elementUI: { name: 'chunk-elementUI', // split elementUI into a single package priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm }, commons: { name: 'chunk-commons', test: resolve('src/components'), // can customize your rules minChunks: 3, // minimum common number priority: 5, reuseExistingChunk: true } } }) // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk config.optimization.runtimeChunk('single') } ) }
You will need to set publicPath if you plan to deploy your site under a sub path, for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/, then publicPath should be set to "/bar/". In most cases please use '/' !!! Detail: https://cli.vuejs.org/config/#publicpath
chainWebpack
javascript
PanJiaChen/vue-admin-template
vue.config.js
https://github.com/PanJiaChen/vue-admin-template/blob/master/vue.config.js
MIT
createRouter = () => new Router({ // mode: 'history', // require service support scrollBehavior: () => ({ y: 0 }), routes: constantRoutes })
constantRoutes a base page that does not have permission requirements all roles can be accessed
createRouter
javascript
PanJiaChen/vue-admin-template
src/router/index.js
https://github.com/PanJiaChen/vue-admin-template/blob/master/src/router/index.js
MIT
createRouter = () => new Router({ // mode: 'history', // require service support scrollBehavior: () => ({ y: 0 }), routes: constantRoutes })
constantRoutes a base page that does not have permission requirements all roles can be accessed
createRouter
javascript
PanJiaChen/vue-admin-template
src/router/index.js
https://github.com/PanJiaChen/vue-admin-template/blob/master/src/router/index.js
MIT
function resetRouter() { const newRouter = createRouter() router.matcher = newRouter.matcher // reset router }
constantRoutes a base page that does not have permission requirements all roles can be accessed
resetRouter
javascript
PanJiaChen/vue-admin-template
src/router/index.js
https://github.com/PanJiaChen/vue-admin-template/blob/master/src/router/index.js
MIT
generateSign = (params) => { const keys = Object.keys(params).filter( (key) => key !== 'format' || key !== 'callback' ); // params has to be ordered alphabetically keys.sort(); const o = keys.reduce((r, key) => r + key + params[key], ''); // append secret return forge.md5 .create() .update(forge.util.encodeUtf8(o + options.apiSecret)) .digest() .toHex(); }
Computes string for signing request See https://www.last.fm/api/authspec#8
generateSign
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
generateSign = (params) => { const keys = Object.keys(params).filter( (key) => key !== 'format' || key !== 'callback' ); // params has to be ordered alphabetically keys.sort(); const o = keys.reduce((r, key) => r + key + params[key], ''); // append secret return forge.md5 .create() .update(forge.util.encodeUtf8(o + options.apiSecret)) .digest() .toHex(); }
Computes string for signing request See https://www.last.fm/api/authspec#8
generateSign
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
_isAuthRequested = () => { const token = localStorage.getObject('lastfmtoken'); return token != null; }
Computes string for signing request See https://www.last.fm/api/authspec#8
_isAuthRequested
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
_isAuthRequested = () => { const token = localStorage.getObject('lastfmtoken'); return token != null; }
Computes string for signing request See https://www.last.fm/api/authspec#8
_isAuthRequested
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
static getSession(callback) { // load session info from localStorage let mySession = localStorage.getObject('lastfmsession'); if (mySession != null) { return callback(mySession); } // trade session with token const token = localStorage.getObject('lastfmtoken'); if (token == null) { return callback(null); } // token exists const params = { method: 'auth.getsession', api_key: options.apiKey, token, }; params.api_sig = generateSign(params); params.format = 'json'; axios .get(apiUrl, { params, }) .then((response) => { const { data } = response; mySession = data.session; localStorage.setObject('lastfmsession', mySession); callback(mySession); }) .catch((error) => { if (error.response.status === 403) { callback(null); } }); return null; }
Computes string for signing request See https://www.last.fm/api/authspec#8
getSession
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
static getUserInfo(callback) { this.getSession((session) => { if (session == null) { callback(null); return; } const params = { method: 'user.getinfo', api_key: options.apiKey, sk: session.key, }; params.api_sig = generateSign(params); params.format = 'json'; axios .post(apiUrl, '', { params, }) .then((response) => { const { data } = response; if (callback != null) { callback(data); } }); }); }
Computes string for signing request See https://www.last.fm/api/authspec#8
getUserInfo
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
static updateStatus() { // auth status // 0: never request for auth // 1: request but fail to success // 2: success auth if (!_isAuthRequested()) { status = 0; return; } this.getUserInfo((data) => { if (data === null) { status = 1; } else { status = 2; } }); }
Computes string for signing request See https://www.last.fm/api/authspec#8
updateStatus
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
static getAuth(callback) { axios .get(apiUrl, { params: { method: 'auth.gettoken', api_key: options.apiKey, format: 'json', }, }) .then((response) => { const { data } = response; const { token } = data; localStorage.setObject('lastfmtoken', token); const grant_url = `https://www.last.fm/api/auth/?api_key=${options.apiKey}&token=${token}`; window.open(grant_url, '_blank'); status = 1; if (callback != null) { callback(); } }); }
Computes string for signing request See https://www.last.fm/api/authspec#8
getAuth
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
static cancelAuth() { localStorage.removeItem('lastfmsession'); localStorage.removeItem('lastfmtoken'); this.updateStatus(); }
Computes string for signing request See https://www.last.fm/api/authspec#8
cancelAuth
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
static sendNowPlaying(track, artist, callback) { this.getSession((session) => { const params = { method: 'track.updatenowplaying', track, artist, api_key: options.apiKey, sk: session.key, }; params.api_sig = generateSign(params); params.format = 'json'; axios .post(apiUrl, '', { params, }) .then((response) => { const { data } = response; if (callback != null) { callback(data); } }); }); }
Computes string for signing request See https://www.last.fm/api/authspec#8
sendNowPlaying
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
static scrobble(timestamp, track, artist, album, callback) { this.getSession((session) => { const params = { method: 'track.scrobble', 'timestamp[0]': timestamp, 'track[0]': track, 'artist[0]': artist, api_key: options.apiKey, sk: session.key, }; if (album !== '' && album != null) { params['album[0]'] = album; } params.api_sig = generateSign(params); params.format = 'json'; axios .post(apiUrl, '', { params, }) .then((response) => { const { data } = response; if (callback != null) { callback(data); } }); }); }
Computes string for signing request See https://www.last.fm/api/authspec#8
scrobble
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
static isAuthorized() { return status === 2; }
Computes string for signing request See https://www.last.fm/api/authspec#8
isAuthorized
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
static isAuthRequested() { return !(status === 0); }
Computes string for signing request See https://www.last.fm/api/authspec#8
isAuthRequested
javascript
listen1/listen1_chrome_extension
js/lastfm.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/lastfm.js
MIT
constructor() { this.playlist = []; this._random_playlist = []; this.index = -1; this._loop_mode = 0; this._media_uri_list = {}; this.playedFrom = 0; this.mode = 'background'; this.skipTime = 15; }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
constructor
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
setMode(newMode) { this.mode = newMode; }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
setMode
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
setRefreshRate(rate = 10) { clearInterval(this.refreshTimer); this.refreshTimer = setInterval(() => { if (this.playing) { this.sendFrameUpdate(); } }, 1000 / rate); }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
setRefreshRate
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
get currentAudio() { return this.playlist[this.index]; }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
currentAudio
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
get currentHowl() { return this.currentAudio && this.currentAudio.howl; }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
currentHowl
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
get playing() { return this.currentHowl ? this.currentHowl.playing() : false; }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
playing
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
get muted() { return !!Howler._muted; }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
muted
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
insertAudio(audio, idx) { if (this.playlist.find((i) => audio.id === i.id)) return; const audioData = { ...audio, disabled: false, // avoid first time load block howl: null, }; if (idx) { this.playlist.splice(idx, 0, [audio]); } else { this.playlist.push(audioData); } this.sendPlaylistEvent(); this.sendLoadEvent(); }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
insertAudio
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
static array_move(arr, old_index, new_index) { // https://stackoverflow.com/questions/5306680/move-an-array-element-from-one-array-position-to-another if (new_index >= arr.length) { let k = new_index - arr.length + 1; while (k > 0) { k -= 1; arr.push(undefined); } } arr.splice(new_index, 0, arr.splice(old_index, 1)[0]); return arr; // for testing }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
array_move
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
insertAudioByDirection(audio, to_audio, direction) { const originTrack = this.playlist[this.index]; const index = this.playlist.findIndex((i) => i.id === audio.id); let insertIndex = this.playlist.findIndex((i) => i.id === to_audio.id); if (index === insertIndex) { return; } if (insertIndex > index) { insertIndex -= 1; } const offset = direction === 'top' ? 0 : 1; this.playlist = Player.array_move( this.playlist, index, insertIndex + offset ); const foundOriginTrackIndex = this.playlist.findIndex( (i) => i.id === originTrack.id ); if (foundOriginTrackIndex >= 0) { this.index = foundOriginTrackIndex; } this.sendPlaylistEvent(); this.sendLoadEvent(); }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
insertAudioByDirection
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
removeAudio(idx) { if (!this.playlist[idx]) { return; } // restore playing status before change const isPlaying = this.playing; const { id: trackId } = this.currentAudio; if (isPlaying && this.playlist[idx].id === trackId) { this.pause(); } this.playlist.splice(idx, 1); const newIndex = this.playlist.findIndex((i) => i.id === trackId); if (newIndex >= 0) { this.index = newIndex; } else { // current playing is deleted if (idx >= this.playlist.length) { this.index = this.playlist.length - 1; } else { this.index = idx; } if (isPlaying) { this.play(); } } this.sendPlaylistEvent(); this.sendLoadEvent(); }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
removeAudio
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
appendAudioList(list) { if (!Array.isArray(list)) { return; } list.forEach((audio) => { this.insertAudio(audio); }); }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
appendAudioList
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
clearPlaylist() { this.stopAll(); // stop the loadded track before remove list this.playlist = []; Howler.unload(); this.sendPlaylistEvent(); this.sendLoadEvent(); }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
clearPlaylist
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
stopAll() { this.playlist.forEach((i) => { if (i.howl) { i.howl.stop(); } }); }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
stopAll
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
setNewPlaylist(list) { if (list.length) { // stop current this.stopAll(); Howler.unload(); this.playlist = list.map((audio) => ({ ...audio, howl: null, })); // TODO: random mode need random choose first song to load this.index = 0; this.load(0); } this.sendPlaylistEvent(); }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
setNewPlaylist
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
playById(id) { const idx = this.playlist.findIndex((audio) => audio.id === id); this.play(idx); }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
playById
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
loadById(id) { const idx = this.playlist.findIndex((audio) => audio.id === id); this.load(idx); }
Player class containing the state of our playlist and where we are in it. Includes all methods for playing, skipping, updating the display, etc. @param {Array} playlist Array of objects with playlist song details ({title, file, howl}).
loadById
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
play(idx) { this.load(idx); const data = this.playlist[this.index]; if (!data.howl || !this._media_uri_list[data.id]) { this.retrieveMediaUrl(this.index, true); } else { this.finishLoad(this.index, true); } }
Play a song in the playlist. @param {Number} index Index of the song in the playlist (leave empty to play the first or current).
play
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
retrieveMediaUrl(index, playNow) { const msg = { type: 'BG_PLAYER:RETRIEVE_URL', data: { ...this.playlist[index], howl: undefined, index, playNow, }, }; MediaService.bootstrapTrack( msg.data, (bootinfo) => { msg.type = 'BG_PLAYER:RETRIEVE_URL_SUCCESS'; msg.data = { ...msg.data, ...bootinfo }; this.playlist[index].bitrate = bootinfo.bitrate; this.playlist[index].platform = bootinfo.platform; this.setMediaURI(msg.data.url, msg.data.id); this.setAudioDisabled(false, msg.data.index); this.finishLoad(msg.data.index, playNow); playerSendMessage(this.mode, msg); }, () => { msg.type = 'BG_PLAYER:RETRIEVE_URL_FAIL'; this.setAudioDisabled(true, msg.data.index); playerSendMessage(this.mode, msg); this.skip('next'); } ); }
Play a song in the playlist. @param {Number} index Index of the song in the playlist (leave empty to play the first or current).
retrieveMediaUrl
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
load(idx) { let index = typeof idx === 'number' ? idx : this.index; if (index < 0) return; if (!this.playlist[index]) { index = 0; } // stop when load new track to avoid multiple songs play in same time if (index !== this.index) { Howler.unload(); } this.index = index; this.sendLoadEvent(); }
Load a song from the playlist. @param {Number} index Index of the song in the playlist (leave empty to load the first or current).
load
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
onload() { self.currentAudio.disabled = false; self.sendPlayingEvent('Loaded'); }
Load a song from the playlist. @param {Number} index Index of the song in the playlist (leave empty to load the first or current).
onload
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
onend() { switch (self.loop_mode) { case 2: self.skip('random'); break; case 1: self.play(); break; case 0: default: self.skip('next'); break; } self.sendPlayingEvent('Ended'); }
Load a song from the playlist. @param {Number} index Index of the song in the playlist (leave empty to load the first or current).
onend
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
onpause() { navigator.mediaSession.playbackState = 'paused'; self.sendPlayingEvent('Paused'); }
Load a song from the playlist. @param {Number} index Index of the song in the playlist (leave empty to load the first or current).
onpause
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
onloaderror(id, err) { playerSendMessage(this.mode, { type: 'BG_PLAYER:PLAY_FAILED', data: err, }); self.currentAudio.disabled = true; self.sendPlayingEvent('err'); self.currentHowl.unload(); data.howl = null; delete self._media_uri_list[data.id]; }
Load a song from the playlist. @param {Number} index Index of the song in the playlist (leave empty to load the first or current).
onloaderror
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
onplayerror(id, err) { playerSendMessage(this.mode, { type: 'BG_PLAYER:PLAY_FAILED', data: err, }); self.currentAudio.disabled = true; self.sendPlayingEvent('err'); }
Load a song from the playlist. @param {Number} index Index of the song in the playlist (leave empty to load the first or current).
onplayerror
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
skip(direction) { Howler.unload(); // Get the next track based on the direction of the track. const nextIndexFn = (idx) => { const l = this.playlist.length; const random_mode = this._loop_mode === 2 || direction === 'random'; let rdx = idx; if (random_mode) { if (this._random_playlist.length / 2 !== l) { // construction random playlist const a = Array.from({ length: l }, (_v, i) => i); for (let i = 0; i < l; i += 1) { const e = l - i - 1; const s = Math.floor(Math.random() * e); const t = a[s]; a[s] = a[e]; a[e] = t; // lookup table a[t + l] = e; } this._random_playlist = a; } rdx = this._random_playlist[idx + l]; } else if (this._random_playlist.length !== 0) { // clear random playlist this._random_playlist = []; } if (direction === 'prev') { if (rdx === 0) rdx = l; rdx -= 1; } else { rdx += 1; } const result = random_mode ? this._random_playlist[rdx % l] : rdx % l; return result; }; this.index = nextIndexFn(this.index); let tryCount = 0; while (tryCount < this.playlist.length) { if (!this.playlist[this.index].disabled) { this.play(this.index); return; } this.index = nextIndexFn(this.index); tryCount += 1; } playerSendMessage(this.mode, { type: 'BG_PLAYER:RETRIEVE_URL_FAIL_ALL', }); this.sendLoadEvent(); }
Skip to the next or previous track. @param {String} direction 'next' or 'prev'.
skip
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
nextIndexFn = (idx) => { const l = this.playlist.length; const random_mode = this._loop_mode === 2 || direction === 'random'; let rdx = idx; if (random_mode) { if (this._random_playlist.length / 2 !== l) { // construction random playlist const a = Array.from({ length: l }, (_v, i) => i); for (let i = 0; i < l; i += 1) { const e = l - i - 1; const s = Math.floor(Math.random() * e); const t = a[s]; a[s] = a[e]; a[e] = t; // lookup table a[t + l] = e; } this._random_playlist = a; } rdx = this._random_playlist[idx + l]; } else if (this._random_playlist.length !== 0) { // clear random playlist this._random_playlist = []; } if (direction === 'prev') { if (rdx === 0) rdx = l; rdx -= 1; } else { rdx += 1; } const result = random_mode ? this._random_playlist[rdx % l] : rdx % l; return result; }
Skip to the next or previous track. @param {String} direction 'next' or 'prev'.
nextIndexFn
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
nextIndexFn = (idx) => { const l = this.playlist.length; const random_mode = this._loop_mode === 2 || direction === 'random'; let rdx = idx; if (random_mode) { if (this._random_playlist.length / 2 !== l) { // construction random playlist const a = Array.from({ length: l }, (_v, i) => i); for (let i = 0; i < l; i += 1) { const e = l - i - 1; const s = Math.floor(Math.random() * e); const t = a[s]; a[s] = a[e]; a[e] = t; // lookup table a[t + l] = e; } this._random_playlist = a; } rdx = this._random_playlist[idx + l]; } else if (this._random_playlist.length !== 0) { // clear random playlist this._random_playlist = []; } if (direction === 'prev') { if (rdx === 0) rdx = l; rdx -= 1; } else { rdx += 1; } const result = random_mode ? this._random_playlist[rdx % l] : rdx % l; return result; }
Skip to the next or previous track. @param {String} direction 'next' or 'prev'.
nextIndexFn
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
set loop_mode(input) { const LOOP_MODE = { all: 0, one: 1, shuffle: 2, }; let myMode = 0; if (typeof input === 'string') { myMode = LOOP_MODE[input]; } else { myMode = input; } if (!Object.values(LOOP_MODE).includes(myMode)) { return; } this._loop_mode = myMode; }
Skip to the next or previous track. @param {String} direction 'next' or 'prev'.
loop_mode
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
get loop_mode() { return this._loop_mode; }
Skip to the next or previous track. @param {String} direction 'next' or 'prev'.
loop_mode
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
set volume(val) { // Update the global volume (affecting all Howls). if (typeof val === 'number') { Howler.volume(val); this.sendVolumeEvent(); this.sendFrameUpdate(); } }
Set the volume and update the volume slider display. @param {Number} val Volume between 0 and 1.
volume
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
get volume() { return Howler.volume(); }
Set the volume and update the volume slider display. @param {Number} val Volume between 0 and 1.
volume
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
adjustVolume(inc) { this.volume = inc ? Math.min(this.volume + 0.1, 1) : Math.max(this.volume - 0.1, 0); this.sendVolumeEvent(); this.sendFrameUpdate(); }
Set the volume and update the volume slider display. @param {Number} val Volume between 0 and 1.
adjustVolume
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
mute() { Howler.mute(true); playerSendMessage(this.mode, { type: 'BG_PLAYER:MUTE', data: true, }); }
Set the volume and update the volume slider display. @param {Number} val Volume between 0 and 1.
mute
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
unmute() { Howler.mute(false); playerSendMessage(this.mode, { type: 'BG_PLAYER:MUTE', data: false, }); }
Set the volume and update the volume slider display. @param {Number} val Volume between 0 and 1.
unmute
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
seek(per) { if (!this.currentHowl) return; // Get the Howl we want to manipulate. const audio = this.currentHowl; // Convert the percent into a seek position. // if (audio.playing()) { // } audio.seek(audio.duration() * per); }
Seek to a new position in the currently playing track. @param {Number} per Percentage through the song to skip.
seek
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
seekTime(seconds) { if (!this.currentHowl) return; const audio = this.currentHowl; audio.seek(seconds); }
Seek to a new position in the currently playing track. @param {Number} seconds Seconds through the song to skip.
seekTime
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
static formatTime(secs) { const minutes = Math.floor(secs / 60) || 0; const seconds = secs - minutes * 60 || 0; return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`; }
Format the time from seconds to M:SS. @param {Number} secs Seconds to format. @return {String} Formatted time.
formatTime
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
setMediaURI(uri, url) { if (url) { this._media_uri_list[url] = uri; } }
Format the time from seconds to M:SS. @param {Number} secs Seconds to format. @return {String} Formatted time.
setMediaURI
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
setAudioDisabled(disabled, idx) { if (this.playlist[idx]) { this.playlist[idx].disabled = disabled; } }
Format the time from seconds to M:SS. @param {Number} secs Seconds to format. @return {String} Formatted time.
setAudioDisabled
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
async sendFrameUpdate() { const data = { id: this.currentAudio ? this.currentAudio.id : 0, duration: this.currentHowl ? this.currentHowl.duration() : 0, pos: this.currentHowl ? this.currentHowl.seek() : 0, playedFrom: this.playedFrom, playing: this.playing, }; if ('setPositionState' in navigator.mediaSession) { navigator.mediaSession.setPositionState({ duration: this.currentHowl ? this.currentHowl.duration() : 0, playbackRate: this.currentHowl ? this.currentHowl.rate() : 1, position: this.currentHowl ? this.currentHowl.seek() : 0, }); } playerSendMessage(this.mode, { type: 'BG_PLAYER:FRAME_UPDATE', data, }); }
Format the time from seconds to M:SS. @param {Number} secs Seconds to format. @return {String} Formatted time.
sendFrameUpdate
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
async sendPlayingEvent(reason = 'UNKNOWN') { playerSendMessage(this.mode, { type: 'BG_PLAYER:PLAY_STATE', data: { isPlaying: this.playing, reason, }, }); }
Format the time from seconds to M:SS. @param {Number} secs Seconds to format. @return {String} Formatted time.
sendPlayingEvent
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
async sendLoadEvent() { playerSendMessage(this.mode, { type: 'BG_PLAYER:LOAD', data: { currentPlaying: { ...this.currentAudio, howl: undefined, }, playlist: { index: this.index, length: this.playlist.length, }, }, }); }
Format the time from seconds to M:SS. @param {Number} secs Seconds to format. @return {String} Formatted time.
sendLoadEvent
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
async sendVolumeEvent() { playerSendMessage(this.mode, { type: 'BG_PLAYER:VOLUME', data: this.volume * 100, }); }
Format the time from seconds to M:SS. @param {Number} secs Seconds to format. @return {String} Formatted time.
sendVolumeEvent
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
async sendPlaylistEvent() { playerSendMessage(this.mode, { type: 'BG_PLAYER:PLAYLIST', data: this.playlist.map((audio) => ({ ...audio, howl: undefined })), }); }
Format the time from seconds to M:SS. @param {Number} secs Seconds to format. @return {String} Formatted time.
sendPlaylistEvent
javascript
listen1/listen1_chrome_extension
js/player_thread.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/player_thread.js
MIT
unlock = function (e) { // Create a pool of unlocked HTML5 Audio objects that can // be used for playing sounds without user interaction. HTML5 // Audio objects must be individually unlocked, as opposed // to the WebAudio API which only needs a single activation. // This must occur before WebAudio setup or the source.onended // event will not fire. while (self._html5AudioPool.length < self.html5PoolSize) { try { var audioNode = new Audio(); // Mark this Audio object as unlocked to ensure it can get returned // to the unlocked pool when released. audioNode._unlocked = true; // Add the audio node to the pool. self._releaseHtml5Audio(audioNode); } catch (e) { self.noAudio = true; break; } } // Loop through any assigned audio nodes and unlock them. for (var i = 0; i < self._howls.length; i++) { if (!self._howls[i]._webAudio) { // Get all of the sounds in this Howl group. var ids = self._howls[i]._getSoundIds(); // Loop through all sounds and unlock the audio nodes. for (var j = 0; j < ids.length; j++) { var sound = self._howls[i]._soundById(ids[j]); if (sound && sound._node && !sound._node._unlocked) { sound._node._unlocked = true; sound._node.load(); } } } } // Fix Android can not play in suspend state. self._autoResume(); // Create an empty buffer. var source = self.ctx.createBufferSource(); source.buffer = self._scratchBuffer; source.connect(self.ctx.destination); // Play the empty buffer. if (typeof source.start === 'undefined') { source.noteOn(0); } else { source.start(0); } // Calling resume() on a stack initiated by user gesture is what actually unlocks the audio on Android Chrome >= 55. if (typeof self.ctx.resume === 'function') { self.ctx.resume(); } // Setup a timeout to check that we are unlocked on the next event loop. source.onended = function () { source.disconnect(0); // Update the unlocked state and prevent this check from happening again. self._audioUnlocked = true; // Remove the touch start listener. document.removeEventListener('touchstart', unlock, true); document.removeEventListener('touchend', unlock, true); document.removeEventListener('click', unlock, true); document.removeEventListener('keydown', unlock, true); // Let all sounds know that audio has been unlocked. for (var i = 0; i < self._howls.length; i++) { self._howls[i]._emit('unlock'); } }; }
Some browsers/devices will only allow audio to be played after a user interaction. Attempt to automatically unlock audio on the first user interaction. Concept from: http://paulbakaus.com/tutorials/html5/web-audio-on-ios/ @return {Howler}
unlock
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
handleSuspension = function () { self.state = 'suspended'; if (self._resumeAfterSuspend) { delete self._resumeAfterSuspend; self._autoResume(); } }
Automatically suspend the Web Audio AudioContext after no sound has played for 30 seconds. This saves processing/energy and fixes various browser-specific bugs with audio getting stuck. @return {Howler}
handleSuspension
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
Howl = function (o) { var self = this; // Throw an error if no source is provided. if (!o.src || o.src.length === 0) { console.error( 'An array of source files must be passed with any new Howl.' ); return; } self.init(o); }
Create an audio group controller. @param {Object} o Passed in properties for this group.
Howl
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
setParams = function () { sound._paused = false; sound._seek = seek; sound._start = start; sound._stop = stop; sound._loop = !!(sound._loop || self._sprite[sprite][2]); }
Play a sound or resume previous playback. @param {String/Number} sprite Sprite name for sprite playback or sound id to continue previous. @param {Boolean} internal Internal Use: true prevents event firing. @return {Number} Sound ID.
setParams
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
playWebAudio = function () { self._playLock = false; setParams(); self._refreshBuffer(sound); // Setup the playback params. var vol = sound._muted || self._muted ? 0 : sound._volume; node.gain.setValueAtTime(vol, Howler.ctx.currentTime); sound._playStart = Howler.ctx.currentTime; // Play the sound using the supported method. if (typeof node.bufferSource.start === 'undefined') { sound._loop ? node.bufferSource.noteGrainOn(0, seek, 86400) : node.bufferSource.noteGrainOn(0, seek, duration); } else { sound._loop ? node.bufferSource.start(0, seek, 86400) : node.bufferSource.start(0, seek, duration); } // Start a new timer if none is present. if (timeout !== Infinity) { self._endTimers[sound._id] = setTimeout( self._ended.bind(self, sound), timeout ); } if (!internal) { setTimeout(function () { self._emit('play', sound._id); self._loadQueue(); }, 0); } }
Play a sound or resume previous playback. @param {String/Number} sprite Sprite name for sprite playback or sound id to continue previous. @param {Boolean} internal Internal Use: true prevents event firing. @return {Number} Sound ID.
playWebAudio
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
playHtml5 = function () { node.currentTime = seek; node.muted = sound._muted || self._muted || Howler._muted || node.muted; node.volume = sound._volume * Howler.volume(); node.playbackRate = sound._rate; // Some browsers will throw an error if this is called without user interaction. try { var play = node.play(); // Support older browsers that don't support promises, and thus don't have this issue. if ( play && typeof Promise !== 'undefined' && (play instanceof Promise || typeof play.then === 'function') ) { // Implements a lock to prevent DOMException: The play() request was interrupted by a call to pause(). self._playLock = true; // Set param values immediately. setParams(); // Releases the lock and executes queued actions. play .then(function () { self._playLock = false; node._unlocked = true; if (!internal) { self._emit('play', sound._id); } else { self._loadQueue(); } }) .catch(function () { self._playLock = false; self._emit( 'playerror', sound._id, 'Playback was unable to start. This is most commonly an issue ' + 'on mobile devices and Chrome where playback was not within a user interaction.' ); // Reset the ended and paused values. sound._ended = true; sound._paused = true; }); } else if (!internal) { self._playLock = false; setParams(); self._emit('play', sound._id); } // Setting rate before playing won't work in IE, so we set it again here. node.playbackRate = sound._rate; // If the node is still paused, then we can assume there was a playback issue. if (node.paused) { self._emit( 'playerror', sound._id, 'Playback was unable to start. This is most commonly an issue ' + 'on mobile devices and Chrome where playback was not within a user interaction.' ); return; } // Setup the end timer on sprites or listen for the ended event. if (sprite !== '__default' || sound._loop) { self._endTimers[sound._id] = setTimeout( self._ended.bind(self, sound), timeout ); } else { self._endTimers[sound._id] = function () { // Fire ended on this audio node. self._ended(sound); // Clear this listener. node.removeEventListener( 'ended', self._endTimers[sound._id], false ); }; node.addEventListener('ended', self._endTimers[sound._id], false); } } catch (err) { self._emit('playerror', sound._id, err); } }
Play a sound or resume previous playback. @param {String/Number} sprite Sprite name for sprite playback or sound id to continue previous. @param {Boolean} internal Internal Use: true prevents event firing. @return {Number} Sound ID.
playHtml5
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
listener = function () { self._state = 'loaded'; // Begin playback. playHtml5(); // Clear this listener. node.removeEventListener(Howler._canPlayEvent, listener, false); }
Play a sound or resume previous playback. @param {String/Number} sprite Sprite name for sprite playback or sound id to continue previous. @param {Boolean} internal Internal Use: true prevents event firing. @return {Number} Sound ID.
listener
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
seekAndEmit = function () { // Restart the playback if the sound was playing. if (playing) { self.play(id, true); } self._emit('seek', id); }
Get/set the seek position of a sound. This method can optionally take 0, 1 or 2 arguments. seek() -> Returns the first sound node's current seek position. seek(id) -> Returns the sound id's current seek position. seek(seek) -> Sets the seek position of the first sound node. seek(seek, id) -> Sets the seek position of passed sound id. @return {Howl/Number} Returns self or the current seek position.
seekAndEmit
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
emitSeek = function () { if (!self._playLock) { seekAndEmit(); } else { setTimeout(emitSeek, 0); } }
Get/set the seek position of a sound. This method can optionally take 0, 1 or 2 arguments. seek() -> Returns the first sound node's current seek position. seek(id) -> Returns the sound id's current seek position. seek(seek) -> Sets the seek position of the first sound node. seek(seek, id) -> Sets the seek position of passed sound id. @return {Howl/Number} Returns self or the current seek position.
emitSeek
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
Sound = function (howl) { this._parent = howl; this.init(); }
Setup the sound object, which each node attached to a Howl group is contained in. @param {Object} howl The Howl parent group.
Sound
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
loadBuffer = function (self) { var url = self._src; // Check if the buffer has already been cached and use it instead. if (cache[url]) { // Set the duration from the cache. self._duration = cache[url].duration; // Load the sound into this Howl. loadSound(self); return; } if (/^data:[^;]+;base64,/.test(url)) { // Decode the base64 data URI without XHR, since some browsers don't support it. var data = atob(url.split(',')[1]); var dataView = new Uint8Array(data.length); for (var i = 0; i < data.length; ++i) { dataView[i] = data.charCodeAt(i); } decodeAudioData(dataView.buffer, self); } else { // Load the buffer from the URL. var xhr = new XMLHttpRequest(); xhr.open(self._xhr.method, url, true); xhr.withCredentials = self._xhr.withCredentials; xhr.responseType = 'arraybuffer'; // Apply any custom headers to the request. if (self._xhr.headers) { Object.keys(self._xhr.headers).forEach(function (key) { xhr.setRequestHeader(key, self._xhr.headers[key]); }); } xhr.onload = function () { // Make sure we get a successful response back. var code = (xhr.status + '')[0]; if (code !== '0' && code !== '2' && code !== '3') { self._emit( 'loaderror', null, 'Failed loading audio file with status: ' + xhr.status + '.' ); return; } decodeAudioData(xhr.response, self); }; xhr.onerror = function () { // If there is an error, switch to HTML5 Audio. if (self._webAudio) { self._html5 = true; self._webAudio = false; self._sounds = []; delete cache[url]; self.load(); } }; safeXhrSend(xhr); } }
Buffer a sound from URL, Data URI or cache and decode to audio source (Web Audio API). @param {Howl} self
loadBuffer
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
safeXhrSend = function (xhr) { try { xhr.send(); } catch (e) { xhr.onerror(); } }
Send the XHR request wrapped in a try/catch. @param {Object} xhr XHR to send.
safeXhrSend
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
decodeAudioData = function (arraybuffer, self) { // Fire a load error if something broke. var error = function () { self._emit('loaderror', null, 'Decoding audio data failed.'); }; // Load the sound on success. var success = function (buffer) { if (buffer && self._sounds.length > 0) { cache[self._src] = buffer; loadSound(self, buffer); } else { error(); } }; // Decode the buffer into an audio source. if ( typeof Promise !== 'undefined' && Howler.ctx.decodeAudioData.length === 1 ) { Howler.ctx.decodeAudioData(arraybuffer).then(success).catch(error); } else { Howler.ctx.decodeAudioData(arraybuffer, success, error); } }
Decode audio data from an array buffer. @param {ArrayBuffer} arraybuffer The audio data. @param {Howl} self
decodeAudioData
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
error = function () { self._emit('loaderror', null, 'Decoding audio data failed.'); }
Decode audio data from an array buffer. @param {ArrayBuffer} arraybuffer The audio data. @param {Howl} self
error
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
success = function (buffer) { if (buffer && self._sounds.length > 0) { cache[self._src] = buffer; loadSound(self, buffer); } else { error(); } }
Decode audio data from an array buffer. @param {ArrayBuffer} arraybuffer The audio data. @param {Howl} self
success
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
loadSound = function (self, buffer) { // Set the duration. if (buffer && !self._duration) { self._duration = buffer.duration; } // Setup a sprite if none is defined. if (Object.keys(self._sprite).length === 0) { self._sprite = { __default: [0, self._duration * 1000] }; } // Fire the loaded event. if (self._state !== 'loaded') { self._state = 'loaded'; self._emit('load'); self._loadQueue(); } }
Sound is now loaded, so finish setting everything up and fire the loaded event. @param {Howl} self @param {Object} buffer The decoded buffer sound source.
loadSound
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
setupAudioContext = function () { // If we have already detected that Web Audio isn't supported, don't run this step again. if (!Howler.usingWebAudio) { return; } // Check if we are using Web Audio and setup the AudioContext if we are. try { if (typeof AudioContext !== 'undefined') { Howler.ctx = new AudioContext(); } else if (typeof webkitAudioContext !== 'undefined') { Howler.ctx = new webkitAudioContext(); } else { Howler.usingWebAudio = false; } } catch (e) { Howler.usingWebAudio = false; } // If the audio context creation still failed, set using web audio to false. if (!Howler.ctx) { Howler.usingWebAudio = false; } // Check if a webview is being used on iOS8 or earlier (rather than the browser). // If it is, disable Web Audio as it causes crashing. var iOS = /iP(hone|od|ad)/.test( Howler._navigator && Howler._navigator.platform ); var appVersion = Howler._navigator && Howler._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/); var version = appVersion ? parseInt(appVersion[1], 10) : null; if (iOS && version && version < 9) { var safari = /safari/.test( Howler._navigator && Howler._navigator.userAgent.toLowerCase() ); if (Howler._navigator && !safari) { Howler.usingWebAudio = false; } } // Create and expose the master GainNode when using Web Audio (useful for plugins or advanced usage). if (Howler.usingWebAudio) { Howler.masterGain = typeof Howler.ctx.createGain === 'undefined' ? Howler.ctx.createGainNode() : Howler.ctx.createGain(); Howler.masterGain.gain.setValueAtTime( Howler._muted ? 0 : Howler._volume, Howler.ctx.currentTime ); Howler.masterGain.connect(Howler.ctx.destination); } // Re-run the setup on Howler. Howler._setup(); }
Setup the audio context when available, or switch to HTML5 Audio mode.
setupAudioContext
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
setupPanner = function (sound, type) { type = type || 'spatial'; // Create the new panner node. if (type === 'spatial') { sound._panner = Howler.ctx.createPanner(); sound._panner.coneInnerAngle = sound._pannerAttr.coneInnerAngle; sound._panner.coneOuterAngle = sound._pannerAttr.coneOuterAngle; sound._panner.coneOuterGain = sound._pannerAttr.coneOuterGain; sound._panner.distanceModel = sound._pannerAttr.distanceModel; sound._panner.maxDistance = sound._pannerAttr.maxDistance; sound._panner.refDistance = sound._pannerAttr.refDistance; sound._panner.rolloffFactor = sound._pannerAttr.rolloffFactor; sound._panner.panningModel = sound._pannerAttr.panningModel; if (typeof sound._panner.positionX !== 'undefined') { sound._panner.positionX.setValueAtTime( sound._pos[0], Howler.ctx.currentTime ); sound._panner.positionY.setValueAtTime( sound._pos[1], Howler.ctx.currentTime ); sound._panner.positionZ.setValueAtTime( sound._pos[2], Howler.ctx.currentTime ); } else { sound._panner.setPosition(sound._pos[0], sound._pos[1], sound._pos[2]); } if (typeof sound._panner.orientationX !== 'undefined') { sound._panner.orientationX.setValueAtTime( sound._orientation[0], Howler.ctx.currentTime ); sound._panner.orientationY.setValueAtTime( sound._orientation[1], Howler.ctx.currentTime ); sound._panner.orientationZ.setValueAtTime( sound._orientation[2], Howler.ctx.currentTime ); } else { sound._panner.setOrientation( sound._orientation[0], sound._orientation[1], sound._orientation[2] ); } } else { sound._panner = Howler.ctx.createStereoPanner(); sound._panner.pan.setValueAtTime(sound._stereo, Howler.ctx.currentTime); } sound._panner.connect(sound._node); // Update the connections. if (!sound._paused) { sound._parent.pause(sound._id, true).play(sound._id, true); } }
Create a new panner node and save it on the sound. @param {Sound} sound Specific sound to setup panning on. @param {String} type Type of panner to create: 'stereo' or 'spatial'.
setupPanner
javascript
listen1/listen1_chrome_extension
js/vendor/howler.core.min.js
https://github.com/listen1/listen1_chrome_extension/blob/master/js/vendor/howler.core.min.js
MIT
function uBlockOrigin_add() { js_adsRemove(uBlockOrigin.chn0abortcurrentscript); js_adsRemove(uBlockOrigin.chn0setconstant); js_adsRemove(uBlockOrigin.abortcurrentscript); js_adsRemove(uBlockOrigin.abortcurrentscript); js_adsRemove(uBlockOrigin.abortcurrentscript); js_adsRemove(uBlockOrigin.abortcurrentscript); js_adsRemove(uBlockOrigin.abortonpropertyread); js_adsRemove(uBlockOrigin.abortonpropertywrite); js_adsRemove(uBlockOrigin.abortonstacktrace); js_adsRemove(uBlockOrigin.addEventListenerdefuser); js_adsRemove(uBlockOrigin.alertbuster); js_adsRemove(uBlockOrigin.cookieremover); js_adsRemove(uBlockOrigin.disablenewtablinks); js_adsRemove(uBlockOrigin.evaldataprune); js_adsRemove(uBlockOrigin.jsonprune); js_adsRemove(uBlockOrigin.m3uprune); js_adsRemove(uBlockOrigin.nanosetIntervalbooster); js_adsRemove(uBlockOrigin.nanosetTimeoutbooster); js_adsRemove(uBlockOrigin.noevalif); js_adsRemove(uBlockOrigin.nofetchif); js_adsRemove(uBlockOrigin.norequestAnimationFrameif); js_adsRemove(uBlockOrigin.nosetIntervalif); js_adsRemove(uBlockOrigin.nosetTimeoutif); js_adsRemove(uBlockOrigin.nowebrtc); js_adsRemove(uBlockOrigin.nowindowopenif); js_adsRemove(uBlockOrigin.noxhrif); js_adsRemove(uBlockOrigin.refreshdefuser); js_adsRemove(uBlockOrigin.removeattr); js_adsRemove(uBlockOrigin.removeclass); js_adsRemove(uBlockOrigin.removenodetext); js_adsRemove(uBlockOrigin.replacenodetext); js_adsRemove(uBlockOrigin.setattr); js_adsRemove(uBlockOrigin.setconstant); js_adsRemove(uBlockOrigin.setcookie); js_adsRemove(uBlockOrigin.setlocalstorageitem); js_adsRemove(uBlockOrigin.spoofcss); js_adsRemove(uBlockOrigin.trustedsetconstant); js_adsRemove(uBlockOrigin.trustedsetcookie); js_adsRemove(uBlockOrigin.windowcloseif); js_adsRemove(uBlockOrigin.xmlprune); }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
uBlockOrigin_add
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function adblock4limbo_svg_switch_by_width() { //const userAgent = navigator.userAgent.toLowerCase(); const window_innerWidth = window.innerWidth; if (window_innerWidth <= 920) { //if (/\b(android|iphone|ipad|ipod)\b/i.test(userAgent)) { var size = '54px'; return size; } else { var size = '75px'; return size; } }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
adblock4limbo_svg_switch_by_width
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function pornhub_interstitialPass() { const ele_skip = "[onclick*='clearModalCookie']" const exist = document.querySelectorAll(ele_skip); if (document.querySelectorAll(ele_skip).length > 0) { const href = exist[1].href; window.location = href; } }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
pornhub_interstitialPass
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function _18comic_adsRemove() { document.cookie = "cover=1"; document.cookie = "shunt=1"; document.cookie = "guide=1"; }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
_18comic_adsRemove
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function missAv_adsRemove() { document.cookie = "_gat_UA-177787578-7; expires=Thu, 01 Jan 1970 00:00:00 GMT"; }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
missAv_adsRemove
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function set_cookie(name, value) { document.cookie = name + '=' + value + '; Path=/;'; }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
set_cookie
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function selector_adsRemove(selector, time) { var i; setTimeout(() => { var nodelists = document.querySelectorAll(selector) for (i = 0; i < nodelists.length; i++) { //nodelists[i].remove(); nodelists[i].style = "display: none !important;" } }, time) }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
selector_adsRemove
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function tag_adsRemove(tagname, keyword) { var i; var tag = document.getElementsByTagName(tagname); for (i = 0; i < tag.length; i++) { if (tag[i].src.indexOf(keyword) !== -1) { tag[i].remove() } if (tag[i].innerHTML.indexOf(keyword) !== -1) { tag[i].remove() } } }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
tag_adsRemove
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function cloudflare_captchaBypass() { var title = document.title; if (title.search("Cloudflare") !== -1 || title.search("Attention") !== -1) { window.location.reload(); console.log("captchaBypass done;") }; }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
cloudflare_captchaBypass
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function div_ad_missav() { let div_ad = document.querySelectorAll('div.mx-auto[style]') for (i = 0; i < div_ad.length; i++) { if (div_ad[i].querySelectorAll('[target=\'_blank\']').length >= 1) { div_ad[i].style.height = '0px' } } }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
div_ad_missav
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function video_loopPlay(x) { if (x === 'loop') { intval = window.setInterval(missAv_playbutton, 1000) } else if (x === 'pause') { if (intval) { timerlist.forEach((item, index) => { clearInterval(item); }) video_pause(); } } }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
video_loopPlay
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function fullscreen() { const fullScreen = document.querySelector('button[data-plyr=\'fullscreen\']'); fullScreen.click() //fullScreen.requestFullscreen(); //const fullScreen = document.querySelector('div.plyr__video-wrapper'); //fullScreen.requestFullscreen(); }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
fullscreen
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT
function addListener(selector, funx) { setTimeout(() => { var ele = document.querySelectorAll(selector); for (let index = 0; index < ele.length; index++) { ele[index].addEventListener("click", funx, false) } }, 1000) }
--------------------------- Author: limbopro View: https://limbopro.com/archives/12904.html ---------------------------
addListener
javascript
limbopro/Adblock4limbo
Adguard/Adblock4limbo.user.10.15.2023.js
https://github.com/limbopro/Adblock4limbo/blob/master/Adguard/Adblock4limbo.user.10.15.2023.js
MIT