Last active
March 9, 2016 14:17
-
-
Save romshark/d43a6caf2ad67b6122b1 to your computer and use it in GitHub Desktop.
Automatically reloads page remembering scroll position
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
#!/bin/bash | |
DIR="./" | |
while true; do | |
echo "listen on $DIR" | |
FILE=$(inotifywait -rqe modify $DIR) | |
echo -e "\t$FILE - compile..." | |
sassc styles/main.sass ./main.css -t compressed | |
echo -e "\tcompiled!" | |
done |
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
document.addEventListener('DOMContentLoaded', function () { | |
var lastPositionY = localStorage.getItem('lastPositionY') | |
var lastPositionX = localStorage.getItem('lastPositionX') | |
if(!lastPositionY) { | |
lastPositionY = 0 | |
} | |
if(!lastPositionX) { | |
lastPositionX = 0 | |
} | |
setTimeout(function() { | |
console.log('lastPositionY:', lastPositionY) | |
console.log('lastPositionX:', lastPositionX) | |
console.log('SCROLL TO:', lastPositionX, lastPositionY) | |
window.scrollTo(lastPositionX, lastPositionY) | |
}, 10) | |
document.onscroll = function() { | |
lastPositionY = window.scrollY | |
lastPositionX = window.scrollX | |
} | |
function onReload() { | |
localStorage.setItem('lastPositionY', lastPositionY) | |
localStorage.setItem('lastPositionX', lastPositionX) | |
window.location.reload() | |
} | |
var socket = io.connect('http://localhost:20000/') | |
socket.on('init', function(data) { | |
console.log('CONNECTED') | |
}) | |
socket.on('reload', function(data) { | |
onReload(data) | |
}) | |
}) |
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
var app = require('express')() | |
var http = require('http').Server(app) | |
var libsocketio = require('socket.io')(http) | |
var libchokidar = require('chokidar') | |
function handle(event, path) { | |
console.log(event, path) | |
libsocketio.emit('reload', { | |
directory: __dirname, | |
triggerEvent: event, | |
changedFile: path | |
}) | |
} | |
libchokidar.watch('.', { | |
ignored: /.*\.lock/ | |
}).on('all', (event, path) => { | |
if(event !== 'add' && event !== 'change') { | |
return | |
} | |
handle(event, path) | |
}) | |
libsocketio.on('connection', function(socket) { | |
console.log('client connected') | |
}) | |
http.listen(20000, function() { | |
console.log('listening on *:20000') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment