diff --git a/manifest.json b/manifest.json index f59aac23d..c93d49fed 100644 --- a/manifest.json +++ b/manifest.json @@ -43,7 +43,6 @@ { "matches": ["*://*/*"], "js": [ - "src/taler-wallet-lib.js", "dist/contentScript-bundle.js" ], "run_at": "document_start" diff --git a/node_modules/.yarn-integrity b/node_modules/.yarn-integrity index a45758dbc..6d4c42d0c 100644 --- a/node_modules/.yarn-integrity +++ b/node_modules/.yarn-integrity @@ -1 +1 @@ -0dc42bcf25ec3d59c7bd394b1d9f751da1a3446ef6012260b277831cef6de2bf \ No newline at end of file +751d3ff225403bea12799f2c0ad32d26a0ff81a4f88821c8f1615d3ddc5a9533 \ No newline at end of file diff --git a/src/content_scripts/notify.ts b/src/content_scripts/notify.ts index 8a25dd500..a0f76cf26 100644 --- a/src/content_scripts/notify.ts +++ b/src/content_scripts/notify.ts @@ -23,378 +23,530 @@ */ -"use strict"; - import URI = require("urijs"); declare var cloneInto: any; -// Make sure we don't pollute the namespace too much. -namespace TalerNotify { - const PROTOCOL_VERSION = 1; +const PROTOCOL_VERSION = 1; - let logVerbose: boolean = false; - try { - logVerbose = !!localStorage.getItem("taler-log-verbose"); - } catch (e) { - // can't read from local storage - } +let logVerbose: boolean = false; +try { + logVerbose = !!localStorage.getItem("taler-log-verbose"); +} catch (e) { + // can't read from local storage +} - if (!taler) { - console.error("Taler wallet lib not included, HTTP 402 payments not" + - " supported"); - } - - if (document.documentElement.getAttribute("data-taler-nojs")) { - document.dispatchEvent(new Event("taler-probe-result")); - } +if (document.documentElement.getAttribute("data-taler-nojs")) { + document.dispatchEvent(new Event("taler-probe-result")); +} - function subst(url: string, H_contract: string) { - url = url.replace("${H_contract}", H_contract); - url = url.replace("${$}", "$"); - return url; - } +function subst(url: string, H_contract: string) { + url = url.replace("${H_contract}", H_contract); + url = url.replace("${$}", "$"); + return url; +} - interface Handler { - type: string; - listener: (e: CustomEvent) => void|Promise; - } - const handlers: Handler[] = []; +interface Handler { + type: string; + listener: (e: CustomEvent) => void|Promise; +} +const handlers: Handler[] = []; - function hashContract(contract: string): Promise { - let walletHashContractMsg = { - type: "hash-contract", - detail: {contract} - }; - return new Promise((resolve, reject) => { - chrome.runtime.sendMessage(walletHashContractMsg, (resp: any) => { - if (!resp.hash) { - console.log("error", resp); - reject(Error("hashing failed")); - } - resolve(resp.hash); - }); +function hashContract(contract: string): Promise { + let walletHashContractMsg = { + type: "hash-contract", + detail: {contract} + }; + return new Promise((resolve, reject) => { + chrome.runtime.sendMessage(walletHashContractMsg, (resp: any) => { + if (!resp.hash) { + console.log("error", resp); + reject(Error("hashing failed")); + } + resolve(resp.hash); }); - } + }); +} - function queryPayment(url: string): Promise { - const walletMsg = { - type: "query-payment", - detail: { url }, - }; - return new Promise((resolve, reject) => { - chrome.runtime.sendMessage(walletMsg, (resp: any) => { +function queryPayment(url: string): Promise { + const walletMsg = { + type: "query-payment", + detail: { url }, + }; + return new Promise((resolve, reject) => { + chrome.runtime.sendMessage(walletMsg, (resp: any) => { + resolve(resp); + }); + }); +} + +function putHistory(historyEntry: any): Promise { + const walletMsg = { + type: "put-history-entry", + detail: { + historyEntry, + }, + }; + return new Promise((resolve, reject) => { + chrome.runtime.sendMessage(walletMsg, (resp: any) => { + resolve(); + }); + }); +} + +function saveOffer(offer: any): Promise { + const walletMsg = { + type: "save-offer", + detail: { + offer: { + contract: offer.data, + merchant_sig: offer.sig, + H_contract: offer.hash, + offer_time: new Date().getTime() / 1000 + }, + }, + }; + return new Promise((resolve, reject) => { + chrome.runtime.sendMessage(walletMsg, (resp: any) => { + if (resp && resp.error) { + reject(resp); + } else { resolve(resp); - }); + } }); + }); +} + + + + +let sheet: CSSStyleSheet|null; + +function initStyle() { + logVerbose && console.log("taking over styles"); + const name = "taler-presence-stylesheet"; + const content = "/* Taler stylesheet controlled by JS */"; + let style = document.getElementById(name) as HTMLStyleElement|null; + if (!style) { + style = document.createElement("style"); + // Needed by WebKit + style.appendChild(document.createTextNode(content)); + style.id = name; + document.head.appendChild(style); + sheet = style.sheet as CSSStyleSheet; + } else { + // We've taken over the stylesheet now, + // make it clear by clearing all the rules in it + // and making it obvious in the DOM. + if (style.tagName.toLowerCase() === "style") { + style.innerText = content; + } + if (!style.sheet) { + throw Error("taler-presence-stylesheet should be a style sheet ( or