Skip to content

Commit 90fcb38

Browse files
authored
Merge pull request #1 from ARR552/dev_firefox
Dev firefox
2 parents a582393 + 514ebbc commit 90fcb38

File tree

5 files changed

+59
-22
lines changed

5 files changed

+59
-22
lines changed

Plugin/background.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var message;
2+
browser.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
3+
message = msg;
4+
sendResponse("Gotcha!");
5+
});

Plugin/block.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
} else {
1616
createWeb3();
1717
}
18+
document.getElementById("setNet").addEventListener("click", setNetwork);
19+
document.getElementById("loginButton").addEventListener("click", Login);
20+
document.getElementById("completeFields").addEventListener("click", CompleteFields);
21+
document.getElementById("submitButton").addEventListener("click", SubmitToBlockchain);
22+
document.getElementById("checkButton").addEventListener("click", CheckIntegrity);
23+
1824

1925
function SubmitToBlockchain (){
2026

@@ -56,8 +62,8 @@
5662
var nonce = "0x" + (nonceValue).toString(16);
5763
rawtx = {
5864
nonce: nonce,
59-
gasPrice: this.web3.utils.toHex(estimatedGas),
60-
gasLimit: this.web3.utils.toHex(GasLimit),
65+
gasPrice: web3.utils.toHex(estimatedGas),
66+
gasLimit: web3.utils.toHex(GasLimit),
6167
to: contractAddress,
6268
data: bytecodeData
6369
};
@@ -67,7 +73,7 @@
6773
tx.sign(privateKey);
6874
var raw = "0x" + tx.serialize().toString("hex");
6975

70-
this.web3.eth.sendSignedTransaction(raw)
76+
web3.eth.sendSignedTransaction(raw)
7177
.once('transactionHash', function(hash){
7278
document.getElementById("comment").innerHTML = "Transaction sent, please wait til' it is mined"
7379
//Arranco el spin y el boton
@@ -217,8 +223,8 @@
217223
var nonce = "0x" + (nonceValue).toString(16);
218224
rawtx = {
219225
nonce: nonce,
220-
gasPrice: this.web3.utils.toHex(estimatedGas),
221-
gasLimit: this.web3.utils.toHex(GasLimit),
226+
gasPrice: web3.utils.toHex(estimatedGas),
227+
gasLimit: web3.utils.toHex(GasLimit),
222228
to: contractAddress,
223229
data: bytecodeData
224230
};
@@ -227,15 +233,14 @@
227233

228234
tx.sign(privateKey);
229235
var raw = "0x" + tx.serialize().toString("hex");
230-
this.web3.eth.sendSignedTransaction(raw)
236+
web3.eth.sendSignedTransaction(raw)
231237
.once('transactionHash', function(hash){
232238
document.getElementById("comment").innerHTML = "Transaction sent, please wait til' it is mined";
233239
//Arranco el spin y oculto el boton
234240
document.getElementById("spin").style.display = "block";
235241
document.getElementById("loginButton").style.display = "none";
236242
})
237243
.on('error', function(error){
238-
//console.log(error);
239244
document.getElementById("comment").innerHTML = "";
240245
document.getElementById("error").innerHTML = "Error in transaction";
241246
document.getElementById("spin").style.display = "none"
@@ -291,6 +296,10 @@
291296

292297
function CompleteFields(){
293298
var pathArray;
299+
browser.runtime.getBackgroundPage().then((get)=>{
300+
console.log(get.message);
301+
document.getElementById("msg").value = get.message;
302+
});
294303
browser.tabs.query({active: true, currentWindow: true}).then((tabs)=>{
295304
pathArray = tabs[0].url.split('/');
296305
if(pathArray[2] == "twitter.com"){
@@ -345,7 +354,7 @@
345354

346355
}
347356
}
348-
357+
349358
function onError(e) {
350359
console.error(e);
351360
}
@@ -370,7 +379,6 @@
370379
}
371380

372381
function createWeb3(){
373-
console.log("func createweb3");
374382
switch (selectedNetwork) {
375383
case "Ropsten":
376384
web3 = new Web3();
@@ -391,7 +399,7 @@
391399
var URL = "http://localhost:7545";
392400
web3 = new Web3(new Web3.providers.HttpProvider(URL));
393401
Web3.providers.HttpProvider.prototype.sendAsync = Web3.providers.HttpProvider.prototype.send
394-
contractAddress = "0xd002c4f91e4ad8650455ea5949c6cc1dd2ca0140";
402+
contractAddress = "0x9ab56344fd3033d8339eb0b9a6723442adfab3a7";
395403
break;
396404
}
397405

Plugin/content.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var url = window.location.href;
2+
var oldUrl;
3+
4+
window.setInterval(function(){
5+
if (oldUrl != url){
6+
oldUrl = url;
7+
var msg = document.getElementsByClassName("TweetTextSize TweetTextSize--jumbo js-tweet-text tweet-text")[0].innerHTML;
8+
browser.runtime.sendMessage(msg, function(response) {
9+
console.log("Response: ", response);
10+
});
11+
}
12+
url = window.location.href;
13+
}, 250);
14+
15+
16+
17+

Plugin/manifest.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
88
"16": "images/icon-16.png",
99
"128": "images/icon-128.png"
1010
},
11+
"content_security_policy": "default-src * 'unsafe-inline' 'unsafe-eval'; script-src 'self' 'unsafe-eval'; object-src 'self'; style-src 'self' 'unsafe-inline' 'unsafe-eval';",
1112
"applications": {
1213
"gecko": {
1314
"id": "webextension@block.io"
1415
}
1516
},
17+
"background": {
18+
"scripts": ["background.js"]
19+
},
20+
21+
"content_scripts": [{
22+
"matches": ["*://twitter.com/*"],
23+
"js": ["content.js"],
24+
"all_frames": true
25+
}],
1626
"browser_action": {
1727
"default_icon": {
1828
"19": "images/icon-19.png",
@@ -25,6 +35,7 @@
2535
"*://*/*",
2636
"tabs",
2737
"webRequest",
38+
"webNavigation",
2839
"storage",
2940
"activeTab"
3041
]

Plugin/popup.html

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
<head>
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=no">
7-
<meta http-equiv="Content-Security-Policy"
8-
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline';">
97
<link rel="stylesheet" type="text/css" href="main.css">
108
<script type="text/javascript" src="./web3/web3.js"></script>
119
<script type="text/javascript" src="./web3/ethereumjs-tx.js"></script>
@@ -23,18 +21,16 @@
2321
<option>MainNet</option>
2422
</select>
2523
</form>
26-
<script src="./block.js" type="text/javascript" charset="utf-8"></script>
27-
<button onclick="setNetwork()" class="boton_personalizado">Set Network</button>
24+
<input id="setNet" type="button" class="boton_personalizado" value="Set Network">
25+
2826
<hr size="1px">
2927
<p class="login">
3028
<b>Register:</b><br>
3129
<input type="password" id="pk" required minlength="64" maxlength="64" placeholder="Enter your private key"> <br>
32-
<input class="boton_personalizado" type="button" value="Login" onclick="Login()" style="display: block;"
33-
id="loginButton" />
30+
<input id="loginButton" class="boton_personalizado" type="button" value="Login" style="display: block;" />
3431
</p>
3532
<br>
36-
<input class="boton_personalizado" type="button" value="AutoComplete" onclick="CompleteFields()"
37-
style="display: block;" id="completeFields" />
33+
<button class="boton_personalizado" type="button" value="AutoComplete" style="display: block;" id="completeFields">AutoComplete</button>
3834
<br>
3935
<input type="text" id="url_id" placeholder="https://"><br>
4036
<br>
@@ -44,13 +40,13 @@
4440
<div id="spin" class="loader" style="display: none;"></div>
4541
<br>
4642
<div style="width: 200px; margin: auto;">
47-
<input class="boton_grande" style="float:left;" type="button" value="Submit&#13;&#10;message"
48-
onclick="SubmitToBlockchain()" style="display: block;" id="submitButton" />
49-
<input class="boton_grande" style="float:right;" type="button" value="Check&#13;&#10;integrity"
50-
onclick="CheckIntegrity()" style="display: block;" id="checkButton" />
43+
<input class="boton_grande" style="float:left;" type="button" value="Submit&#13;&#10;message" style="display: block;" id="submitButton" />
44+
<input class="boton_grande" style="float:right;" type="button" value="Check&#13;&#10;integrity" style="display: block;" id="checkButton" />
5145
</div>
5246
<h3 id="comment"></h3>
5347
<b id="error" style="color: red;"></b>
48+
<script src="./block.js" type="text/javascript" charset="utf-8"></script>
49+
5450
</body>
5551

5652
</html>

0 commit comments

Comments
 (0)