Created
May 10, 2013 07:20
-
-
Save rskull/5552912 to your computer and use it in GitHub Desktop.
ファイルを監視し、変更があったら親ウィンドを自動でリロードさせる。
This file contains hidden or 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
// Bookmarklet min | |
javascript:(function(){var e=window.open("","autoloader","width=350, height=450px, location=no");if(e.autoload)e.foucus();else{var t=e.document,n=t.createElement("div"),r=t.createElement("script");n.innerHTML='<style>#main{width:300px;margin:auto}#drop{border:3px solid #555;background:#CCC;height:150px;margin-top:5px}#list{border:dashed #AAA;border-width:1px 0px;margin-top:10px;padding:5px;height:150px;overflow:auto;cursor:default}li:hover{color:#F00}p{text-align:center}</style><div id="main"><input id="file" type="file"><div id="drop"></div><div id="list"><ul></ul></div><p>Copyrigh 2013 AutoLoader Geekz</p></div>',r.innerHTML='(function(e,t){var n=e.autoload,r=function(e){return t.querySelector(e)};autoload={},autoload.FPS=250,autoload.observer={list:{},getFiles:function(e){return e.target.files?e.target.files:e.dataTransfer.files},addFiles:function(e){var t=this.getFiles(e);for(var n=0;n<t.length;n++)this.enable(t[n])},checkPoint:function(e){var t;try{t=e.lastModifiedDate.toString()}catch(n){t=e.getAsBinary()}return t},enable:function(n){var i,s,o=r("#list ul");s=this.checkPoint(n),this.list[n.name]=setInterval(function(){i=autoload.observer.checkPoint(n),s!=i&&(s=autoload.observer.checkPoint(n),e.opener.location.reload())},autoload.FPS);var u=t.createElement("li");u.addEventListener("click",function(){this.parentNode.removeChild(this),autoload.observer.remove(n.name)},!0),o.appendChild(u).innerHTML=n.name},remove:function(e){clearInterval(this.list[e]),delete this.list[e]}},setInterval(function(){(!e.opener||e.opener.closed)&&e.close()},500),input=r("#drop"),list=r("#list ul > li"),input.addEventListener("dragenter",function(e){e.preventDefault()},!0),input.addEventListener("dragover",function(e){e.preventDefault()},!0),input.addEventListener("drop",function(e){autoload.observer.addFiles(e),e.preventDefault()},!0),r("#file").addEventListener("change",function(e){autoload.observer.addFiles(e)},!0)})(window,document)',t.title="Autoloader ver.1.0",t.body.appendChild(n),t.body.appendChild(r)}})(); | |
// Bookmarklet | |
(function () { | |
var al = window.open('', 'autoloader', 'width=350, height=450px, location=no'); | |
if ( al.autoload ) { | |
al.foucus(); | |
} else { | |
var d = al.document, | |
content = d.createElement( 'div' ), | |
script = d.createElement( 'script' ); | |
content.innerHTML = '<style>#main{width:300px;margin:auto}#drop{border:3px solid #555;background:#CCC;height:150px;margin-top:5px}#list{border:dashed #AAA;border-width:1px 0px;margin-top:10px;padding:5px;height:150px;overflow:auto;cursor:default}li:hover{color:#F00}p{text-align:center}</style><div id="main"><input id="file" type="file"><div id="drop"></div><div id="list"><ul></ul></div><p>Copyrigh 2013 AutoLoader Geekz</p></div>'; | |
script.innerHTML = '(function(e,t){var n=e.autoload,r=function(e){return t.querySelector(e)};autoload={},autoload.FPS=250,autoload.observer={list:{},getFiles:function(e){return e.target.files?e.target.files:e.dataTransfer.files},addFiles:function(e){var t=this.getFiles(e);for(var n=0;n<t.length;n++)this.enable(t[n])},checkPoint:function(e){var t;try{t=e.lastModifiedDate.toString()}catch(n){t=e.getAsBinary()}return t},enable:function(n){var i,s,o=r("#list ul");s=this.checkPoint(n),this.list[n.name]=setInterval(function(){i=autoload.observer.checkPoint(n),s!=i&&(s=autoload.observer.checkPoint(n),e.opener.location.reload())},autoload.FPS);var u=t.createElement("li");u.addEventListener("click",function(){this.parentNode.removeChild(this),autoload.observer.remove(n.name)},!0),o.appendChild(u).innerHTML=n.name},remove:function(e){clearInterval(this.list[e]),delete this.list[e]}},setInterval(function(){(!e.opener||e.opener.closed)&&e.close()},500),input=r("#drop"),list=r("#list ul > li"),input.addEventListener("dragenter",function(e){e.preventDefault()},!0),input.addEventListener("dragover",function(e){e.preventDefault()},!0),input.addEventListener("drop",function(e){autoload.observer.addFiles(e),e.preventDefault()},!0),r("#file").addEventListener("change",function(e){autoload.observer.addFiles(e)},!0)})(window,document)'; | |
d.title = 'Autoloader ver.1.0'; | |
d.body.appendChild( content ); | |
d.body.appendChild( script ); | |
} | |
})(); | |
// script.innerHTML -> Main Script | |
(function ( w, d ) { | |
var _al = w.autoload, $ = function ( sec ) { | |
return d.querySelector( sec ); | |
} | |
autoload = {} | |
autoload.FPS = 250; | |
autoload.observer = { | |
list: {}, | |
getFiles: function ( e ) { | |
if ( e.target.files ) { | |
return e.target.files | |
} else { | |
return e.dataTransfer.files | |
} | |
}, | |
addFiles: function ( e ) { | |
var files = this.getFiles( e ); | |
for ( var i = 0; i < files.length; i++ ) { | |
this.enable( files[ i ] ); | |
} | |
}, | |
checkPoint: function ( file ) { | |
var point; | |
try { | |
point = file.lastModifiedDate.toString(); | |
} catch ( e ) { | |
point = file.getAsBinary(); | |
} | |
return point; | |
}, | |
enable: function ( file ) { | |
var now, before, list = $( '#list ul' ); | |
before = this.checkPoint( file ); | |
this.list[ file.name ] = setInterval(function () { | |
now = autoload.observer.checkPoint( file ); | |
if ( before != now ) { | |
before = autoload.observer.checkPoint( file ); | |
w.opener.location.reload() | |
} | |
}, autoload.FPS); | |
var li = d.createElement( "li" ); | |
li.addEventListener('click', function () { | |
this.parentNode.removeChild( this ); | |
autoload.observer.remove( file.name ); | |
}, true); | |
list.appendChild( li ).innerHTML = file.name; | |
}, | |
remove: function ( key ) { | |
clearInterval( this.list[ key ] ); | |
delete this.list[ key ]; | |
} | |
} | |
setInterval(function () { | |
if ( !w.opener || w.opener.closed ) w.close(); | |
}, 500); | |
input = $( "#drop" ), | |
list = $( "#list ul > li" ); | |
input.addEventListener("dragenter", function ( e ) { | |
e.preventDefault() | |
}, true); | |
input.addEventListener("dragover", function ( e ) { | |
e.preventDefault() | |
}, true); | |
input.addEventListener("drop", function ( e ) { | |
autoload.observer.addFiles( e ); | |
e.preventDefault() | |
}, true); | |
$( "#file" ).addEventListener("change", function ( e ) { | |
autoload.observer.addFiles( e ); | |
}, true); | |
})( window, document ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment