Skip to content

Commit

Permalink
bad things
Browse files Browse the repository at this point in the history
  • Loading branch information
amyxjhuang committed Apr 6, 2020
1 parent b0901b5 commit 0111eb6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INLINE_RUNTIME_CHUNK=false;
4 changes: 2 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"scripts": [ "background.js" ],
"persistent": true
},
"content_security_policy": "script-src 'self' 'sha256-CMyYic0d7L0Q9AwjGU0n6buHFRR6bU3TOAe0P7DEJrk'; object-src 'self'"
}
"content_security_policy": "script-src 'self' 'sha256-CMyYic0d7L0Q9AwjGU0n6buHFRR6bU3TOAe0P7DEJrk'"
}
30 changes: 22 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class App extends React.Component {
elapsedminutes: 0,
block: false,
signedIn: false,
websites: []
websites: [],
timerStart: false
}

this.updateMinutes.bind(this);
Expand All @@ -26,18 +27,31 @@ class App extends React.Component {


}


updateMinutes = (minutes) => {
this.setState({elapsedminutes: this.state.elapsedminutes + minutes})
}

blockSites = (details) => {
//return { redirectUrl: "https://www.coolmathgames.com"};
return { redirectUrl: chrome.runtime.getURL("blocked.html") };
}

signIn = () => {
this.setState({signedIn: true});
}

activateTimer = () => {
this.setState({timerStart: true});
this.block()
}

deactivateTimer = () => {
this.setState({timerStart: false});
this.unblock()
}

block() {
chrome.webRequest.onBeforeRequest.addListener(
this.blockSites,
Expand All @@ -46,14 +60,12 @@ class App extends React.Component {
}
makeSiteList() {
const finalList = []
const webList = ["facebook.com", "poptropica.com", "neopets.com"]
for (const link of webList) {
for (const link of this.state.websites) {
finalList.push("*://*."+link+"/*")
}

return finalList;
}

unblock() {
chrome.webRequest.onBeforeRequest.removeListener(this.blockSites);
}
Expand All @@ -64,6 +76,7 @@ class App extends React.Component {


render() {

if (this.state.signedIn) {
return (
<div className="App">
Expand All @@ -72,9 +85,10 @@ class App extends React.Component {

<Reward minutes = {this.state.elapsedminutes}/>{"\n"}
<Timer updateMinutes = {this.updateMinutes}
startMin = {this.startTime_min}
startSec = {this.startTime_sec}/>
<Settings addWebsite={this.addWebsite}
activateTimer = {this.activateTimer}
deactivateTimer = {this.deactivateTimer}/>
<Settings websites = {this.state.websites}
addWebsite={this.addWebsite}
block={this.block}
unblock={this.unblock}/>

Expand Down
17 changes: 3 additions & 14 deletions src/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class Settings extends React.Component {
this.handleSubmit = this.handleSubmit.bind(this);
this.state = {
display: false,
websites: ["facebook.com", "instagram.com"],
type_box: ''
}
}
Expand All @@ -18,7 +17,7 @@ class Settings extends React.Component {
}

handleSubmit(event) {
this.setState({websites: this.state.websites.concat([this.state.type_box])});
this.props.addWebsite(this.state.type_box);
event.preventDefault();

}
Expand All @@ -34,18 +33,8 @@ class Settings extends React.Component {
}

render() {
// if (!this.state.display) { //display the settings button only
// return (
// // <div>
// // <button class="open"><img src="https://image.flaticon.com/icons/svg/1827/1827870.svg" onClick={this.displaySettings}/></button>
// // </div>
// );
// }

// else {
var webList = this.state.websites.map((w) =>
<li>{w}</li>
);
var webList = this.props.websites ? this.props.websites.map((w) =>
<li>{w}</li>) : null;
return (
<div className="Settings">
<img src= 'https://image.flaticon.com/icons/svg/1827/1827870.svg' onClick={this.closeSettings}/>
Expand Down
8 changes: 7 additions & 1 deletion src/Timer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Timer extends React.Component {

startTimer() {
this.setState({active: true})
this.props.activateTimer();
return;
}

Expand All @@ -30,7 +31,9 @@ class Timer extends React.Component {
timeSet: false
}))

clearInterval(this.myInterval)
clearInterval(this.myInterval);
this.props.deactivateTimer();

return;
}

Expand Down Expand Up @@ -96,6 +99,9 @@ class Timer extends React.Component {

render() {
const {min,hr} = this.state;
if (min===0 && hr===0) {
this.props.deactivateTimer();
}
return (

<div className="Timer">
Expand Down

0 comments on commit 0111eb6

Please sign in to comment.