Update file load and save + parent selection get and set + debug bookmarklet compiler + frame view image (only)

This commit is contained in:
devingfx 2018-07-09 03:06:41 +02:00
parent cb62ddab67
commit 4f7fd380d4
4 changed files with 17 additions and 7 deletions

View File

@ -28,7 +28,7 @@
<menu>
<button select-get title="Get selected text on the page"
onclick="$text.value = getParentSelection()">
onclick="$text.value = CC.bin2buffer(getParentSelection())">
<i class="fas fa-align-left"></i>
<i class="fas fa-caret-down"></i>
</button>
@ -44,7 +44,7 @@
<button open title="Load a file from disk"
onclick="$`[type=file]`.click()">
<i class="far fa-folder-open"></i>
<input type="file" onchange="read(this.files[0]).then( s=> $text.value = s ); $filename.value = this.files[0].name"/>
<input type="file" onchange="read(this.files[0]).then( a=> $text.value = a ); $filename.value = this.files[0].name"/>
</button>
<input filename type="text" eo:placeHolder="Filo nami" en:placeHolder="File name" fr:placeHolder="Nom du fichier"/>
@ -54,7 +54,7 @@
<i class="far fa-save"></i>
</button>
<button select-set en:title="Replace selected text on the page" fr:title="Remplacer la séléction" eo:title="Sovargi al disko"
onclick="setParentSelection( $text.value )">
onclick="setParentSelection( buffer2bin($text.value) )">
<i class="fas fa-align-left"></i>
<i class="fas fa-caret-up"></i>
</button>
@ -102,6 +102,7 @@
position: absolute;
top: 0;
box-sizing: border-box;
background: white;
}
:host-context([frame]) iframe { display: block; }
button {

8
app.js
View File

@ -7,7 +7,7 @@ const algo = { name: "AES-GCM", iv: Uint8Array.from([120,1,248,135,62,71,87,156,
, $text = $`ui-data`
, $filename = $`[filename]`
opener && document.documentElement.classtList.add('parented')
opener && document.documentElement.classList.add('parented')
// sel=opener.document.getSelection().type=='None'||'Range'
const getParentSelection = ()=> opener && opener.document.getSelection().toString()
@ -127,7 +127,7 @@ const read = file=> new Promise( (ok,ko)=> {
let r = new FileReader()
r.onload = e=> ok( r.result )
r.onerror = e=> ko()
r.readAsText( file )
r.readAsArrayBuffer( file )
})
@ -172,8 +172,8 @@ const bin2utf8 = binstr=> decodeURIComponent(
const buffer2utf8 = buf=> bin2utf8( buffer2bin(buf) )
const utf82bin = str=> encodeURIComponent(str)
// replaces any uri escape sequence, such as %0A,
// with binary escape, such as 0x0A
/* replaces any uri escape sequence, such as %0A, */
/* with binary escape, such as 0x0A */
.replace(/%([0-9A-F]{2})/g, (s,$1)=> String.fromCharCode(parseInt($1, 16)) )
const utf82buffer = str=> bin2buffer(utf82bin(str))

View File

@ -4,13 +4,20 @@ writeFileSync(
'kriptoptlet'
, `javascript:win=window.open('','','titlebar=no,location=no');win.document.write(\`${
readFileSync('kriptopter', 'utf8')
.replace(/\\/g,'\\\\')
.replace(/%0A/g,'\%0A')
.replace(/`/g,'\\`')
.replace(/\$\{/g,'\\${')
.replace(/\n/g,'\\n')
.replace(/\t/g,'\\t')
}\`)`
, 'utf8'
)
/*
javascript:win=window.open('','','titlebar=no,location=no'); fetch('https://git.p2p.legal/dig/kriptopter/raw/master/kriptopter').then(res=>res.text()).then(app=>win.document.write(app) )
*/

2
ui.js
View File

@ -82,6 +82,8 @@ class Data extends UI {
console.log(arguments)
if( newValue != null && this._value && CC['buffer2'+this.type] )
this.shadowRoot.$`textarea`.value = CC['buffer2'+this.type]( this._value )
else if( this.type == 'frame' )
this.shadowRoot.$`iframe`.src = URL.createObjectURL(new File([$text.value],'file.jpg',{type: 'image/jpeg'}) )
}
}