-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
182 additions
and
44 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,3 @@ | ||
.App { | ||
text-align: center; | ||
} | ||
|
||
.App-logo { | ||
animation: App-logo-spin infinite 20s linear; | ||
height: 40vmin; | ||
pointer-events: none; | ||
} | ||
|
||
.App-header { | ||
background-color: #282c34; | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: calc(10px + 2vmin); | ||
color: white; | ||
} | ||
|
||
.App-link { | ||
color: #61dafb; | ||
} | ||
|
||
@keyframes App-logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
.hide { | ||
display: none | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { Component } from 'react'; | ||
import nouns from "../data/nouns.js"; | ||
import verbs from "../data/verbs.js"; | ||
const base64 = require('hi-base64'); | ||
|
||
class EncodeForm extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
base64Text: '', | ||
plainText: '', | ||
encodedText: '' | ||
} | ||
} | ||
|
||
handleEncodedTextChange = (evt) => { | ||
this.setState({ encodedText: evt.target.value }) | ||
} | ||
|
||
handleClick = (evt) => { | ||
this.setState({ plainText: this.decode(this.state.encodedText) }) | ||
} | ||
|
||
decode = (text) => { | ||
const cleanText = text.replace(/,|。/g, '') | ||
const arrCleanText = cleanText.split('') | ||
let result = '' | ||
let subject | ||
let keyword | ||
for(let i =0 ; i< cleanText.length/2; i++){ | ||
keyword = arrCleanText.splice(0,2).join('') | ||
subject = i%3 === 1? verbs: nouns | ||
result += subject.find(({key}) => key == keyword).value | ||
} | ||
this.setState({base64Text:result}) | ||
return base64.decode(result) | ||
} | ||
|
||
render() { | ||
const { encodedText, plainText, base64Text } = this.state | ||
return ( | ||
<div className="container"> | ||
<div className="form-group"> | ||
<textarea rows="10" className="form-control" id="encodedText" type="text" onChange={this.handleEncodedTextChange} value={encodedText} /> | ||
<button className="btn btn-primary my-2" onClick={this.handleClick}>decode</button> | ||
</div> | ||
<div>編碼結果:{base64Text}</div> | ||
<textarea rows="20" className="form-control" type="text" value={plainText} /> | ||
<div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default EncodeForm; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { Component } from 'react'; | ||
import nouns from "../data/nouns.js"; | ||
import verbs from "../data/verbs.js"; | ||
const base64 = require('hi-base64'); | ||
|
||
class EncodeForm extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
base64Text: '', | ||
plainText: '', | ||
encodedText: '' | ||
} | ||
} | ||
|
||
handlePlainTextChange = (evt) => { | ||
this.setState({ plainText: evt.target.value }) | ||
} | ||
|
||
handleClick = (evt) => { | ||
this.setState({ encodedText: this.encode(this.state.plainText) }) | ||
} | ||
|
||
encode = (text) => { | ||
const b64text = base64.encode(text) | ||
this.setState({base64Text:b64text}) | ||
let junk = '' | ||
b64text.split('').forEach((char, index) => { | ||
if (index % 3 === 0) { | ||
const matched = nouns.find(({ value }) => value == char) | ||
junk += matched? matched.key : '$' | ||
} else if (index % 3 === 1) { | ||
const matched = verbs.find(({ value }) => value == char) | ||
junk += matched? matched.key : '$' | ||
} else { | ||
const matched = nouns.find(({ value }) => value == char) | ||
junk += matched? matched.key : '$' | ||
junk += index === b64text.length -1 ? '。': ',' | ||
} | ||
}) | ||
return junk | ||
} | ||
|
||
render() { | ||
const { encodedText, plainText, base64Text } = this.state | ||
return ( | ||
<div className="container"> | ||
<div className="form-group"> | ||
<textarea rows="10" className="form-control" id="plainText" type="text" onChange={this.handlePlainTextChange} value={plainText} /> | ||
<button className="btn btn-primary my-2" onClick={this.handleClick}>encode</button> | ||
</div> | ||
<div>編碼結果:{base64Text}</div> | ||
<textarea rows="20" className="form-control" type="text" value={encodedText} /> | ||
<div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default EncodeForm; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
我們練習廢文,不顧北京反對! | ||
你知道小熊維尼從20190304開始一連串的還願嗎? |
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