Skip to content

Commit

Permalink
add firefox support
Browse files Browse the repository at this point in the history
  • Loading branch information
sudonims committed Nov 8, 2020
1 parent ae3ed3b commit 973150c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
16 changes: 6 additions & 10 deletions Firefox_Extensions/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,18 @@ function add(a, b) {

var xhr = new XMLHttpRequest();
var data;
xhr.open("GET", chrome.extension.getURL("cipher.json"), true);
xhr.open("GET", browser.extension.getURL("cipher.json"), true);
xhr.send();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4) {
data = xhr.response;
data = JSON.parse(data);
// console.log(data['0']['a']);
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.generate == true) {
chrome.storage.sync.get(["init_pass"], (initPass) => {
browser.storage.local.get(["init_pass"], (initPass) => {
console.log(initPass);
chrome.storage.sync.get(["lucky"], (lucky) => {
browser.storage.local.get(["lucky"], (lucky) => {
console.log(lucky);
var luck = parseInt(lucky.lucky);
luck1 = luck % 5;
Expand Down Expand Up @@ -225,16 +225,12 @@ xhr.onreadystatechange = () => {
// ans1=sample[luck] + sample[(luck+100)%72] + ans1;
// ans1+=sample[((luck+200)%10)+62] + sample[(luck+300)%72];
console.log(ans1);
chrome.storage.sync.set({ gen_pass: ans1 }, () => {
chrome.runtime.sendMessage({ generated: true });
browser.storage.local.set({ gen_pass: ans1 }, () => {
browser.runtime.sendMessage({ generated: true });
});
});
});
}
});
}
};

// const print = (data)=>{
// console.log(data);
// }
20 changes: 10 additions & 10 deletions Firefox_Extensions/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ document.addEventListener("DOMContentLoaded", async function () {
console.log(l_num, in_pass);

if (l_num != 0) {
chrome.storage.sync.set({ lucky: l_num }, function () {
chrome.notifications.create("success", {
browser.storage.local.set({ lucky: l_num }, function () {
browser.notifications.create("success", {
type: "basic",
iconUrl: "logo.png",
title: "success",
Expand All @@ -38,8 +38,8 @@ document.addEventListener("DOMContentLoaded", async function () {
// }

if (in_pass != 0) {
chrome.storage.sync.set({ init_pass: in_pass }, function () {
chrome.runtime.sendMessage({ generate: true });
browser.storage.local.set({ init_pass: in_pass }, function () {
browser.runtime.sendMessage({ generate: true });
});
in_pass = 0;
}
Expand All @@ -60,39 +60,39 @@ document.addEventListener("DOMContentLoaded", async function () {
pass.remove();
});

chrome.storage.sync.get(["lucky"], (data) => {
browser.storage.local.get(["lucky"], (data) => {
if (data.lucky) {
// gen_pass.innerHTML=data.lucky;
// lucky.className+=" hide";
lucky.remove();
}
});

chrome.runtime.onMessage.addListener(function (
browser.runtime.onMessage.addListener(function (
request,
sender,
sendResponse
) {
if (request.generated) {
chrome.storage.sync.get(["gen_pass"], function (gen_p) {
browser.storage.local.get(["gen_pass"], function (gen_p) {
gen_pass.innerHTML = gen_p.gen_pass;
});
}
});

copy.addEventListener("click", async function () {
chrome.storage.sync.get(["gen_pass"], async function (res) {
browser.storage.local.get(["gen_pass"], async function (res) {
await navigator.clipboard.writeText(res.gen_pass).then(
function () {
chrome.notifications.create("copy_success", {
browser.notifications.create("copy_success", {
type: "basic",
iconUrl: "logo.png",
title: "copy success",
message: "Password copied on Clipboard successfully",
});
},
function () {
chrome.notifications.create("copy_fail", {
browser.notifications.create("copy_fail", {
type: "basic",
iconUrl: "logo.png",
title: "copy_fail",
Expand Down

0 comments on commit 973150c

Please sign in to comment.