JavaScript
8
Вклад в тег
<link rel="icon" href="/favicons/favicon.ico" type="image/x-icon">
function setFavicon(url) {
var link = document.querySelector('link[rel=icon]')
link.setAttribute('href', url)
}
function startAnimation(icons, initial) {
initial = initial === undefined ? 0 : initial
setFavicon(icons[initial])
var next = icons.length <= initial + 1 ? 0 : initial + 1
setTimeout(function () {
startAnimation(icons, next)
}, 1000)
}
var icons = [
'https://habr.com/images/favicon-32x32.png',
'https://nextjs.org/static/favicon/favicon.ico'
]
startAnimation(icons)
afterChange
afterChange
оно дальше передается в вверх 1-му слайду (reviews-slider) так как первый слайд подписан на события init reInit afterChange
счетчик изменяетсяafterChange
дальше$('.reviews-gallery-slider').slick(
...
).on('afterChange', function(event, slick){
event.stopPropagation(); // <-
...
});
$examplesSlider2.on('init reInit afterChange', function (event, slick, currentSlide, nextSlide) {
// check
if (!event.target.classList.value.includes('reviews-slider')) {
return;
}
...
});
const User = require('./models/User')
const facebookStrategy = require('./passports/facebook')
const googleStrategy = require('./passports/google')
module.exports = function (passport) {
passport.serializeUser(function (user, done) {
return done(null, user.id)
})
passport.deserializeUser(async (id, done) => {
try {
const user = await User.findOne({ id })
done(null, user)
} catch (err) {
done(err)
}
})
passport.use(facebookStrategy())
passport.use(googleStrategy())
}
const assert = require('assert')
const FacebookStrategy = require('passport-facebook').Strategy
const User = require('../models/User')
assert(process.env.FACEBOOK_APP_ID)
assert(process.env.FACEBOOK_APP_SECRET)
assert(process.env.APP_URL)
module.exports = () => {
return new FacebookStrategy({
clientID: process.env.FACEBOOK_APP_ID,
clientSecret: process.env.FACEBOOK_APP_SECRET,
callbackURL: `${process.env.APP_URL}/auth/facebook/callback`
},
async (accessToken, refreshToken, profile, done) => {
try {
const user = await User.findOrCreate({ facebook_id: profile.id }, {
facebook_id: profile.id,
name: profile.displayName,
provider: 'facebook'
})
return done(null, user.toJSON())
} catch (err) {
return done(err)
}
})
}
app.get('/auth/facebook', passport.authenticate('facebook'))
app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login' }, (req, res) => {
const user = req.user;
const payload = {
id: user._id,
email: user.email,
};
jwt.sign(payload, secret, {expiresIn: 3600}, (err, token) => {
if (err) {
res.status(500).send({
error: 'Error signing token',
raw: err,
});
}
// Отдаем html
res.send(`
<script>
localStorage.setItem('token', '${`Bearer ${token}`}');
localtion.href = '/'
</script>
`);
});
})
const passport = require('passport')
require('./passport')(passport)
app.use(passport.initialize())
// Пример
// Перехват запроса, и блокирование если есть совпадения с url
chrome.webRequest.onBeforeRequest.addListener(
function(details) { return {cancel: true}; },
{urls: ["*://www.domain.com/*"]},
["blocking"]);