Skip to content

Commit

Permalink
Merge pull request #123 from modos189/fix-121
Browse files Browse the repository at this point in the history
  • Loading branch information
modos189 authored Oct 7, 2023
2 parents 64fb0d0 + cd71769 commit fee2b11
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
onToggleIITC
} from "./intel";
import "./requests";
import { strToBase64 } from "@/strToBase64";

const manager = new Manager({
storage: browser.storage.local,
Expand Down Expand Up @@ -145,7 +146,7 @@ async function xmlHttpRequestHandler(data) {

const injectedCode = `
document.dispatchEvent(new CustomEvent('bridgeResponse', {
detail: "${btoa(String(detail_stringify))}"
detail: "${strToBase64(String(detail_stringify))}"
}));
`;

Expand Down
3 changes: 2 additions & 1 deletion src/content-scripts/bridge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3

import { inject } from "@/content-scripts/utils";
import { strToBase64 } from "@/strToBase64";

export async function bridgeAction(e) {
const task = e.detail;
Expand Down Expand Up @@ -48,7 +49,7 @@ const getStorageBridge = async req => {

const injectedCode = `
document.dispatchEvent(new CustomEvent('bridgeResponse', {
detail: "${btoa(String(detail_stringify))}"
detail: "${strToBase64(String(detail_stringify))}"
}));
`;
inject(injectedCode);
Expand Down
8 changes: 7 additions & 1 deletion src/content-scripts/gm-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ export const GM = function() {
const cache = {};
const defineProperty = Object.defineProperty;

function base64ToStr(base64) {
const binString = atob(base64);
const bytes = Uint8Array.from(binString, m => m.codePointAt(0));
return new TextDecoder().decode(bytes);
}

function uuidv4() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(
Expand Down Expand Up @@ -173,7 +179,7 @@ export const GM = function() {
};
};
document.addEventListener("bridgeResponse", function(e) {
const detail = JSON.parse(atob(e.detail));
const detail = JSON.parse(base64ToStr(e.detail));
const uuid = detail.task_uuid;

const response = JSON.parse(detail.response);
Expand Down
3 changes: 2 additions & 1 deletion src/content-scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3

import { getUID } from "lib-iitc-manager";
import { strToBase64 } from "@/strToBase64";

const LOADED_PLUGINS = [];

Expand All @@ -14,7 +15,7 @@ export function inject(code) {
}

function getPluginHash(uid) {
return "VMin" + btoa(uid);
return "VMin" + strToBase64(uid);
}

export async function IITCButtonInitJS(e) {
Expand Down
7 changes: 7 additions & 0 deletions src/strToBase64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3

export function strToBase64(str) {
const bytes = new TextEncoder().encode(str);
const binString = String.fromCodePoint(...bytes);
return btoa(binString);
}

0 comments on commit fee2b11

Please sign in to comment.